Fix query with extra option

This commit is contained in:
Jinzhu 2016-02-15 19:42:49 +08:00
parent c9dfd80959
commit b054f235b9
1 changed files with 4 additions and 5 deletions

View File

@ -51,13 +51,12 @@ func queryCallback(scope *Scope) {
scope.prepareQuerySql() scope.prepareQuerySql()
if !scope.HasError() { if !scope.HasError() {
var extraOption string
if str, ok := scope.Get("gorm:query_option"); ok {
extraOption = fmt.Sprint(str)
}
scope.db.RowsAffected = 0 scope.db.RowsAffected = 0
if str, ok := scope.Get("gorm:query_option"); ok {
scope.Sql += addExtraSpaceIfExist(fmt.Sprint(str))
}
if rows, err := scope.SqlDB().Query(scope.Sql+addExtraSpaceIfExist(extraOption), scope.SqlVars...); scope.Err(err) == nil { if rows, err := scope.SqlDB().Query(scope.Sql, scope.SqlVars...); scope.Err(err) == nil {
defer rows.Close() defer rows.Close()
columns, _ := rows.Columns() columns, _ := rows.Columns()