Fix binvar for mysql

This commit is contained in:
Jinzhu 2013-11-16 20:47:25 +08:00
parent 6404f803e8
commit ba6403f904
7 changed files with 7 additions and 14 deletions

View File

@ -1,7 +1,7 @@
package dialect package dialect
type Dialect interface { type Dialect interface {
BinVar() string BinVar(i int) string
SupportLastInsertId() bool SupportLastInsertId() bool
SqlTag(column interface{}, size int) string SqlTag(column interface{}, size int) string
PrimaryKeyTag(column interface{}, size int) string PrimaryKeyTag(column interface{}, size int) string

View File

@ -8,7 +8,7 @@ import (
type mysql struct{} type mysql struct{}
func (s *mysql) BinVar() string { func (s *mysql) BinVar(i int) string {
return "?" return "?"
} }

View File

@ -9,8 +9,8 @@ import (
type postgres struct { type postgres struct {
} }
func (s *postgres) BinVar() string { func (s *postgres) BinVar(i int) string {
return "$%v" return fmt.Sprintf("$%v", i)
} }
func (s *postgres) SupportLastInsertId() bool { func (s *postgres) SupportLastInsertId() bool {

View File

@ -8,7 +8,7 @@ import (
type sqlite3 struct{} type sqlite3 struct{}
func (s *sqlite3) BinVar() string { func (s *sqlite3) BinVar(i int) string {
return "?" return "?"
} }

2
do.go
View File

@ -58,7 +58,7 @@ func (s *Do) setModel(value interface{}) *Do {
func (s *Do) addToVars(value interface{}) string { func (s *Do) addToVars(value interface{}) string {
s.sqlVars = append(s.sqlVars, value) 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) { func (s *Do) trace(t time.Time) {

View File

@ -96,8 +96,7 @@ func init() {
db.SetPool(10) db.SetPool(10)
err = db.DropTable(&User{}).Error if err := db.DropTable(&User{}).Error; err != nil {
if err != nil {
fmt.Printf("Got error when try to delete table users, %+v\n", err) fmt.Printf("Got error when try to delete table users, %+v\n", err)
} }

View File

@ -3,7 +3,6 @@ package gorm
import ( import (
"bytes" "bytes"
"database/sql" "database/sql"
"fmt"
"reflect" "reflect"
"strconv" "strconv"
@ -98,8 +97,3 @@ func isBlank(value reflect.Value) bool {
} }
return false return false
} }
func debug(values ...interface{}) {
fmt.Println("*****************")
fmt.Println(values)
}