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

Closed
opened 1 year ago by Epsirom · 0 comments
Epsirom commented 1 year ago

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 1 year ago
lunny added this to the 1.1.1 milestone 8 months ago
lunny referenced this issue from a commit 8 months ago
lunny closed this issue 8 months ago
lunny closed this issue 8 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.