upgrade xorm to v1.0.6 (#14246)

tokarchuk/v1.17
Lunny Xiao 4 years ago committed by GitHub
parent 8db0372a45
commit 126c9331d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      go.mod
  2. 4
      go.sum
  3. 2
      vendor/modules.txt
  4. 14
      vendor/xorm.io/xorm/CHANGELOG.md
  5. 2
      vendor/xorm.io/xorm/dialects/dialect.go
  6. 5
      vendor/xorm.io/xorm/dialects/mssql.go
  7. 2
      vendor/xorm.io/xorm/dialects/sqlite3.go
  8. 21
      vendor/xorm.io/xorm/engine.go
  9. 4
      vendor/xorm.io/xorm/internal/statements/statement.go
  10. 2
      vendor/xorm.io/xorm/internal/statements/update.go
  11. 2
      vendor/xorm.io/xorm/internal/statements/values.go
  12. 1
      vendor/xorm.io/xorm/schemas/column.go
  13. 7
      vendor/xorm.io/xorm/schemas/table.go
  14. 4
      vendor/xorm.io/xorm/session.go
  15. 24
      vendor/xorm.io/xorm/session_convert.go
  16. 3
      vendor/xorm.io/xorm/session_find.go
  17. 9
      vendor/xorm.io/xorm/session_update.go
  18. 4
      vendor/xorm.io/xorm/tags/parser.go
  19. 3
      vendor/xorm.io/xorm/tags/tag.go

@ -122,7 +122,7 @@ require (
mvdan.cc/xurls/v2 v2.2.0 mvdan.cc/xurls/v2 v2.2.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.5 xorm.io/xorm v1.0.6
) )
replace github.com/hashicorp/go-version => github.com/6543/go-version v1.2.4 replace github.com/hashicorp/go-version => github.com/6543/go-version v1.2.4

@ -1612,5 +1612,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.5 h1:LRr5PfOUb4ODPR63YwbowkNDwcolT2LnkwP/TUaMaB0= xorm.io/xorm v1.0.6 h1:7eco1c8QUpGz+3dztpLDj9gU1bTiQdFC/KtmPaLxUJk=
xorm.io/xorm v1.0.5/go.mod h1:uF9EtbhODq5kNWxMbnBEj8hRRZnlcNSz2t2N7HW/+A4= xorm.io/xorm v1.0.6/go.mod h1:uF9EtbhODq5kNWxMbnBEj8hRRZnlcNSz2t2N7HW/+A4=

@ -982,7 +982,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.5 # xorm.io/xorm v1.0.6
## explicit ## explicit
xorm.io/xorm xorm.io/xorm
xorm.io/xorm/caches xorm.io/xorm/caches

14
vendor/xorm.io/xorm/CHANGELOG.md generated vendored

