From eca2d0bf7e085cbde1a5865a00e1c88cf54f1991 Mon Sep 17 00:00:00 2001 From: John Date: Mon, 7 May 2018 16:18:39 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dgdb.Delete=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- g/database/gdb/gdb_base.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/g/database/gdb/gdb_base.go b/g/database/gdb/gdb_base.go index 0fa883c92..27a582b9e 100644 --- a/g/database/gdb/gdb_base.go +++ b/g/database/gdb/gdb_base.go @@ -362,7 +362,7 @@ func (db *Db) Update(table string, data interface{}, condition interface{}, args // CURD操作:删除数据 func (db *Db) Delete(table string, condition interface{}, args ...interface{}) (sql.Result, error) { - return db.Exec(fmt.Sprintf("DELETE FROM %s WHERE %s", db.charl, table, db.charr, db.formatCondition(condition)), args...) + return db.Exec(fmt.Sprintf("DELETE FROM %s%s%s WHERE %s", db.charl, table, db.charr, db.formatCondition(condition)), args...) } // 格式化SQL查询条件 From 5db50ef2f28df6488fb762c73e0cf082739cdd1c Mon Sep 17 00:00:00 2001 From: John Date: Mon, 7 May 2018 16:22:22 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dgdb.Model.And/Or=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- g/database/gdb/gdb_base.go | 2 ++ g/database/gdb/gdb_model.go | 4 ++-- geg/database/mysql/mysql.go | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/g/database/gdb/gdb_base.go b/g/database/gdb/gdb_base.go index 27a582b9e..fc1b7e700 100644 --- a/g/database/gdb/gdb_base.go +++ b/g/database/gdb/gdb_base.go @@ -38,6 +38,8 @@ func (db *Db) Close() error { // 数据库sql查询操作,主要执行查询 func (db *Db) Query(query string, args ...interface{}) (*sql.Rows, error) { + fmt.Println(query) + fmt.Println(args) p := db.link.handleSqlBeforeExec(&query) rows, err := db.slave.Query(*p, args ...) err = db.formatError(err, p, args...) diff --git a/g/database/gdb/gdb_model.go b/g/database/gdb/gdb_model.go index 8a85f4e27..8bfd9a480 100644 --- a/g/database/gdb/gdb_model.go +++ b/g/database/gdb/gdb_model.go @@ -91,14 +91,14 @@ func (md *Model) Where(where interface{}, args...interface{}) (*Model) { // 链式操作,添加AND条件到Where中 func (md *Model) And(where interface{}, args...interface{}) (*Model) { md.where += " AND " + md.db.formatCondition(where) - md.whereArgs = append(md.whereArgs, args) + md.whereArgs = append(md.whereArgs, args...) return md } // 链式操作,添加OR条件到Where中 func (md *Model) Or(where interface{}, args...interface{}) (*Model) { md.where += " OR " + md.db.formatCondition(where) - md.whereArgs = append(md.whereArgs, args) + md.whereArgs = append(md.whereArgs, args...) return md } diff --git a/geg/database/mysql/mysql.go b/geg/database/mysql/mysql.go index 4ddc0f759..afff92934 100644 --- a/geg/database/mysql/mysql.go +++ b/geg/database/mysql/mysql.go @@ -478,7 +478,7 @@ func mapToStruct() { } func main() { - r, _ := db.Table("user").Fields("*").Where("typeid = ?", 1).Limit(0, 10).Select() + r, _ := db.Table("user").Fields("*").Where("typeid = ?", 1).And("uid=?", 1).Limit(0, 10).Select() j, _ := gparser.VarToJson(r.ToList()) fmt.Println(string(j)) fmt.Println(r) From 1e0cfd6d1ad17d7d10ff6f80f6c9f79bf3f10694 Mon Sep 17 00:00:00 2001 From: John Date: Mon, 7 May 2018 16:44:15 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E8=AF=AD=E5=8F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- g/database/gdb/gdb_base.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/g/database/gdb/gdb_base.go b/g/database/gdb/gdb_base.go index fc1b7e700..27a582b9e 100644 --- a/g/database/gdb/gdb_base.go +++ b/g/database/gdb/gdb_base.go @@ -38,8 +38,6 @@ func (db *Db) Close() error { // 数据库sql查询操作,主要执行查询 func (db *Db) Query(query string, args ...interface{}) (*sql.Rows, error) { - fmt.Println(query) - fmt.Println(args) p := db.link.handleSqlBeforeExec(&query) rows, err := db.slave.Query(*p, args ...) err = db.formatError(err, p, args...)