Fix complicated Select

This commit is contained in:
Jinzhu 2015-08-01 11:49:34 +08:00
parent f07216e90e
commit e2e417a8c2
2 changed files with 3 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import (
"fmt"
"reflect"
"github.com/jinzhu/gorm"
"github.com/jinzhu/now"
"testing"
@ -556,7 +557,7 @@ func TestSelectWithEscapedFieldName(t *testing.T) {
func TestSelectWithVariables(t *testing.T) {
DB.Save(&User{Name: "jinzhu"})
rows, _ := DB.Table("users").Select("? as fake", "name").Rows()
rows, _ := DB.Table("users").Select("? as fake", gorm.Expr("name")).Rows()
if !rows.Next() {
t.Errorf("Should have returned at least one row")

View File

@ -149,7 +149,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.Dialect().Quote(fmt.Sprintf("%v", arg)), 1)
str = strings.Replace(str, "?", scope.AddToVars(arg), 1)
}
}
return