使用SetMapper后Incr和Decr生成的sql有问题 #1247

Closed
opened 2019-03-13 03:55:41 +00:00 by wudaoren · 3 comments
wudaoren commented 2019-03-13 03:55:41 +00:00 (Migrated from github.com)

代码如下

eg, _ := xorm.NewEngine("mysql", fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8", "root", "", "127.0.0.1:3306", "test"))
	eg.ShowSQL(true)
	eg.SetMapper(new(core.SameMapper))
	var user = &User{
		Age: 22,
	}
	eg.Cols("Age").Decr("Age", 9).ID(3).Update(user)

生成的Sql语句如下

UPDATE `User` SET `Age` = ?, `Age` = `Age` - ?, `Version` = `Version` + 1 WHERE `Id`=? AND `Version`=? []interface {}{22, 9, 3, 0}

正确的语句应该是

UPDATE `User` SET `Age` = `Age` - ?, `Version` = `Version` + 1 WHERE `Id`=? AND `Version`=? []interface {}{22, 9, 3, 0}

不使用SetMapper生成的sql语句正常

代码如下 ``` eg, _ := xorm.NewEngine("mysql", fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8", "root", "", "127.0.0.1:3306", "test")) eg.ShowSQL(true) eg.SetMapper(new(core.SameMapper)) var user = &User{ Age: 22, } eg.Cols("Age").Decr("Age", 9).ID(3).Update(user) ``` 生成的Sql语句如下 ``` UPDATE `User` SET `Age` = ?, `Age` = `Age` - ?, `Version` = `Version` + 1 WHERE `Id`=? AND `Version`=? []interface {}{22, 9, 3, 0} ``` 正确的语句应该是 ``` UPDATE `User` SET `Age` = `Age` - ?, `Version` = `Version` + 1 WHERE `Id`=? AND `Version`=? []interface {}{22, 9, 3, 0} ``` 不使用SetMapper生成的sql语句正常

Which version are you using?

Which version are you using?
wudaoren commented 2019-03-13 04:42:08 +00:00 (Migrated from github.com)

go get -u github.com/go-xorm/xorm
最新版本,刚刚更新了也是同样的问题

go get -u github.com/go-xorm/xorm 最新版本,刚刚更新了也是同样的问题
lunny added the
need
test
label 2021-06-12 09:43:53 +00:00
lunny added this to the 1.1.1 milestone 2021-06-12 09:49:47 +00:00

Closed per #1951

Closed per #1951
lunny closed this issue 2021-06-12 12:35:43 +00:00
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: xorm/xorm#1247
No description provided.