Fix tests for mysql, postgres

This commit is contained in:
Jinzhu 2014-11-24 18:16:07 +08:00
parent 84954e6779
commit 1aaac379ae
2 changed files with 7 additions and 4 deletions

View File

@ -6,7 +6,6 @@ import (
"github.com/jinzhu/now" "github.com/jinzhu/now"
"math/rand"
"testing" "testing"
"time" "time"
) )
@ -542,11 +541,15 @@ func TestSelectWithEscapedFieldName(t *testing.T) {
func TestSelectWithVariables(t *testing.T) { func TestSelectWithVariables(t *testing.T) {
DB.Save(&User{Name: "jinzhu"}) DB.Save(&User{Name: "jinzhu"})
randomNum := rand.Intn(1000000000) rows, _ := DB.Table("users").Select("? as fake", "name").Rows()
rows, _ := DB.Table("users").Select("? as fake", randomNum).Where("fake = ?", randomNum).Rows()
if !rows.Next() { if !rows.Next() {
t.Errorf("Should have returned at least one row") 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")
}
} }
} }

View File

@ -152,7 +152,7 @@ func (scope *Scope) buildSelectQuery(clause map[string]interface{}) (str string)
if valuer, ok := interface{}(arg).(driver.Valuer); ok { if valuer, ok := interface{}(arg).(driver.Valuer); ok {
arg, _ = valuer.Value() arg, _ = valuer.Value()
} }
str = strings.Replace(str, "?", scope.AddToVars(arg), 1) str = strings.Replace(str, "?", scope.Dialect().Quote(fmt.Sprintf("%v", arg)), 1)
} }
} }
return return