From f8882f4fa909905311de86e80175184954464dc1 Mon Sep 17 00:00:00 2001 From: John Olheiser <42128690+jolheiser@users.noreply.github.com> Date: Wed, 25 Sep 2019 14:02:54 -0500 Subject: [PATCH] Update xorm (#8286) Signed-off-by: jolheiser --- go.mod | 2 +- go.sum | 4 +- .../github.com/go-xorm/xorm/dialect_mssql.go | 3 ++ .../github.com/go-xorm/xorm/session_insert.go | 8 ++- .../github.com/go-xorm/xorm/statement_args.go | 53 +++++++++++++++++-- vendor/modules.txt | 2 +- 6 files changed, 61 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index 017e3f615..8981d35c0 100644 --- a/go.mod +++ b/go.mod @@ -48,7 +48,7 @@ require ( github.com/go-redis/redis v6.15.2+incompatible github.com/go-sql-driver/mysql v1.4.1 github.com/go-swagger/go-swagger v0.20.1 - github.com/go-xorm/xorm v0.7.8-0.20190924080535-59ed80ce1a67 + github.com/go-xorm/xorm v0.7.8-0.20190925172902-71947cf034b6 github.com/gobwas/glob v0.2.3 github.com/gogits/chardet v0.0.0-20150115103509-2404f7772561 github.com/gogs/cron v0.0.0-20171120032916-9f6c956d3e14 diff --git a/go.sum b/go.sum index 4607de2ce..432c6055d 100644 --- a/go.sum +++ b/go.sum @@ -250,8 +250,8 @@ github.com/go-swagger/scan-repo-boundary v0.0.0-20180623220736-973b3573c013/go.m github.com/go-xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:9wScpmSP5A3Bk8V3XHWUcJmYTh+ZnlHVyc+A4oZYS3Y= github.com/go-xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a/go.mod h1:56xuuqnHyryaerycW3BfssRdxQstACi0Epw/yC5E2xM= github.com/go-xorm/xorm v0.7.6/go.mod h1:nqz2TAsuOHWH2yk4FYWtacCGgdbrcdZ5mF1XadqEHls= -github.com/go-xorm/xorm v0.7.8-0.20190924080535-59ed80ce1a67 h1:mB5RWONyATkQ48+iQZ1lCZNPG3tABilyaEOxDm1QWyU= -github.com/go-xorm/xorm v0.7.8-0.20190924080535-59ed80ce1a67/go.mod h1:RSsmsVARCy4sayuKWFPaVNQMPYGLNRIK71YIVvgImL0= +github.com/go-xorm/xorm v0.7.8-0.20190925172902-71947cf034b6 h1:kwKsKxuD8cUIOHWaMk5nuBU9ZUTnGpN2c/e4Mt6RTAo= +github.com/go-xorm/xorm v0.7.8-0.20190925172902-71947cf034b6/go.mod h1:RSsmsVARCy4sayuKWFPaVNQMPYGLNRIK71YIVvgImL0= github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y= github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8= github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= diff --git a/vendor/github.com/go-xorm/xorm/dialect_mssql.go b/vendor/github.com/go-xorm/xorm/dialect_mssql.go index 61061cb25..ce4dd00c1 100644 --- a/vendor/github.com/go-xorm/xorm/dialect_mssql.go +++ b/vendor/github.com/go-xorm/xorm/dialect_mssql.go @@ -254,6 +254,9 @@ func (db *mssql) SqlType(c *core.Column) string { case core.TinyInt: res = core.TinyInt c.Length = 0 + case core.BigInt: + res = core.BigInt + c.Length = 0 default: res = t } diff --git a/vendor/github.com/go-xorm/xorm/session_insert.go b/vendor/github.com/go-xorm/xorm/session_insert.go index de6452909..1e19ce7a4 100644 --- a/vendor/github.com/go-xorm/xorm/session_insert.go +++ b/vendor/github.com/go-xorm/xorm/session_insert.go @@ -25,6 +25,12 @@ func (session *Session) Insert(beans ...interface{}) (int64, error) { defer session.Close() } + session.autoResetStatement = false + defer func() { + session.autoResetStatement = true + session.resetStatement() + }() + for _, bean := range beans { switch bean.(type) { case map[string]interface{}: @@ -35,7 +41,6 @@ func (session *Session) Insert(beans ...interface{}) (int64, error) { affected += cnt case []map[string]interface{}: s := bean.([]map[string]interface{}) - session.autoResetStatement = false for i := 0; i < len(s); i++ { cnt, err := session.insertMapInterface(s[i]) if err != nil { @@ -51,7 +56,6 @@ func (session *Session) Insert(beans ...interface{}) (int64, error) { affected += cnt case []map[string]string: s := bean.([]map[string]string) - session.autoResetStatement = false for i := 0; i < len(s); i++ { cnt, err := session.insertMapString(s[i]) if err != nil { diff --git a/vendor/github.com/go-xorm/xorm/statement_args.go b/vendor/github.com/go-xorm/xorm/statement_args.go index 4ce336f48..23496443f 100644 --- a/vendor/github.com/go-xorm/xorm/statement_args.go +++ b/vendor/github.com/go-xorm/xorm/statement_args.go @@ -6,17 +6,60 @@ package xorm import ( "fmt" + "reflect" + "strings" + "time" "xorm.io/builder" "xorm.io/core" ) +func quoteNeeded(a interface{}) bool { + switch a.(type) { + case int, int8, int16, int32, int64: + return false + case uint, uint8, uint16, uint32, uint64: + return false + case float32, float64: + return false + case bool: + return false + case string: + return true + case time.Time, *time.Time: + return true + case builder.Builder, *builder.Builder: + return false + } + + t := reflect.TypeOf(a) + switch t.Kind() { + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + return false + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: + return false + case reflect.Float32, reflect.Float64: + return false + case reflect.Bool: + return false + case reflect.String: + return true + } + + return true +} + +func convertArg(arg interface{}) string { + if quoteNeeded(arg) { + argv := fmt.Sprintf("%v", arg) + return "'" + strings.Replace(argv, "'", "''", -1) + "'" + } + + return fmt.Sprintf("%v", arg) +} + func (statement *Statement) writeArg(w *builder.BytesWriter, arg interface{}) error { switch argv := arg.(type) { - case string: - if _, err := w.WriteString("'" + argv + "'"); err != nil { - return err - } case bool: if statement.Engine.dialect.DBType() == core.MSSQL { if argv { @@ -50,7 +93,7 @@ func (statement *Statement) writeArg(w *builder.BytesWriter, arg interface{}) er return err } default: - if _, err := w.WriteString(fmt.Sprintf("%v", argv)); err != nil { + if _, err := w.WriteString(convertArg(arg)); err != nil { return err } } diff --git a/vendor/modules.txt b/vendor/modules.txt index 56df013a5..d64735c5f 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -198,7 +198,7 @@ github.com/go-swagger/go-swagger/cmd/swagger/commands/initcmd github.com/go-swagger/go-swagger/codescan github.com/go-swagger/go-swagger/generator github.com/go-swagger/go-swagger/scan -# github.com/go-xorm/xorm v0.7.8-0.20190924080535-59ed80ce1a67 +# github.com/go-xorm/xorm v0.7.8-0.20190925172902-71947cf034b6 github.com/go-xorm/xorm # github.com/gobwas/glob v0.2.3 github.com/gobwas/glob