mirror of
https://gitee.com/johng/gf
synced 2026-06-26 17:35:40 +08:00
Merge pull request #1499 from zxr615/fix_orderby_null
order by null is not escaped
This commit is contained in:
@ -276,6 +276,7 @@ func doQuoteWord(s, charLeft, charRight string) string {
|
||||
|
||||
// doQuoteString quotes string with quote chars.
|
||||
// For example, if quote char is '`':
|
||||
// "null" => "NULL"
|
||||
// "user" => "`user`"
|
||||
// "user u" => "`user` u"
|
||||
// "user,user_detail" => "`user`,`user_detail`"
|
||||
@ -289,7 +290,11 @@ func doQuoteString(s, charLeft, charRight string) string {
|
||||
array2 := gstr.SplitAndTrim(v1, " ")
|
||||
array3 := gstr.Split(gstr.Trim(array2[0]), ".")
|
||||
if len(array3) == 1 {
|
||||
array3[0] = doQuoteWord(array3[0], charLeft, charRight)
|
||||
if strings.EqualFold(array3[0], "NULL") {
|
||||
array3[0] = doQuoteWord(array3[0], "", "")
|
||||
} else {
|
||||
array3[0] = doQuoteWord(array3[0], charLeft, charRight)
|
||||
}
|
||||
} else if len(array3) >= 2 {
|
||||
array3[0] = doQuoteWord(array3[0], charLeft, charRight)
|
||||
// Note:
|
||||
|
||||
@ -1083,6 +1083,13 @@ func Test_Model_OrderBy(t *testing.T) {
|
||||
t.Assert(len(result), TableSize)
|
||||
t.Assert(result[0]["nickname"].String(), fmt.Sprintf("name_%d", TableSize))
|
||||
})
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
result, err := db.Model(table).Order("NULL").All()
|
||||
t.AssertNil(err)
|
||||
t.Assert(len(result), TableSize)
|
||||
t.Assert(result[0]["nickname"].String(), "name_1")
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Model_GroupBy(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user