diff --git a/go.mod b/go.mod index 2a63fb5d053..e19e2d23280 100644 --- a/go.mod +++ b/go.mod @@ -114,7 +114,7 @@ require ( mvdan.cc/xurls/v2 v2.1.0 strk.kbt.io/projects/go/libravatar v0.0.0-20191008002943-06d1c002b251 xorm.io/builder v0.3.7 - xorm.io/xorm v1.0.4 + xorm.io/xorm v1.0.5 ) replace github.com/hashicorp/go-version => github.com/6543/go-version v1.2.3 diff --git a/go.sum b/go.sum index 04c55ce7df6..6970a6ee439 100644 --- a/go.sum +++ b/go.sum @@ -1228,5 +1228,5 @@ xorm.io/builder v0.3.7/go.mod h1:aUW0S9eb9VCaPohFCH3j7czOx1PMW3i1HrSzbLYGBSE= xorm.io/core v0.7.2 h1:mEO22A2Z7a3fPaZMk6gKL/jMD80iiyNwRrX5HOv3XLw= xorm.io/core v0.7.2/go.mod h1:jJfd0UAEzZ4t87nbQYtVjmqpIODugN6PD2D9E+dJvdM= xorm.io/xorm v0.8.0/go.mod h1:ZkJLEYLoVyg7amJK/5r779bHyzs2AU8f8VMiP6BM7uY= -xorm.io/xorm v1.0.4 h1:UBXA4I3NhiyjXfPqxXUkS2t5hMta9SSPATeMMaZg9oA= -xorm.io/xorm v1.0.4/go.mod h1:uF9EtbhODq5kNWxMbnBEj8hRRZnlcNSz2t2N7HW/+A4= +xorm.io/xorm v1.0.5 h1:LRr5PfOUb4ODPR63YwbowkNDwcolT2LnkwP/TUaMaB0= +xorm.io/xorm v1.0.5/go.mod h1:uF9EtbhODq5kNWxMbnBEj8hRRZnlcNSz2t2N7HW/+A4= diff --git a/vendor/modules.txt b/vendor/modules.txt index 3a09a263b7e..87b0687cdcd 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -953,7 +953,7 @@ strk.kbt.io/projects/go/libravatar # xorm.io/builder v0.3.7 ## explicit xorm.io/builder -# xorm.io/xorm v1.0.4 +# xorm.io/xorm v1.0.5 ## explicit xorm.io/xorm xorm.io/xorm/caches diff --git a/vendor/xorm.io/xorm/CHANGELOG.md b/vendor/xorm.io/xorm/CHANGELOG.md index fa0259bc73e..3cead87d00b 100644 --- a/vendor/xorm.io/xorm/CHANGELOG.md +++ b/vendor/xorm.io/xorm/CHANGELOG.md @@ -3,6 +3,25 @@ This changelog goes through all the changes that have been made in each release without substantial changes to our git log. +## [1.0.5](https://gitea.com/xorm/xorm/pulls?q=&type=all&state=closed&milestone=1299) - 2020-09-08 + +* BUGFIXES + * Fix bug of ToDB when update on a nil pointer (#1786) + * Fix warnings with schema Sync2 with default varchar as NVARCHAR (#1783) + * Do not ever quote asterisk symbol. Fixes #1780 (#1781) + * Fix bug on get columns for postgres (#1779) + +## [1.0.4](https://gitea.com/xorm/xorm/pulls?q=&type=all&state=closed&milestone=1286) - 2020-09-02 + +* FEATURES + * Add params for mssql to allow redefine varchar as nvarchar or char as nchar (#1741) +* BUGFIXES + * Fix mysql dialect error from invalid db identifier in orderby clause (#1743) (#1751) +* ENHANCEMENTS + * Support get dataSourceName on ContextHook for monitor which DB executed SQL (#1740) +* MISC + * Correct default detection in MariaDB >= 10.2.7 (#1778) + ## [1.0.3](https://gitea.com/xorm/xorm/pulls?q=&type=all&state=closed&milestone=1281) - 2020-07-10 * BUGFIXES diff --git a/vendor/xorm.io/xorm/Makefile b/vendor/xorm.io/xorm/Makefile index ed873883f27..092f23b3b34 100644 --- a/vendor/xorm.io/xorm/Makefile +++ b/vendor/xorm.io/xorm/Makefile @@ -22,6 +22,7 @@ TEST_MSSQL_USERNAME ?= sa TEST_MSSQL_PASSWORD ?= MwantsaSecurePassword1 TEST_MSSQL_DEFAULT_VARCHAR ?= varchar TEST_MSSQL_DEFAULT_CHAR ?= char +TEST_MSSQL_DO_NVARCHAR_OVERRIDE_TEST ?= true TEST_MYSQL_HOST ?= mysql:3306 TEST_MYSQL_CHARSET ?= utf8 @@ -147,6 +148,7 @@ test-mssql: go-check $(GO) test $(INTEGRATION_PACKAGES) -v -race -db=mssql -cache=$(TEST_CACHE_ENABLE) -quote=$(TEST_QUOTE_POLICY) \ -conn_str="server=$(TEST_MSSQL_HOST);user id=$(TEST_MSSQL_USERNAME);password=$(TEST_MSSQL_PASSWORD);database=$(TEST_MSSQL_DBNAME)" \ -default_varchar=$(TEST_MSSQL_DEFAULT_VARCHAR) -default_char=$(TEST_MSSQL_DEFAULT_CHAR) \ + -do_nvarchar_override_test=$(TEST_MSSQL_DO_NVARCHAR_OVERRIDE_TEST) \ -coverprofile=mssql.$(TEST_QUOTE_POLICY).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic .PNONY: test-mssql\#% @@ -154,6 +156,7 @@ test-mssql\#%: go-check $(GO) test $(INTEGRATION_PACKAGES) -v -race -run $* -db=mssql -cache=$(TEST_CACHE_ENABLE) -quote=$(TEST_QUOTE_POLICY) \ -conn_str="server=$(TEST_MSSQL_HOST);user id=$(TEST_MSSQL_USERNAME);password=$(TEST_MSSQL_PASSWORD);database=$(TEST_MSSQL_DBNAME)" \ -default_varchar=$(TEST_MSSQL_DEFAULT_VARCHAR) -default_char=$(TEST_MSSQL_DEFAULT_CHAR) \ + -do_nvarchar_override_test=$(TEST_MSSQL_DO_NVARCHAR_OVERRIDE_TEST) \ -coverprofile=mssql.$(TEST_QUOTE_POLICY).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic .PNONY: test-mymysql diff --git a/vendor/xorm.io/xorm/dialects/mssql.go b/vendor/xorm.io/xorm/dialects/mssql.go index d76a8c6c11a..8e76e53855b 100644 --- a/vendor/xorm.io/xorm/dialects/mssql.go +++ b/vendor/xorm.io/xorm/dialects/mssql.go @@ -229,7 +229,7 @@ func (db *mssql) SetParams(params map[string]string) { var t = strings.ToUpper(defaultVarchar) switch t { case "NVARCHAR", "VARCHAR": - db.defaultVarchar = defaultVarchar + db.defaultVarchar = t default: db.defaultVarchar = "VARCHAR" } @@ -242,7 +242,7 @@ func (db *mssql) SetParams(params map[string]string) { var t = strings.ToUpper(defaultChar) switch t { case "NCHAR", "CHAR": - db.defaultChar = defaultChar + db.defaultChar = t default: db.defaultChar = "CHAR" } @@ -285,7 +285,7 @@ func (db *mssql) SQLType(c *schemas.Column) string { case schemas.MediumInt: res = schemas.Int case schemas.Text, schemas.MediumText, schemas.TinyText, schemas.LongText, schemas.Json: - res = schemas.Varchar + "(MAX)" + res = db.defaultVarchar + "(MAX)" case schemas.Double: res = schemas.Real case schemas.Uuid: @@ -297,10 +297,26 @@ func (db *mssql) SQLType(c *schemas.Column) string { case schemas.BigInt: res = schemas.BigInt c.Length = 0 + case schemas.NVarchar: + res = t + if c.Length == -1 { + res += "(MAX)" + } case schemas.Varchar: res = db.defaultVarchar + if c.Length == -1 { + res += "(MAX)" + } case schemas.Char: res = db.defaultChar + if c.Length == -1 { + res += "(MAX)" + } + case schemas.NChar: + res = t + if c.Length == -1 { + res += "(MAX)" + } default: res = t } @@ -424,8 +440,18 @@ func (db *mssql) GetColumns(queryer core.Queryer, ctx context.Context, tableName col.SQLType = schemas.SQLType{Name: schemas.TimeStampz, DefaultLength: 0, DefaultLength2: 0} case "NVARCHAR": col.SQLType = schemas.SQLType{Name: schemas.NVarchar, DefaultLength: 0, DefaultLength2: 0} + if col.Length > 0 { + col.Length /= 2 + col.Length2 /= 2 + } case "IMAGE": col.SQLType = schemas.SQLType{Name: schemas.VarBinary, DefaultLength: 0, DefaultLength2: 0} + case "NCHAR": + if col.Length > 0 { + col.Length /= 2 + col.Length2 /= 2 + } + fallthrough default: if _, ok := schemas.SqlTypes[ct]; ok { col.SQLType = schemas.SQLType{Name: ct, DefaultLength: 0, DefaultLength2: 0} diff --git a/vendor/xorm.io/xorm/dialects/postgres.go b/vendor/xorm.io/xorm/dialects/postgres.go index 1996c49dea6..a2c0de74f0f 100644 --- a/vendor/xorm.io/xorm/dialects/postgres.go +++ b/vendor/xorm.io/xorm/dialects/postgres.go @@ -857,6 +857,8 @@ func (db *postgres) SQLType(c *schemas.Column) string { res = schemas.Real case schemas.TinyText, schemas.MediumText, schemas.LongText: res = schemas.Text + case schemas.NChar: + res = schemas.Char case schemas.NVarchar: res = schemas.Varchar case schemas.Uuid: @@ -1015,7 +1017,7 @@ WHERE n.nspname= s.table_schema AND c.relkind = 'r'::char AND c.relname = $1%s A schema := db.getSchema() if schema != "" { - s = fmt.Sprintf(s, "AND s.table_schema = $2") + s = fmt.Sprintf(s, " AND s.table_schema = $2") args = append(args, schema) } else { s = fmt.Sprintf(s, "") @@ -1086,8 +1088,10 @@ WHERE n.nspname= s.table_schema AND c.relkind = 'r'::char AND c.relname = $1%s A col.Nullable = (isNullable == "YES") switch strings.ToLower(dataType) { - case "character varying", "character", "string": + case "character varying", "string": col.SQLType = schemas.SQLType{Name: schemas.Varchar, DefaultLength: 0, DefaultLength2: 0} + case "character": + col.SQLType = schemas.SQLType{Name: schemas.Char, DefaultLength: 0, DefaultLength2: 0} case "timestamp without time zone": col.SQLType = schemas.SQLType{Name: schemas.DateTime, DefaultLength: 0, DefaultLength2: 0} case "timestamp with time zone": diff --git a/vendor/xorm.io/xorm/internal/statements/update.go b/vendor/xorm.io/xorm/internal/statements/update.go index b6ae118e0f4..ff5f82b7316 100644 --- a/vendor/xorm.io/xorm/internal/statements/update.go +++ b/vendor/xorm.io/xorm/internal/statements/update.go @@ -130,7 +130,7 @@ func (statement *Statement) BuildUpdates(tableValue reflect.Value, } } - if structConvert, ok := fieldValue.Interface().(convert.Conversion); ok { + if structConvert, ok := fieldValue.Interface().(convert.Conversion); ok && !fieldValue.IsNil() { data, err := structConvert.ToDB() if err != nil { return nil, nil, err diff --git a/vendor/xorm.io/xorm/internal/statements/values.go b/vendor/xorm.io/xorm/internal/statements/values.go index a1102c54a2c..99eaa766911 100644 --- a/vendor/xorm.io/xorm/internal/statements/values.go +++ b/vendor/xorm.io/xorm/internal/statements/values.go @@ -36,18 +36,21 @@ func (statement *Statement) Value2Interface(col *schemas.Column, fieldValue refl } } - if fieldConvert, ok := fieldValue.Interface().(convert.Conversion); ok { - data, err := fieldConvert.ToDB() - if err != nil { - return nil, err + isNil := fieldValue.Kind() == reflect.Ptr && fieldValue.IsNil() + if !isNil { + if fieldConvert, ok := fieldValue.Interface().(convert.Conversion); ok { + data, err := fieldConvert.ToDB() + if err != nil { + return nil, err + } + if col.SQLType.IsBlob() { + return data, nil + } + if nil == data { + return nil, nil + } + return string(data), nil } - if col.SQLType.IsBlob() { - return data, nil - } - if nil == data { - return nil, nil - } - return string(data), nil } fieldType := fieldValue.Type() diff --git a/vendor/xorm.io/xorm/schemas/quote.go b/vendor/xorm.io/xorm/schemas/quote.go index c44abe250f8..a0070048a0b 100644 --- a/vendor/xorm.io/xorm/schemas/quote.go +++ b/vendor/xorm.io/xorm/schemas/quote.go @@ -82,9 +82,7 @@ func (q Quoter) JoinWrite(b *strings.Builder, a []string, sep string) error { return err } } - if s != "*" { - q.QuoteTo(b, strings.TrimSpace(s)) - } + q.QuoteTo(b, strings.TrimSpace(s)) } return nil } @@ -143,7 +141,7 @@ func (q Quoter) quoteWordTo(buf *strings.Builder, word string) error { } isReserved := q.IsReserved(realWord) - if isReserved { + if isReserved && realWord != "*" { if err := buf.WriteByte(q.Prefix); err != nil { return err } @@ -151,7 +149,7 @@ func (q Quoter) quoteWordTo(buf *strings.Builder, word string) error { if _, err := buf.WriteString(realWord); err != nil { return err } - if isReserved { + if isReserved && realWord != "*" { return buf.WriteByte(q.Suffix) }