Update xorm to latest version and fix correct user table referencing in sql (#4473)

This commit is contained in:
Lauris BH 2018-07-20 05:10:17 +03:00 committed by Lunny Xiao
parent 1e2da5d396
commit 0c59edaafa
49 changed files with 1718 additions and 1102 deletions

View file

@ -4,6 +4,10 @@
package builder
import (
"fmt"
)
type optype byte
const (
@ -29,6 +33,9 @@ type Builder struct {
joins []join
inserts Eq
updates []Eq
orderBy string
groupBy string
having string
}
// Select creates a select Builder
@ -67,6 +74,11 @@ func (b *Builder) From(tableName string) *Builder {
return b
}
// TableName returns the table name
func (b *Builder) TableName() string {
return b.tableName
}
// Into sets insert table name
func (b *Builder) Into(tableName string) *Builder {
b.tableName = tableName
@ -178,6 +190,33 @@ func (b *Builder) ToSQL() (string, []interface{}, error) {
return w.writer.String(), w.args, nil
}
// ConvertPlaceholder replaces ? to $1, $2 ... or :1, :2 ... according prefix
func ConvertPlaceholder(sql, prefix string) (string, error) {
buf := StringBuilder{}
var j, start = 0, 0
for i := 0; i < len(sql); i++ {
if sql[i] == '?' {
_, err := buf.WriteString(sql[start:i])
if err != nil {
return "", err
}
start = i + 1
_, err = buf.WriteString(prefix)
if err != nil {
return "", err
}
j = j + 1
_, err = buf.WriteString(fmt.Sprintf("%d", j))
if err != nil {
return "", err
}
}
}
return buf.String(), nil
}
// ToSQL convert a builder or condtions to SQL and args
func ToSQL(cond interface{}) (string, []interface{}, error) {
switch cond.(type) {