diff --git a/dialect/dialect.go b/dialect/dialect.go index 4120985e..f21e1876 100644 --- a/dialect/dialect.go +++ b/dialect/dialect.go @@ -1,7 +1,7 @@ package dialect type Dialect interface { - BinVar() string + BinVar(i int) string SupportLastInsertId() bool SqlTag(column interface{}, size int) string PrimaryKeyTag(column interface{}, size int) string diff --git a/dialect/mysql.go b/dialect/mysql.go index f9e05170..0e71612b 100644 --- a/dialect/mysql.go +++ b/dialect/mysql.go @@ -8,7 +8,7 @@ import ( type mysql struct{} -func (s *mysql) BinVar() string { +func (s *mysql) BinVar(i int) string { return "?" } diff --git a/dialect/postgres.go b/dialect/postgres.go index 833a4a09..13a0afa0 100644 --- a/dialect/postgres.go +++ b/dialect/postgres.go @@ -9,8 +9,8 @@ import ( type postgres struct { } -func (s *postgres) BinVar() string { - return "$%v" +func (s *postgres) BinVar(i int) string { + return fmt.Sprintf("$%v", i) } func (s *postgres) SupportLastInsertId() bool { diff --git a/dialect/sqlite3.go b/dialect/sqlite3.go index c6731b6d..f413bd14 100644 --- a/dialect/sqlite3.go +++ b/dialect/sqlite3.go @@ -8,7 +8,7 @@ import ( type sqlite3 struct{} -func (s *sqlite3) BinVar() string { +func (s *sqlite3) BinVar(i int) string { return "?" } diff --git a/do.go b/do.go index 8a7a3aab..db2974f4 100644 --- a/do.go +++ b/do.go @@ -58,7 +58,7 @@ func (s *Do) setModel(value interface{}) *Do { func (s *Do) addToVars(value interface{}) string { s.sqlVars = append(s.sqlVars, value) - return fmt.Sprintf(s.dialect().BinVar(), len(s.sqlVars)) + return s.dialect().BinVar(len(s.sqlVars)) } func (s *Do) trace(t time.Time) { diff --git a/gorm_test.go b/gorm_test.go index 945c697f..e3ce416a 100644 --- a/gorm_test.go +++ b/gorm_test.go @@ -96,8 +96,7 @@ func init() { db.SetPool(10) - err = db.DropTable(&User{}).Error - if err != nil { + if err := db.DropTable(&User{}).Error; err != nil { fmt.Printf("Got error when try to delete table users, %+v\n", err) } diff --git a/utils.go b/utils.go index 7586b89c..d4897c13 100644 --- a/utils.go +++ b/utils.go @@ -3,7 +3,6 @@ package gorm import ( "bytes" "database/sql" - "fmt" "reflect" "strconv" @@ -98,8 +97,3 @@ func isBlank(value reflect.Value) bool { } return false } - -func debug(values ...interface{}) { - fmt.Println("*****************") - fmt.Println(values) -}