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

Closed
opened 3 years ago by wudaoren · 3 comments
wudaoren commented 3 years ago (Migrated from github.com)
Owner

代码如下

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语句正常
Owner

Which version are you using?

Which version are you using?
wudaoren commented 3 years ago (Migrated from github.com)
Owner

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

go get -u github.com/go-xorm/xorm 最新版本,刚刚更新了也是同样的问题
lunny added the
need/test
label 6 months ago
lunny referenced this issue from a commit 6 months ago
lunny added this to the 1.1.1 milestone 6 months ago
Owner

Closed per #1951

Closed per #1951
lunny closed this issue 6 months ago
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date

No due date set.

Dependencies

This issue currently doesn't have any dependencies.

Loading…
There is no content yet.