2019-02-02 16:18:25 +08:00
|
|
|
|
// Copyright 2017 gf Author(https://github.com/gogf/gf). All Rights Reserved.
|
2018-08-08 09:09:28 +08:00
|
|
|
|
//
|
|
|
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
|
|
|
// If a copy of the MIT was not distributed with this file,
|
2019-02-02 16:18:25 +08:00
|
|
|
|
// You can obtain one at https://github.com/gogf/gf.
|
2018-08-08 20:09:52 +08:00
|
|
|
|
// @author wxkj<wxscz@qq.com>
|
2018-08-08 09:09:28 +08:00
|
|
|
|
|
|
|
|
|
package gdb
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"database/sql"
|
|
|
|
|
)
|
|
|
|
|
|
2018-08-08 20:09:52 +08:00
|
|
|
|
// 使用时需要import:
|
2019-02-02 16:18:25 +08:00
|
|
|
|
// _ "github.com/gogf/gf/third/github.com/mattn/go-sqlite3"
|
2018-08-08 20:09:52 +08:00
|
|
|
|
|
2018-10-26 22:08:52 +08:00
|
|
|
|
// Sqlite接口对象
|
|
|
|
|
// @author wxkj<wxscz@qq.com>
|
|
|
|
|
|
2018-08-08 09:09:28 +08:00
|
|
|
|
// 数据库链接对象
|
2018-12-14 18:35:51 +08:00
|
|
|
|
type dbSqlite struct {
|
|
|
|
|
*dbBase
|
2018-08-08 09:09:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-15 15:50:39 +08:00
|
|
|
|
func (db *dbSqlite) Open(config *ConfigNode) (*sql.DB, error) {
|
2018-08-08 09:09:28 +08:00
|
|
|
|
var source string
|
2018-12-15 15:50:39 +08:00
|
|
|
|
if config.Linkinfo != "" {
|
|
|
|
|
source = config.Linkinfo
|
2018-08-08 09:09:28 +08:00
|
|
|
|
} else {
|
2018-12-15 15:50:39 +08:00
|
|
|
|
source = config.Name
|
2018-08-08 09:09:28 +08:00
|
|
|
|
}
|
|
|
|
|
if db, err := sql.Open("sqlite3", source); err == nil {
|
|
|
|
|
return db, nil
|
|
|
|
|
} else {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-14 18:35:51 +08:00
|
|
|
|
// 获得关键字操作符
|
|
|
|
|
func (db *dbSqlite) getChars () (charLeft string, charRight string) {
|
|
|
|
|
return "`", "`"
|
2018-08-08 09:09:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 在执行sql之前对sql进行进一步处理
|
2018-08-09 09:49:57 +08:00
|
|
|
|
// @todo 需要增加对Save方法的支持,可使用正则来实现替换,
|
|
|
|
|
// @todo 将ON DUPLICATE KEY UPDATE触发器修改为两条SQL语句(INSERT OR IGNORE & UPDATE)
|
2018-12-14 18:35:51 +08:00
|
|
|
|
func (db *dbSqlite) handleSqlBeforeExec(query string) string {
|
|
|
|
|
return query
|
2018-10-26 22:08:52 +08:00
|
|
|
|
}
|