if my model struct use decimal.Decimal, and i use get function, Decimal.Decimal is enforced as a query condition #2087

Open
opened 2021-12-29 07:03:38 +00:00 by eliassama · 0 comments

xorm: xorm.io/xorm v1.2.5
decimal: github.com/shopspring/decimal v1.2.0
go: go version go1.16.10 darwin/amd64
os: MacOS 11.4
database: postgres , docker run latest tag

a mock model struct like this:

type mockTable struct {
	ID             	uint64      		`xorm:"pk autoincr 'id'"`
    Name		   	string       		`xorm:"index unique text"`
	Weight         	decimal.Decimal		`xorm:" DECIMAL(128,0)"`
	Height		 	decimal.Decimal 	`xorm:" DECIMAL(128,0)"`
	AvgCount  		decimal.Decimal 	`xorm:" DECIMAL(128,0)"`
}

if i execute the query like this:

engine.Where("id = ?", 10).Get(&mockTable{})

or like this:

engine.Get(&mockTable{ID:10})

the SQL that you end up executing looks like this.

SELECT "id", "name", "weight", "height", "avgCount" FROM "mock_table" WHERE "id"=$1 AND "weight"=$2 AND "height"=$3 AND "avgCount"=$4 LIMIT 1 [11 0 0 0]

i think maybe there was a bad processing of decimal.Decimal.

**xorm**: xorm.io/xorm v1.2.5 **decimal**: github.com/shopspring/decimal v1.2.0 **go**: go version go1.16.10 darwin/amd64 **os**: MacOS 11.4 **database**: postgres , docker run latest tag a mock model struct like this: ``` type mockTable struct { ID uint64 `xorm:"pk autoincr 'id'"` Name string `xorm:"index unique text"` Weight decimal.Decimal `xorm:" DECIMAL(128,0)"` Height decimal.Decimal `xorm:" DECIMAL(128,0)"` AvgCount decimal.Decimal `xorm:" DECIMAL(128,0)"` } ``` if i execute the query like this: ``` engine.Where("id = ?", 10).Get(&mockTable{}) ``` or like this: ``` engine.Get(&mockTable{ID:10}) ``` the SQL that you end up executing looks like this. ``` SELECT "id", "name", "weight", "height", "avgCount" FROM "mock_table" WHERE "id"=$1 AND "weight"=$2 AND "height"=$3 AND "avgCount"=$4 LIMIT 1 [11 0 0 0] ``` i think maybe there was a bad processing of decimal.Decimal.
eliassama started working 2021-12-29 09:18:48 +00:00
eliassama stopped working 2021-12-29 09:19:00 +00:00
12s
eliassama deleted spent time 2021-12-29 09:19:22 +00:00
- 12s
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#2087
No description provided.