Skip to content

Commit

Permalink
fix(database/gdb): fix #3649 when constructing query param, gdb.Row
Browse files Browse the repository at this point in the history
… value not directly write to Buffer (#3718)
  • Loading branch information
cyjaysong authored Aug 14, 2024
1 parent a6c361d commit 6e5ce98
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
17 changes: 17 additions & 0 deletions contrib/drivers/mysql/mysql_z_unit_issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1199,3 +1199,20 @@ func Test_Issue3238(t *testing.T) {
}
})
}

// https://github.com/gogf/gf/issues/3649
func Test_Issue3649(t *testing.T) {
table := createInitTable()
defer dropTable(table)

gtest.C(t, func(t *gtest.T) {
sql, err := gdb.CatchSQL(context.Background(), func(ctx context.Context) (err error) {
user := db.Model(table).Ctx(ctx)
_, err = user.Where("create_time = ?", gdb.Raw("now()")).WhereLT("create_time", gdb.Raw("now()")).Count()
return
})
t.AssertNil(err)
sqlStr := fmt.Sprintf("SELECT COUNT(1) FROM `%s` WHERE (create_time = now()) AND (`create_time` < now())", table)
t.Assert(sql[0], sqlStr)
})
}
6 changes: 1 addition & 5 deletions database/gdb/gdb_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -777,11 +777,7 @@ func formatWhereKeyValue(in formatWhereKeyValueInput) (newArgs []interface{}) {
} else {
in.Buffer.WriteString(quotedKey)
}
if s, ok := in.Value.(Raw); ok {
in.Buffer.WriteString(gconv.String(s))
} else {
in.Args = append(in.Args, in.Value)
}
in.Args = append(in.Args, in.Value)
}
}
return in.Args
Expand Down

0 comments on commit 6e5ce98

Please sign in to comment.