add test and fix bug

This commit is contained in:
Yuyang Gong 2019-07-28 20:14:51 +08:00
parent d25d5bdf9c
commit a64f22fd4d
2 changed files with 16 additions and 0 deletions

View File

@ -23,6 +23,11 @@ type RowsQueryResult struct {
func rowQueryCallback(scope *Scope) { func rowQueryCallback(scope *Scope) {
if result, ok := scope.InstanceGet("row_query_result"); ok { if result, ok := scope.InstanceGet("row_query_result"); ok {
scope.prepareQuerySQL() scope.prepareQuerySQL()
if str, ok := scope.Get("gorm:query_hint"); ok {
scope.SQL = fmt.Sprint(str) + scope.SQL
}
if str, ok := scope.Get("gorm:query_option"); ok { if str, ok := scope.Get("gorm:query_option"); ok {
scope.SQL += addExtraSpaceIfExist(fmt.Sprint(str)) scope.SQL += addExtraSpaceIfExist(fmt.Sprint(str))
} }

View File

@ -1262,6 +1262,17 @@ func TestCountWithQueryOption(t *testing.T) {
} }
} }
func TestQueryHint(t *testing.T) {
db := DB.New()
var count int
err := db.Set("gorm:query_hint", "/*master*/").Raw("select ?", "1").Count(&count).Error
if err != nil {
t.Error("Unexpected error on query_hint")
}
}
func TestFloatColumnPrecision(t *testing.T) { func TestFloatColumnPrecision(t *testing.T) {
if dialect := os.Getenv("GORM_DIALECT"); dialect != "mysql" && dialect != "sqlite" { if dialect := os.Getenv("GORM_DIALECT"); dialect != "mysql" && dialect != "sqlite" {
t.Skip() t.Skip()