diff --git a/query_test.go b/query_test.go index d4a68aa1..09b6c702 100644 --- a/query_test.go +++ b/query_test.go @@ -6,7 +6,6 @@ import ( "github.com/jinzhu/now" - "math/rand" "testing" "time" ) @@ -542,11 +541,15 @@ func TestSelectWithEscapedFieldName(t *testing.T) { func TestSelectWithVariables(t *testing.T) { DB.Save(&User{Name: "jinzhu"}) - randomNum := rand.Intn(1000000000) - rows, _ := DB.Table("users").Select("? as fake", randomNum).Where("fake = ?", randomNum).Rows() + rows, _ := DB.Table("users").Select("? as fake", "name").Rows() if !rows.Next() { t.Errorf("Should have returned at least one row") + } else { + columns, _ := rows.Columns() + if !reflect.DeepEqual(columns, []string{"fake"}) { + t.Errorf("Should only contains one column") + } } } diff --git a/scope_private.go b/scope_private.go index 2d99e81d..e36dbec7 100644 --- a/scope_private.go +++ b/scope_private.go @@ -152,7 +152,7 @@ func (scope *Scope) buildSelectQuery(clause map[string]interface{}) (str string) if valuer, ok := interface{}(arg).(driver.Valuer); ok { arg, _ = valuer.Value() } - str = strings.Replace(str, "?", scope.AddToVars(arg), 1) + str = strings.Replace(str, "?", scope.Dialect().Quote(fmt.Sprintf("%v", arg)), 1) } } return