From e2e417a8c28526667a54311d42980e966e5e2809 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Sat, 1 Aug 2015 11:49:34 +0800 Subject: [PATCH] Fix complicated Select --- query_test.go | 3 ++- scope_private.go | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/query_test.go b/query_test.go index b15d01ba..580d06c4 100644 --- a/query_test.go +++ b/query_test.go @@ -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") diff --git a/scope_private.go b/scope_private.go index fdf14dc7..4344f22e 100644 --- a/scope_private.go +++ b/scope_private.go @@ -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