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
type Dialect interface {
BinVar() string
BinVar(i int) string
SupportLastInsertId() bool
SqlTag(column interface{}, size int) string
PrimaryKeyTag(column interface{}, size int) string

View File

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

View File

@ -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 {

View File

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

2
do.go
View File

@ -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) {

View File

@ -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)
}

View File

@ -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)
}