@ -3,6 +3,20 @@
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.6](https://gitea.com/xorm/xorm/pulls?q=&type=all&state=closed&milestone=1308) - 2021-01-05
* BUGFIXES
* Fix bug when modify column on mssql (#1849)
* Fix find and count bug with cols (#1826)
* Fix update bug (#1823)
* Fix json tag with other type (#1822)
* ENHANCEMENTS
* prevent panic when struct with unexport field (#1839)
* Automatically convert datetime to int64 (#1715)
* MISC
* Fix index (#1841)
* Performance improvement for columnsbyName (#1788)
## [1.0.5](https://gitea.com/xorm/xorm/pulls?q=&type=all&state=closed&milestone=1299) - 2020-09-08 ## [1.0.5](https://gitea.com/xorm/xorm/pulls?q=&type=all&state=closed&milestone=1299) - 2020-09-08
* BUGFIXES * BUGFIXES

@ -163,7 +163,7 @@ func (db *Base) DropIndexSQL(tableName string, index *schemas.Index) string {
func (db *Base) ModifyColumnSQL(tableName string, col *schemas.Column) string { func (db *Base) ModifyColumnSQL(tableName string, col *schemas.Column) string {
s, _ := ColumnString(db.dialect, col, false) s, _ := ColumnString(db.dialect, col, false)
return fmt.Sprintf("alter table %s MODIFY COLUMN %s", tableName, s) return fmt.Sprintf("ALTER TABLE %s MODIFY COLUMN %s", tableName, s)
} }
func (b *Base) ForUpdateSQL(query string) string { func (b *Base) ForUpdateSQL(query string) string {

@ -368,6 +368,11 @@ func (db *mssql) DropTableSQL(tableName string) (string, bool) {
"DROP TABLE \"%s\"", tableName, tableName), true "DROP TABLE \"%s\"", tableName, tableName), true
} }
func (db *mssql) ModifyColumnSQL(tableName string, col *schemas.Column) string {
s, _ := ColumnString(db.dialect, col, false)
return fmt.Sprintf("ALTER TABLE %s ALTER COLUMN %s", tableName, s)
}
func (db *mssql) IndexCheckSQL(tableName, idxName string) (string, []interface{}) { func (db *mssql) IndexCheckSQL(tableName, idxName string) (string, []interface{}) {
args := []interface{}{idxName} args := []interface{}{idxName}
sql := "select name from sysindexes where id=object_id('" + tableName + "') and name=?" sql := "select name from sysindexes where id=object_id('" + tableName + "') and name=?"

@ -483,7 +483,7 @@ func (db *sqlite3) GetIndexes(queryer core.Queryer, ctx context.Context, tableNa
continue continue
} }
indexName := strings.Trim(sql[nNStart+6:nNEnd], "` []'\"") indexName := strings.Trim(strings.TrimSpace(sql[nNStart+6:nNEnd]), "`[]'\"")
var isRegular bool var isRegular bool
if strings.HasPrefix(indexName, "IDX_"+tableName) || strings.HasPrefix(indexName, "UQE_"+tableName) { if strings.HasPrefix(indexName, "IDX_"+tableName) || strings.HasPrefix(indexName, "UQE_"+tableName) {
index.Name = indexName[5+len(tableName):] index.Name = indexName[5+len(tableName):]

21
vendor/xorm.io/xorm/engine.go generated vendored

@ -61,6 +61,10 @@ func NewEngine(driverName string, dataSourceName string) (*Engine, error) {
return nil, err return nil, err
} }
return newEngine(driverName, dataSourceName, dialect, db)
}
func newEngine(driverName, dataSourceName string, dialect dialects.Dialect, db *core.DB) (*Engine, error) {
cacherMgr := caches.NewManager() cacherMgr := caches.NewManager()
mapper := names.NewCacheMapper(new(names.SnakeMapper)) mapper := names.NewCacheMapper(new(names.SnakeMapper))
tagParser := tags.NewParser("xorm", dialect, mapper, mapper, cacherMgr) tagParser := tags.NewParser("xorm", dialect, mapper, mapper, cacherMgr)
@ -88,7 +92,7 @@ func NewEngine(driverName string, dataSourceName string) (*Engine, error) {
engine.SetLogger(log.NewLoggerAdapter(logger)) engine.SetLogger(log.NewLoggerAdapter(logger))
runtime.SetFinalizer(engine, func(engine *Engine) { runtime.SetFinalizer(engine, func(engine *Engine) {
engine.Close() _ = engine.Close()
}) })
return engine, nil return engine, nil
@ -101,6 +105,14 @@ func NewEngineWithParams(driverName string, dataSourceName string, params map[st
return engine, err return engine, err
} }
// NewEngineWithDialectAndDB new a db manager according to the parameter.
// If you do not want to use your own dialect or db, please use NewEngine.
// For creating dialect, you can call dialects.OpenDialect. And, for creating db,
// you can call core.Open or core.FromDB.
func NewEngineWithDialectAndDB(driverName, dataSourceName string, dialect dialects.Dialect, db *core.DB) (*Engine, error) {
return newEngine(driverName, dataSourceName, dialect, db)
}
// EnableSessionID if enable session id // EnableSessionID if enable session id
func (engine *Engine) EnableSessionID(enable bool) { func (engine *Engine) EnableSessionID(enable bool) {
engine.logSessionID = enable engine.logSessionID = enable
@ -347,13 +359,16 @@ func (engine *Engine) loadTableInfo(table *schemas.Table) error {
var seq int var seq int
for _, index := range indexes { for _, index := range indexes {
for _, name := range index.Cols { for _, name := range index.Cols {
parts := strings.Split(name, " ") parts := strings.Split(strings.TrimSpace(name), " ")
if len(parts) > 1 { if len(parts) > 1 {
if parts[1] == "DESC" { if parts[1] == "DESC" {
seq = 1 seq = 1
} else if parts[1] == "ASC" {
seq = 0
} }
} }
if col := table.GetColumn(parts[0]); col != nil { var colName = strings.Trim(parts[0], `"`)
if col := table.GetColumn(colName); col != nil {
col.Indexes[index.Name] = index.Type col.Indexes[index.Name] = index.Type
} else { } else {
return fmt.Errorf("Unknown col %s seq %d, in index %v of table %v, columns %v", name, seq, index.Name, table.Name, table.ColumnsSeq()) return fmt.Errorf("Unknown col %s seq %d, in index %v of table %v, columns %v", name, seq, index.Name, table.Name, table.ColumnsSeq())

@ -704,7 +704,7 @@ func (statement *Statement) buildConds2(table *schemas.Table, bean interface{},
col.SQLType.IsBlob() || col.SQLType.Name == schemas.TimeStampz) { col.SQLType.IsBlob() || col.SQLType.Name == schemas.TimeStampz) {
continue continue
} }
if col.SQLType.IsJson() { if col.IsJSON {
continue continue
} }
@ -813,7 +813,7 @@ func (statement *Statement) buildConds2(table *schemas.Table, bean interface{},
continue continue
} }
} else { } else {
if col.SQLType.IsJson() { if col.IsJSON {
if col.SQLType.IsText() { if col.SQLType.IsText() {
bytes, err := json.DefaultJSONHandler.Marshal(fieldValue.Interface()) bytes, err := json.DefaultJSONHandler.Marshal(fieldValue.Interface())
if err != nil { if err != nil {

@ -204,7 +204,7 @@ func (statement *Statement) BuildUpdates(tableValue reflect.Value,
continue continue
} }
} else { } else {
if !col.SQLType.IsJson() { if !col.IsJSON {
table, err := statement.tagParser.ParseWithCache(fieldValue) table, err := statement.tagParser.ParseWithCache(fieldValue)
if err != nil { if err != nil {
val = fieldValue.Interface() val = fieldValue.Interface()

@ -86,7 +86,7 @@ func (statement *Statement) Value2Interface(col *schemas.Column, fieldValue refl
return t.Float64, nil return t.Float64, nil
} }
if !col.SQLType.IsJson() { if !col.IsJSON {
// !<winxxp>! 增加支持driver.Valuer接口的结构,如sql.NullString // !<winxxp>! 增加支持driver.Valuer接口的结构,如sql.NullString
if v, ok := fieldValue.Interface().(driver.Valuer); ok { if v, ok := fieldValue.Interface().(driver.Valuer); ok {
return v.Value() return v.Value()

@ -51,6 +51,7 @@ type Column struct {
func NewColumn(name, fieldName string, sqlType SQLType, len1, len2 int, nullable bool) *Column { func NewColumn(name, fieldName string, sqlType SQLType, len1, len2 int, nullable bool) *Column {
return &Column{ return &Column{
Name: name, Name: name,
IsJSON: sqlType.IsJson(),
TableName: "", TableName: "",
FieldName: fieldName, FieldName: fieldName,
SQLType: sqlType, SQLType: sqlType,

@ -58,12 +58,7 @@ func (table *Table) ColumnsSeq() []string {
} }
func (table *Table) columnsByName(name string) []*Column { func (table *Table) columnsByName(name string) []*Column {
for k, cols := range table.columnsMap { return table.columnsMap[strings.ToLower(name)]
if strings.EqualFold(k, name) {
return cols
}
}
return nil
} }
// GetColumn returns column according column name, if column not found, return nil // GetColumn returns column according column name, if column not found, return nil

4
vendor/xorm.io/xorm/session.go generated vendored

@ -503,7 +503,7 @@ func (session *Session) slice2Bean(scanResults []interface{}, fields []string, b
fieldType := fieldValue.Type() fieldType := fieldValue.Type()
hasAssigned := false hasAssigned := false
if col.SQLType.IsJson() { if col.IsJSON {
var bs []byte var bs []byte
if rawValueType.Kind() == reflect.String { if rawValueType.Kind() == reflect.String {
bs = []byte(vv.String()) bs = []byte(vv.String())
@ -683,7 +683,7 @@ func (session *Session) slice2Bean(scanResults []interface{}, fields []string, b
session.engine.logger.Errorf("sql.Sanner error: %v", err) session.engine.logger.Errorf("sql.Sanner error: %v", err)
hasAssigned = false hasAssigned = false
} }
} else if col.SQLType.IsJson() { } else if col.IsJSON {
if rawValueType.Kind() == reflect.String { if rawValueType.Kind() == reflect.String {
hasAssigned = true hasAssigned = true
x := reflect.New(fieldType) x := reflect.New(fieldType)

@ -168,7 +168,29 @@ func (session *Session) bytes2Value(col *schemas.Column, fieldValue *reflect.Val
} else if strings.EqualFold(sdata, "false") { } else if strings.EqualFold(sdata, "false") {
x = 0 x = 0
} else { } else {
x, err = strconv.ParseInt(sdata, 10, 64) if col.SQLType.Name == schemas.DateTime {
if len(sdata) == 20 {
t, err := time.Parse("2006-01-02T15:04:05Z", sdata)
if err != nil {
return fmt.Errorf("arg %v as int: %s", key, err.Error())
}
x = t.Unix()
} else if len(sdata) == 19 {
var parseFormat = "2006-01-02 15:04:05"
if sdata[10] == 'T' {
parseFormat = "2006-01-02T15:04:05"
}
t, err := time.Parse(parseFormat, sdata)
if err != nil {
return fmt.Errorf("arg %v as int: %s", key, err.Error())
}
x = t.Unix()
} else {
x, err = strconv.ParseInt(sdata, 10, 64)
}
} else {
x, err = strconv.ParseInt(sdata, 10, 64)
}
} }
if err != nil { if err != nil {
return fmt.Errorf("arg %v as int: %s", key, err.Error()) return fmt.Errorf("arg %v as int: %s", key, err.Error())

@ -57,6 +57,9 @@ func (session *Session) FindAndCount(rowsSlicePtr interface{}, condiBean ...inte
if session.statement.SelectStr != "" { if session.statement.SelectStr != "" {
session.statement.SelectStr = "" session.statement.SelectStr = ""
} }
if len(session.statement.ColumnMap) > 0 {
session.statement.ColumnMap = []string{}
}
if session.statement.OrderStr != "" { if session.statement.OrderStr != "" {
session.statement.OrderStr = "" session.statement.OrderStr = ""
} }

@ -273,8 +273,15 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6
k = ct.Elem().Kind() k = ct.Elem().Kind()
} }
if k == reflect.Struct { if k == reflect.Struct {
var refTable = session.statement.RefTable
if refTable == nil {
refTable, err = session.engine.TableInfo(condiBean[0])
if err != nil {
return 0, err
}
}
var err error var err error
autoCond, err = session.statement.BuildConds(session.statement.RefTable, condiBean[0], true, true, false, true, false) autoCond, err = session.statement.BuildConds(refTable, condiBean[0], true, true, false, true, false)
if err != nil { if err != nil {
return 0, err return 0, err
} }

@ -253,7 +253,7 @@ func (parser *Parser) Parse(v reflect.Value) (*schemas.Table, error) {
addIndex(indexName, table, col, indexType) addIndex(indexName, table, col, indexType)
} }
} }
} else { } else if fieldValue.CanSet() {
var sqlType schemas.SQLType var sqlType schemas.SQLType
if fieldValue.CanAddr() { if fieldValue.CanAddr() {
if _, ok := fieldValue.Addr().Interface().(convert.Conversion); ok { if _, ok := fieldValue.Addr().Interface().(convert.Conversion); ok {
@ -272,6 +272,8 @@ func (parser *Parser) Parse(v reflect.Value) (*schemas.Table, error) {
if fieldType.Kind() == reflect.Int64 && (strings.ToUpper(col.FieldName) == "ID" || strings.HasSuffix(strings.ToUpper(col.FieldName), ".ID")) { if fieldType.Kind() == reflect.Int64 && (strings.ToUpper(col.FieldName) == "ID" || strings.HasSuffix(strings.ToUpper(col.FieldName), ".ID")) {
idFieldColName = col.Name idFieldColName = col.Name
} }
} else {
continue
} }
if col.IsAutoIncrement { if col.IsAutoIncrement {
col.Nullable = false col.Nullable = false

3
vendor/xorm.io/xorm/tags/tag.go generated vendored

@ -226,6 +226,9 @@ func CommentTagHandler(ctx *Context) error {
// SQLTypeTagHandler describes SQL Type tag handler // SQLTypeTagHandler describes SQL Type tag handler
func SQLTypeTagHandler(ctx *Context) error { func SQLTypeTagHandler(ctx *Context) error {
ctx.col.SQLType = schemas.SQLType{Name: ctx.tagName} ctx.col.SQLType = schemas.SQLType{Name: ctx.tagName}
if strings.EqualFold(ctx.tagName, "JSON") {
ctx.col.IsJSON = true
}
if len(ctx.params) > 0 { if len(ctx.params) > 0 {
if ctx.tagName == schemas.Enum { if ctx.tagName == schemas.Enum {
ctx.col.EnumOptions = make(map[string]int) ctx.col.EnumOptions = make(map[string]int)

Loading…
Cancel
Save