Upgrade xorm to v1.0.5 (#12765)

Co-authored-by: techknowlogick <techknowlogick@gitea.io>
release/v1.15
Lunny Xiao 2020-09-09 01:57:19 +08:00 committed by GitHub
parent 3865ecbf13
commit bea343ce09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 79 additions and 26 deletions

2
go.mod
View File

@ -114,7 +114,7 @@ require (
mvdan.cc/xurls/v2 v2.1.0 mvdan.cc/xurls/v2 v2.1.0
strk.kbt.io/projects/go/libravatar v0.0.0-20191008002943-06d1c002b251 strk.kbt.io/projects/go/libravatar v0.0.0-20191008002943-06d1c002b251
xorm.io/builder v0.3.7 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 replace github.com/hashicorp/go-version => github.com/6543/go-version v1.2.3

4
go.sum
View File

@ -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 h1:mEO22A2Z7a3fPaZMk6gKL/jMD80iiyNwRrX5HOv3XLw=
xorm.io/core v0.7.2/go.mod h1:jJfd0UAEzZ4t87nbQYtVjmqpIODugN6PD2D9E+dJvdM= 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 v0.8.0/go.mod h1:ZkJLEYLoVyg7amJK/5r779bHyzs2AU8f8VMiP6BM7uY=
xorm.io/xorm v1.0.4 h1:UBXA4I3NhiyjXfPqxXUkS2t5hMta9SSPATeMMaZg9oA= xorm.io/xorm v1.0.5 h1:LRr5PfOUb4ODPR63YwbowkNDwcolT2LnkwP/TUaMaB0=
xorm.io/xorm v1.0.4/go.mod h1:uF9EtbhODq5kNWxMbnBEj8hRRZnlcNSz2t2N7HW/+A4= xorm.io/xorm v1.0.5/go.mod h1:uF9EtbhODq5kNWxMbnBEj8hRRZnlcNSz2t2N7HW/+A4=

2
vendor/modules.txt vendored
View File

@ -953,7 +953,7 @@ strk.kbt.io/projects/go/libravatar
# xorm.io/builder v0.3.7 # xorm.io/builder v0.3.7
## explicit ## explicit
xorm.io/builder xorm.io/builder
# xorm.io/xorm v1.0.4 # xorm.io/xorm v1.0.5
## explicit ## explicit
xorm.io/xorm xorm.io/xorm
xorm.io/xorm/caches xorm.io/xorm/caches

19
vendor/xorm.io/xorm/CHANGELOG.md generated vendored
View File

@ -3,6 +3,25 @@
This changelog goes through all the changes that have been made in each release This changelog goes through all the changes that have been made in each release
without substantial changes to our git log. 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 ## [1.0.3](https://gitea.com/xorm/xorm/pulls?q=&type=all&state=closed&milestone=1281) - 2020-07-10
* BUGFIXES * BUGFIXES

3
vendor/xorm.io/xorm/Makefile generated vendored
View File

@ -22,6 +22,7 @@ TEST_MSSQL_USERNAME ?= sa
TEST_MSSQL_PASSWORD ?= MwantsaSecurePassword1 TEST_MSSQL_PASSWORD ?= MwantsaSecurePassword1
TEST_MSSQL_DEFAULT_VARCHAR ?= varchar TEST_MSSQL_DEFAULT_VARCHAR ?= varchar
TEST_MSSQL_DEFAULT_CHAR ?= char TEST_MSSQL_DEFAULT_CHAR ?= char
TEST_MSSQL_DO_NVARCHAR_OVERRIDE_TEST ?= true
TEST_MYSQL_HOST ?= mysql:3306 TEST_MYSQL_HOST ?= mysql:3306
TEST_MYSQL_CHARSET ?= utf8 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) \ $(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)" \ -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) \ -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 -coverprofile=mssql.$(TEST_QUOTE_POLICY).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
.PNONY: test-mssql\#% .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) \ $(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)" \ -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) \ -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 -coverprofile=mssql.$(TEST_QUOTE_POLICY).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic
.PNONY: test-mymysql .PNONY: test-mymysql

View File

@ -229,7 +229,7 @@ func (db *mssql) SetParams(params map[string]string) {
var t = strings.ToUpper(defaultVarchar) var t = strings.ToUpper(defaultVarchar)
switch t { switch t {
case "NVARCHAR", "VARCHAR": case "NVARCHAR", "VARCHAR":
db.defaultVarchar = defaultVarchar db.defaultVarchar = t
default: default:
db.defaultVarchar = "VARCHAR" db.defaultVarchar = "VARCHAR"
} }
@ -242,7 +242,7 @@ func (db *mssql) SetParams(params map[string]string) {
var t = strings.ToUpper(defaultChar) var t = strings.ToUpper(defaultChar)
switch t { switch t {
case "NCHAR", "CHAR": case "NCHAR", "CHAR":
db.defaultChar = defaultChar db.defaultChar = t
default: default:
db.defaultChar = "CHAR" db.defaultChar = "CHAR"
} }
@ -285,7 +285,7 @@ func (db *mssql) SQLType(c *schemas.Column) string {
case schemas.MediumInt: case schemas.MediumInt:
res = schemas.Int res = schemas.Int
case schemas.Text, schemas.MediumText, schemas.TinyText, schemas.LongText, schemas.Json: case schemas.Text, schemas.MediumText, schemas.TinyText, schemas.LongText, schemas.Json:
res = schemas.Varchar + "(MAX)" res = db.defaultVarchar + "(MAX)"
case schemas.Double: case schemas.Double:
res = schemas.Real res = schemas.Real
case schemas.Uuid: case schemas.Uuid:
@ -297,10 +297,26 @@ func (db *mssql) SQLType(c *schemas.Column) string {
case schemas.BigInt: case schemas.BigInt:
res = schemas.BigInt res = schemas.BigInt
c.Length = 0 c.Length = 0
case schemas.NVarchar:
res = t
if c.Length == -1 {
res += "(MAX)"
}
case schemas.Varchar: case schemas.Varchar:
res = db.defaultVarchar res = db.defaultVarchar
if c.Length == -1 {
res += "(MAX)"
}
case schemas.Char: case schemas.Char:
res = db.defaultChar res = db.defaultChar
if c.Length == -1 {
res += "(MAX)"
}
case schemas.NChar:
res = t
if c.Length == -1 {
res += "(MAX)"
}
default: default:
res = t 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} col.SQLType = schemas.SQLType{Name: schemas.TimeStampz, DefaultLength: 0, DefaultLength2: 0}
case "NVARCHAR": case "NVARCHAR":
col.SQLType = schemas.SQLType{Name: schemas.NVarchar, DefaultLength: 0, DefaultLength2: 0} col.SQLType = schemas.SQLType{Name: schemas.NVarchar, DefaultLength: 0, DefaultLength2: 0}
if col.Length > 0 {
col.Length /= 2
col.Length2 /= 2
}
case "IMAGE": case "IMAGE":
col.SQLType = schemas.SQLType{Name: schemas.VarBinary, DefaultLength: 0, DefaultLength2: 0} 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: default:
if _, ok := schemas.SqlTypes[ct]; ok { if _, ok := schemas.SqlTypes[ct]; ok {
col.SQLType = schemas.SQLType{Name: ct, DefaultLength: 0, DefaultLength2: 0} col.SQLType = schemas.SQLType{Name: ct, DefaultLength: 0, DefaultLength2: 0}

View File

@ -857,6 +857,8 @@ func (db *postgres) SQLType(c *schemas.Column) string {
res = schemas.Real res = schemas.Real
case schemas.TinyText, schemas.MediumText, schemas.LongText: case schemas.TinyText, schemas.MediumText, schemas.LongText:
res = schemas.Text res = schemas.Text
case schemas.NChar:
res = schemas.Char
case schemas.NVarchar: case schemas.NVarchar:
res = schemas.Varchar res = schemas.Varchar
case schemas.Uuid: 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() schema := db.getSchema()
if schema != "" { if schema != "" {
s = fmt.Sprintf(s, "AND s.table_schema = $2") s = fmt.Sprintf(s, " AND s.table_schema = $2")
args = append(args, schema) args = append(args, schema)
} else { } else {
s = fmt.Sprintf(s, "") 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") col.Nullable = (isNullable == "YES")
switch strings.ToLower(dataType) { switch strings.ToLower(dataType) {
case "character varying", "character", "string": case "character varying", "string":
col.SQLType = schemas.SQLType{Name: schemas.Varchar, DefaultLength: 0, DefaultLength2: 0} 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": case "timestamp without time zone":
col.SQLType = schemas.SQLType{Name: schemas.DateTime, DefaultLength: 0, DefaultLength2: 0} col.SQLType = schemas.SQLType{Name: schemas.DateTime, DefaultLength: 0, DefaultLength2: 0}
case "timestamp with time zone": case "timestamp with time zone":

View File

@ -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() data, err := structConvert.ToDB()
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err

View File

@ -36,18 +36,21 @@ func (statement *Statement) Value2Interface(col *schemas.Column, fieldValue refl
} }
} }
if fieldConvert, ok := fieldValue.Interface().(convert.Conversion); ok { isNil := fieldValue.Kind() == reflect.Ptr && fieldValue.IsNil()
data, err := fieldConvert.ToDB() if !isNil {
if err != nil { if fieldConvert, ok := fieldValue.Interface().(convert.Conversion); ok {
return nil, err 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() fieldType := fieldValue.Type()

View File

@ -82,9 +82,7 @@ func (q Quoter) JoinWrite(b *strings.Builder, a []string, sep string) error {
return err return err
} }
} }
if s != "*" { q.QuoteTo(b, strings.TrimSpace(s))
q.QuoteTo(b, strings.TrimSpace(s))
}
} }
return nil return nil
} }
@ -143,7 +141,7 @@ func (q Quoter) quoteWordTo(buf *strings.Builder, word string) error {
} }
isReserved := q.IsReserved(realWord) isReserved := q.IsReserved(realWord)
if isReserved { if isReserved && realWord != "*" {
if err := buf.WriteByte(q.Prefix); err != nil { if err := buf.WriteByte(q.Prefix); err != nil {
return err return err
} }
@ -151,7 +149,7 @@ func (q Quoter) quoteWordTo(buf *strings.Builder, word string) error {
if _, err := buf.WriteString(realWord); err != nil { if _, err := buf.WriteString(realWord); err != nil {
return err return err
} }
if isReserved { if isReserved && realWord != "*" {
return buf.WriteByte(q.Suffix) return buf.WriteByte(q.Suffix)
} }