Skip to content

Commit 57a49c6

Browse files
authored
fix bug when query map condtion with no quote (go-xorm#1449)
1 parent 6a47ef9 commit 57a49c6

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

session_get_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,3 +618,28 @@ func TestCustomTypes(t *testing.T) {
618618
assert.True(t, has)
619619
assert.EqualValues(t, 32, age)
620620
}
621+
622+
func TestGetViaMapCond(t *testing.T) {
623+
type GetViaMapCond struct {
624+
Id int64
625+
Platform int
626+
Index int
627+
}
628+
629+
assert.NoError(t, prepareEngine())
630+
assertSync(t, new(GetViaMapCond))
631+
632+
var (
633+
r GetViaMapCond
634+
platformStr = colMapper.Obj2Table("Platform")
635+
indexStr = colMapper.Obj2Table("Index")
636+
query = map[string]interface{}{
637+
platformStr: 1,
638+
indexStr: 1,
639+
}
640+
)
641+
642+
has, err := testEngine.Where(query).Get(&r)
643+
assert.NoError(t, err)
644+
assert.False(t, has)
645+
}

statement.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,12 @@ func (statement *Statement) And(query interface{}, args ...interface{}) *Stateme
149149
cond := builder.Expr(query.(string), args...)
150150
statement.cond = statement.cond.And(cond)
151151
case map[string]interface{}:
152-
cond := builder.Eq(query.(map[string]interface{}))
153-
statement.cond = statement.cond.And(cond)
152+
queryMap := query.(map[string]interface{})
153+
newMap := make(map[string]interface{})
154+
for k, v := range queryMap {
155+
newMap[statement.Engine.Quote(k)] = v
156+
}
157+
statement.cond = statement.cond.And(builder.Eq(newMap))
154158
case builder.Cond:
155159
cond := query.(builder.Cond)
156160
statement.cond = statement.cond.And(cond)

0 commit comments

Comments
 (0)