diff --git a/database/gdb/gdb_func.go b/database/gdb/gdb_func.go index 6d8154429..d55885f5e 100644 --- a/database/gdb/gdb_func.go +++ b/database/gdb/gdb_func.go @@ -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: diff --git a/database/gdb/gdb_z_mysql_model_test.go b/database/gdb/gdb_z_mysql_model_test.go index a8f0db125..1adae244b 100644 --- a/database/gdb/gdb_z_mysql_model_test.go +++ b/database/gdb/gdb_z_mysql_model_test.go @@ -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) {