Skip to content

Commit 6e5ce98

Browse files
authored
fix(database/gdb): fix #3649 when constructing query param, gdb.Row value not directly write to Buffer (#3718)
1 parent a6c361d commit 6e5ce98

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

contrib/drivers/mysql/mysql_z_unit_issue_test.go

+17
Original file line numberDiff line numberDiff line change
@@ -1199,3 +1199,20 @@ func Test_Issue3238(t *testing.T) {
11991199
}
12001200
})
12011201
}
1202+
1203+
// https://github.com/gogf/gf/issues/3649
1204+
func Test_Issue3649(t *testing.T) {
1205+
table := createInitTable()
1206+
defer dropTable(table)
1207+
1208+
gtest.C(t, func(t *gtest.T) {
1209+
sql, err := gdb.CatchSQL(context.Background(), func(ctx context.Context) (err error) {
1210+
user := db.Model(table).Ctx(ctx)
1211+
_, err = user.Where("create_time = ?", gdb.Raw("now()")).WhereLT("create_time", gdb.Raw("now()")).Count()
1212+
return
1213+
})
1214+
t.AssertNil(err)
1215+
sqlStr := fmt.Sprintf("SELECT COUNT(1) FROM `%s` WHERE (create_time = now()) AND (`create_time` < now())", table)
1216+
t.Assert(sql[0], sqlStr)
1217+
})
1218+
}

database/gdb/gdb_func.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -777,11 +777,7 @@ func formatWhereKeyValue(in formatWhereKeyValueInput) (newArgs []interface{}) {
777777
} else {
778778
in.Buffer.WriteString(quotedKey)
779779
}
780-
if s, ok := in.Value.(Raw); ok {
781-
in.Buffer.WriteString(gconv.String(s))
782-
} else {
783-
in.Args = append(in.Args, in.Value)
784-
}
780+
in.Args = append(in.Args, in.Value)
785781
}
786782
}
787783
return in.Args

0 commit comments

Comments
 (0)