Session.Table().ID().Exist does not meet expectations #1818

Closed
opened 2020-10-29 03:20:13 +00:00 by Epsirom · 0 comments

The following three demos should have the same result and SQL, but in fact they are different with xorm.io/xorm v1.0.5

engine, _ := xorm.NewEngine(...)
has, err := engine.ID(123).Cols("id").Exist(new(Table))
fmt.Println(has, err) // false nil
// engine.ShowSQL() will output: SELECT `id` FROM `table` WHERE `id`=? LIMIT 1 [123]
engine, _ := xorm.NewEngine(...)
has, err := engine.Table(new(Table)).ID(123).Cols("id").Exist()
fmt.Println(has, err) // true nil
// engine.ShowSQL() will output: SELECT * FROM `table`  LIMIT 1 []
engine, _ := xorm.NewEngine(...)
has, err := engine.Table(new(Table)).Where("id = ?", 123).Cols("id").Exist()
fmt.Println(has, err) // false nil
// engine.ShowSQL() will output: SELECT * FROM `table`  WHERE (id = ?) LIMIT 1 [123]

The first demo is the ground truth, and the third demo is acceptable(Cols("id") is ignored but does not affect the result).

The following three demos should have the same result and SQL, but in fact they are different with xorm.io/xorm v1.0.5 ```golang engine, _ := xorm.NewEngine(...) has, err := engine.ID(123).Cols("id").Exist(new(Table)) fmt.Println(has, err) // false nil // engine.ShowSQL() will output: SELECT `id` FROM `table` WHERE `id`=? LIMIT 1 [123] ``` ```golang engine, _ := xorm.NewEngine(...) has, err := engine.Table(new(Table)).ID(123).Cols("id").Exist() fmt.Println(has, err) // true nil // engine.ShowSQL() will output: SELECT * FROM `table` LIMIT 1 [] ``` ```golang engine, _ := xorm.NewEngine(...) has, err := engine.Table(new(Table)).Where("id = ?", 123).Cols("id").Exist() fmt.Println(has, err) // false nil // engine.ShowSQL() will output: SELECT * FROM `table` WHERE (id = ?) LIMIT 1 [123] ``` The first demo is the ground truth, and the third demo is acceptable(Cols("id") is ignored but does not affect the result).
lunny added the
kind
bug
label 2020-10-29 06:43:34 +00:00
lunny added this to the 1.1.1 milestone 2021-06-06 13:07:07 +00:00
lunny referenced this issue from a commit 2021-06-07 05:45:30 +00:00
lunny closed this issue 2021-06-07 05:45:30 +00:00
lunny closed this issue 2021-06-07 05:45:30 +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#1818
No description provided.