forked from mirror/gorm
Fix complicated Select
This commit is contained in:
parent
f07216e90e
commit
e2e417a8c2
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
|
"github.com/jinzhu/gorm"
|
||||||
"github.com/jinzhu/now"
|
"github.com/jinzhu/now"
|
||||||
|
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -556,7 +557,7 @@ 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"})
|
||||||
|
|
||||||
rows, _ := DB.Table("users").Select("? as fake", "name").Rows()
|
rows, _ := DB.Table("users").Select("? as fake", gorm.Expr("name")).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")
|
||||||
|
|
|
@ -149,7 +149,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.Dialect().Quote(fmt.Sprintf("%v", arg)), 1)
|
str = strings.Replace(str, "?", scope.AddToVars(arg), 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue