Fixed HasColumn, removed debug statements, improved test error messages

This commit is contained in:
Tristan Rice 2016-01-29 15:23:15 -08:00
parent 34a3fd2a3a
commit 6508b88f62
3 changed files with 4 additions and 8 deletions

View File

@ -2,7 +2,6 @@ package gorm
import ( import (
"fmt" "fmt"
"log"
"reflect" "reflect"
"time" "time"
) )
@ -105,8 +104,9 @@ func (s cockroach) HasColumn(scope *Scope, tableName string, columnName string)
} }
defer rows.Close() defer rows.Close()
var column string var column string
var typ, null, defaultVal interface{}
for rows.Next() { for rows.Next() {
if err := rows.Scan(&column); err != nil { if err := rows.Scan(&column, &typ, &null, &defaultVal); err != nil {
scope.Err(err) scope.Err(err)
return false return false
} }
@ -133,7 +133,6 @@ func (s cockroach) HasIndex(scope *Scope, tableName string, indexName string) bo
scope.Err(err) scope.Err(err)
return false return false
} }
log.Printf("HasIndex %#v %#v %#v ", table, name, indexName)
if name == indexName { if name == indexName {
return true return true
} }

View File

@ -4,7 +4,6 @@ import (
"database/sql/driver" "database/sql/driver"
"errors" "errors"
"fmt" "fmt"
"log"
"regexp" "regexp"
"strings" "strings"
"time" "time"
@ -362,8 +361,6 @@ func (scope *Scope) InstanceGet(name string) (interface{}, bool) {
// Trace print sql log // Trace print sql log
func (scope *Scope) Trace(t time.Time) { func (scope *Scope) Trace(t time.Time) {
if len(scope.Sql) > 0 { if len(scope.Sql) > 0 {
// TODO(d4l3k): Remove this line
log.Println("sql", scope.Sql, scope.SqlVars)
scope.db.slog(scope.Sql, t, scope.SqlVars...) scope.db.slog(scope.Sql, t, scope.SqlVars...)
} }
} }

View File

@ -20,13 +20,13 @@ func TestScannableSlices(t *testing.T) {
} }
if err := DB.Save(&r1).Error; err != nil { if err := DB.Save(&r1).Error; err != nil {
t.Errorf("Should save record with slice values") t.Errorf("Should save record with slice values; err %s", err)
} }
var r2 RecordWithSlice var r2 RecordWithSlice
if err := DB.Find(&r2).Error; err != nil { if err := DB.Find(&r2).Error; err != nil {
t.Errorf("Should fetch record with slice values") t.Errorf("Should fetch record with slice values; err %s", err)
} }
if len(r2.Strings) != 3 || r2.Strings[0] != "a" || r2.Strings[1] != "b" || r2.Strings[2] != "c" { if len(r2.Strings) != 3 || r2.Strings[0] != "a" || r2.Strings[1] != "b" || r2.Strings[2] != "c" {