mirror of https://github.com/go-gorm/gorm.git
AddVar accept writer
This commit is contained in:
parent
504f42760a
commit
2a0c3e39f2
|
@ -38,8 +38,9 @@ func (dialector Dialector) Migrator(db *gorm.DB) gorm.Migrator {
|
|||
}}}
|
||||
}
|
||||
|
||||
func (dialector Dialector) BindVar(stmt *gorm.Statement, v interface{}) string {
|
||||
return "@p" + strconv.Itoa(len(stmt.Vars))
|
||||
func (dialector Dialector) BindVarTo(writer clause.Writer, stmt *gorm.Statement, v interface{}) {
|
||||
writer.WriteString("@p")
|
||||
writer.WriteString(strconv.Itoa(len(stmt.Vars)))
|
||||
}
|
||||
|
||||
func (dialector Dialector) QuoteTo(writer clause.Writer, str string) {
|
||||
|
|
|
@ -36,8 +36,8 @@ func (dialector Dialector) Migrator(db *gorm.DB) gorm.Migrator {
|
|||
}}}
|
||||
}
|
||||
|
||||
func (dialector Dialector) BindVar(stmt *gorm.Statement, v interface{}) string {
|
||||
return "?"
|
||||
func (dialector Dialector) BindVarTo(writer clause.Writer, stmt *gorm.Statement, v interface{}) {
|
||||
writer.WriteByte('?')
|
||||
}
|
||||
|
||||
func (dialector Dialector) QuoteTo(writer clause.Writer, str string) {
|
||||
|
|
|
@ -38,8 +38,9 @@ func (dialector Dialector) Migrator(db *gorm.DB) gorm.Migrator {
|
|||
}}}
|
||||
}
|
||||
|
||||
func (dialector Dialector) BindVar(stmt *gorm.Statement, v interface{}) string {
|
||||
return "$" + strconv.Itoa(len(stmt.Vars))
|
||||
func (dialector Dialector) BindVarTo(writer clause.Writer, stmt *gorm.Statement, v interface{}) {
|
||||
writer.WriteByte('$')
|
||||
writer.WriteString(strconv.Itoa(len(stmt.Vars)))
|
||||
}
|
||||
|
||||
func (dialector Dialector) QuoteTo(writer clause.Writer, str string) {
|
||||
|
|
|
@ -35,8 +35,8 @@ func (dialector Dialector) Migrator(db *gorm.DB) gorm.Migrator {
|
|||
}}}
|
||||
}
|
||||
|
||||
func (dialector Dialector) BindVar(stmt *gorm.Statement, v interface{}) string {
|
||||
return "?"
|
||||
func (dialector Dialector) BindVarTo(writer clause.Writer, stmt *gorm.Statement, v interface{}) {
|
||||
writer.WriteByte('?')
|
||||
}
|
||||
|
||||
func (dialector Dialector) QuoteTo(writer clause.Writer, str string) {
|
||||
|
|
|
@ -13,7 +13,7 @@ type Dialector interface {
|
|||
Initialize(*DB) error
|
||||
Migrator(db *DB) Migrator
|
||||
DataTypeOf(*schema.Field) string
|
||||
BindVar(stmt *Statement, v interface{}) string
|
||||
BindVarTo(writer clause.Writer, stmt *Statement, v interface{})
|
||||
QuoteTo(clause.Writer, string)
|
||||
Explain(sql string, vars ...interface{}) string
|
||||
}
|
||||
|
|
|
@ -120,7 +120,7 @@ func (stmt *Statement) AddVar(writer clause.Writer, vars ...interface{}) {
|
|||
writer.WriteString(v.Name)
|
||||
} else {
|
||||
stmt.Vars = append(stmt.Vars, v.Value)
|
||||
writer.WriteString(stmt.DB.Dialector.BindVar(stmt, v.Value))
|
||||
stmt.DB.Dialector.BindVarTo(writer, stmt, v.Value)
|
||||
}
|
||||
case clause.Column, clause.Table:
|
||||
stmt.QuoteTo(writer, v)
|
||||
|
@ -130,7 +130,6 @@ func (stmt *Statement) AddVar(writer clause.Writer, vars ...interface{}) {
|
|||
case []interface{}:
|
||||
if len(v) > 0 {
|
||||
writer.WriteByte('(')
|
||||
stmt.skipResetPlacehodler = true
|
||||
stmt.AddVar(writer, v...)
|
||||
writer.WriteByte(')')
|
||||
} else {
|
||||
|
@ -138,7 +137,7 @@ func (stmt *Statement) AddVar(writer clause.Writer, vars ...interface{}) {
|
|||
}
|
||||
default:
|
||||
stmt.Vars = append(stmt.Vars, v)
|
||||
writer.WriteString(stmt.DB.Dialector.BindVar(stmt, v))
|
||||
stmt.DB.Dialector.BindVarTo(writer, stmt, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,8 +18,8 @@ func (DummyDialector) Migrator(*gorm.DB) gorm.Migrator {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (DummyDialector) BindVar(stmt *gorm.Statement, v interface{}) string {
|
||||
return "?"
|
||||
func (DummyDialector) BindVarTo(writer clause.Writer, stmt *gorm.Statement, v interface{}) {
|
||||
writer.WriteByte('?')
|
||||
}
|
||||
|
||||
func (DummyDialector) QuoteTo(writer clause.Writer, str string) {
|
||||
|
|
Loading…
Reference in New Issue