Why Exist dose not support ID Conditional? #1043

Open
opened 2018-07-20 02:58:02 +00:00 by limpo1989 · 1 comment
limpo1989 commented 2018-07-20 02:58:02 +00:00 (Migrated from github.com)
engine.Table(...).ID(core.PK {key1, key2}).Exist()
``` engine.Table(...).ID(core.PK {key1, key2}).Exist() ```
Wenfeng-GAO commented 2018-07-26 01:42:38 +00:00 (Migrated from github.com)

This only happens when we use .Table()and with no bean args in Exist(), as we can see in the source code

 26         if len(bean) == 0 {
 27             tableName := session.statement.TableName()
 28             if len(tableName) <= 0 {
 29                 return false, ErrTableNotFound
 30             }
 31
 32             if session.statement.cond.IsValid() {
 33                 condSQL, condArgs, err := builder.ToSQL(session.statement.cond)
 34                 if err != nil {
 35                     return false, err
 36                 }
 37
 38                 sqlStr = fmt.Sprintf("SELECT * FROM %s WHERE %s LIMIT 1", tableName, condSQL)
 39                 args = condArgs
 40             } else {
 41                 sqlStr = fmt.Sprintf("SELECT * FROM %s LIMIT 1", tableName)
 42                 args = []interface{}{}
 43             }

in this case, sqlStr was generated without idParam.

By the way, a fail test case pr has been submitted.

This only happens when we use `.Table()`and with no bean args in `Exist()`, as we can see in the source code ``` 26 if len(bean) == 0 { 27 tableName := session.statement.TableName() 28 if len(tableName) <= 0 { 29 return false, ErrTableNotFound 30 } 31 32 if session.statement.cond.IsValid() { 33 condSQL, condArgs, err := builder.ToSQL(session.statement.cond) 34 if err != nil { 35 return false, err 36 } 37 38 sqlStr = fmt.Sprintf("SELECT * FROM %s WHERE %s LIMIT 1", tableName, condSQL) 39 args = condArgs 40 } else { 41 sqlStr = fmt.Sprintf("SELECT * FROM %s LIMIT 1", tableName) 42 args = []interface{}{} 43 } ``` in this case, `sqlStr` was generated without `idParam`. By the way, a fail test case pr has been submitted.
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#1043
No description provided.