Merge branch 'master' of http://johnx.cn:6662/John/gf into qiangg_router

This commit is contained in:
John
2018-04-12 09:25:59 +08:00
2 changed files with 20 additions and 25 deletions

View File

@ -12,6 +12,7 @@ import (
"errors"
"strings"
"database/sql"
"gitee.com/johng/gf/g/util/gconv"
)
// 关闭链接
@ -309,13 +310,7 @@ func (db *Db) Update(table string, data interface{}, condition interface{}, args
return nil, errors.New("invalid data type for 'data' field, string or Map expected")
}
for _, v := range args {
if r, ok := v.(string); ok {
params = append(params, r)
} else if r, ok := v.(int); ok {
params = append(params, string(r))
} else {
}
params = append(params, gconv.String(v))
}
return db.Exec(fmt.Sprintf("UPDATE %s%s%s SET %s WHERE %s", db.charl, table, db.charr, updates, condition), params...)
}

View File

@ -16,7 +16,7 @@ func init () {
Host : "127.0.0.1",
Port : "3306",
User : "root",
Pass : "8692651",
Pass : "123456",
Name : "test",
Type : "mysql",
Role : "master",
@ -225,7 +225,7 @@ func update1() {
// 数据更新
func update2() {
fmt.Println("update2:")
r, err := db.Update("user", "name='john2'", "uid=1")
r, err := db.Update("user", gdb.Map{"name" : "john6"}, "uid=?", 1)
if err == nil {
fmt.Println(r.LastInsertId())
fmt.Println(r.RowsAffected())
@ -300,7 +300,7 @@ func linkopUpdate1() {
// 通过Map指针方式传参方式
func linkopUpdate2() {
fmt.Println("linkopUpdate2:")
r, err := db.Table("user").Data(gdb.Map{"name" : "john2"}).Where("name=?", "john").Update()
r, err := db.Table("user").Data(gdb.Map{"name" : "john2"}).Where("name=?", "john_1").Update()
if err == nil {
fmt.Println(r.RowsAffected())
} else {
@ -438,22 +438,22 @@ func instance() {
func main() {
create()
create()
insert()
query()
replace()
save()
batchInsert()
update1()
//create()
//create()
//insert()
//query()
//replace()
//save()
//batchInsert()
//update1()
update2()
update3()
linkopSelect1()
linkopSelect2()
linkopSelect3()
linkopUpdate1()
linkopUpdate2()
linkopUpdate3()
//update3()
//linkopSelect1()
//linkopSelect2()
//linkopSelect3()
//linkopUpdate1()
//linkopUpdate2()
//linkopUpdate3()
//keepPing()
//transaction1()
//transaction2()