summaryrefslogtreecommitdiffstats
path: root/vendor/xorm.io/xorm
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-01-05 14:28:51 +0800
committerGitHub <noreply@github.com>2021-01-05 14:28:51 +0800
commit126c9331d6d8789563fae5d5bac2196d63fee0e8 (patch)
tree304d5f1ce134bd75344a4e7e1a376d7a6dc9cfb1 /vendor/xorm.io/xorm
parent8db0372a45082c8827bdee1b449f618b393c026d (diff)
downloadgitea-126c9331d6d8789563fae5d5bac2196d63fee0e8.tar.gz
gitea-126c9331d6d8789563fae5d5bac2196d63fee0e8.zip
upgrade xorm to v1.0.6 (#14246)
Diffstat (limited to 'vendor/xorm.io/xorm')
-rw-r--r--vendor/xorm.io/xorm/CHANGELOG.md14
-rw-r--r--vendor/xorm.io/xorm/dialects/dialect.go2
-rw-r--r--vendor/xorm.io/xorm/dialects/mssql.go5
-rw-r--r--vendor/xorm.io/xorm/dialects/sqlite3.go2
-rw-r--r--vendor/xorm.io/xorm/engine.go21
-rw-r--r--vendor/xorm.io/xorm/internal/statements/statement.go4
-rw-r--r--vendor/xorm.io/xorm/internal/statements/update.go2
-rw-r--r--vendor/xorm.io/xorm/internal/statements/values.go2
-rw-r--r--vendor/xorm.io/xorm/schemas/column.go1
-rw-r--r--vendor/xorm.io/xorm/schemas/table.go7
-rw-r--r--vendor/xorm.io/xorm/session.go4
-rw-r--r--vendor/xorm.io/xorm/session_convert.go24
-rw-r--r--vendor/xorm.io/xorm/session_find.go3
-rw-r--r--vendor/xorm.io/xorm/session_update.go9
-rw-r--r--vendor/xorm.io/xorm/tags/parser.go4
-rw-r--r--vendor/xorm.io/xorm/tags/tag.go3
16 files changed, 87 insertions, 20 deletions
diff --git a/vendor/xorm.io/xorm/CHANGELOG.md b/vendor/xorm.io/xorm/CHANGELOG.md
index 3cead87d00..32403a1a86 100644
--- a/vendor/xorm.io/xorm/CHANGELOG.md
+++ b/vendor/xorm.io/xorm/CHANGELOG.md
@@ -3,6 +3,20 @@
This changelog goes through all the changes that have been made in each release
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
* BUGFIXES
diff --git a/vendor/xorm.io/xorm/dialects/dialect.go b/vendor/xorm.io/xorm/dialects/dialect.go
index dc96f73ae2..18b781a155 100644
--- a/vendor/xorm.io/xorm/dialects/dialect.go
+++ b/vendor/xorm.io/xorm/dialects/dialect.go
@@ -163,7 +163,7 @@ func (db *Base) DropIndexSQL(tableName string, index *schemas.Index) string {
func (db *Base) ModifyColumnSQL(tableName string, col *schemas.Column) string {
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 {
diff --git a/vendor/xorm.io/xorm/dialects/mssql.go b/vendor/xorm.io/xorm/dialects/mssql.go
index 8e76e53855..5340455dd3 100644
--- a/vendor/xorm.io/xorm/dialects/mssql.go
+++ b/vendor/xorm.io/xorm/dialects/mssql.go
@@ -368,6 +368,11 @@ func (db *mssql) DropTableSQL(tableName string) (string, bool) {
"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{}) {
args := []interface{}{idxName}
sql := "select name from sysindexes where id=object_id('" + tableName + "') and name=?"
diff --git a/vendor/xorm.io/xorm/dialects/sqlite3.go b/vendor/xorm.io/xorm/dialects/sqlite3.go
index 73f98beb9d..62a383976f 100644
--- a/vendor/xorm.io/xorm/dialects/sqlite3.go
+++ b/vendor/xorm.io/xorm/dialects/sqlite3.go
@@ -483,7 +483,7 @@ func (db *sqlite3) GetIndexes(queryer core.Queryer, ctx context.Context, tableNa
continue
}
- indexName := strings.Trim(sql[nNStart+6:nNEnd], "` []'\"")
+ indexName := strings.Trim(strings.TrimSpace(sql[nNStart+6:nNEnd]), "`[]'\"")
var isRegular bool
if strings.HasPrefix(indexName, "IDX_"+tableName) || strings.HasPrefix(indexName, "UQE_"+tableName) {
index.Name = indexName[5+len(tableName):]
diff --git a/vendor/xorm.io/xorm/engine.go b/vendor/xorm.io/xorm/engine.go
index 4159a7b24b..873fcdc1b9 100644
--- a/vendor/xorm.io/xorm/engine.go
+++ b/vendor/xorm.io/xorm/engine.go
@@ -61,6 +61,10 @@ func NewEngine(driverName string, dataSourceName string) (*Engine, error) {
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()
mapper := names.NewCacheMapper(new(names.SnakeMapper))
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))
runtime.SetFinalizer(engine, func(engine *Engine) {
- engine.Close()
+ _ = engine.Close()
})
return engine, nil
@@ -101,6 +105,14 @@ func NewEngineWithParams(driverName string, dataSourceName string, params map[st
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
func (engine *Engine) EnableSessionID(enable bool) {
engine.logSessionID = enable
@@ -347,13 +359,16 @@ func (engine *Engine) loadTableInfo(table *schemas.Table) error {
var seq int
for _, index := range indexes {
for _, name := range index.Cols {
- parts := strings.Split(name, " ")
+ parts := strings.Split(strings.TrimSpace(name), " ")
if len(parts) > 1 {
if parts[1] == "DESC" {
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
} 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())
diff --git a/vendor/xorm.io/xorm/internal/statements/statement.go b/vendor/xorm.io/xorm/internal/statements/statement.go
index ed7bdaeb62..a4294bec6d 100644
--- a/vendor/xorm.io/xorm/internal/statements/statement.go
+++ b/vendor/xorm.io/xorm/internal/statements/statement.go
@@ -704,7 +704,7 @@ func (statement *Statement) buildConds2(table *schemas.Table, bean interface{},
col.SQLType.IsBlob() || col.SQLType.Name == schemas.TimeStampz) {
continue
}
- if col.SQLType.IsJson() {
+ if col.IsJSON {
continue
}
@@ -813,7 +813,7 @@ func (statement *Statement) buildConds2(table *schemas.Table, bean interface{},
continue
}
} else {
- if col.SQLType.IsJson() {
+ if col.IsJSON {
if col.SQLType.IsText() {
bytes, err := json.DefaultJSONHandler.Marshal(fieldValue.Interface())
if err != nil {
diff --git a/vendor/xorm.io/xorm/internal/statements/update.go b/vendor/xorm.io/xorm/internal/statements/update.go
index ff5f82b731..251880b230 100644
--- a/vendor/xorm.io/xorm/internal/statements/update.go
+++ b/vendor/xorm.io/xorm/internal/statements/update.go
@@ -204,7 +204,7 @@ func (statement *Statement) BuildUpdates(tableValue reflect.Value,
continue
}
} else {
- if !col.SQLType.IsJson() {
+ if !col.IsJSON {
table, err := statement.tagParser.ParseWithCache(fieldValue)
if err != nil {
val = fieldValue.Interface()
diff --git a/vendor/xorm.io/xorm/internal/statements/values.go b/vendor/xorm.io/xorm/internal/statements/values.go
index 99eaa76691..71327c5568 100644
--- a/vendor/xorm.io/xorm/internal/statements/values.go
+++ b/vendor/xorm.io/xorm/internal/statements/values.go
@@ -86,7 +86,7 @@ func (statement *Statement) Value2Interface(col *schemas.Column, fieldValue refl
return t.Float64, nil
}
- if !col.SQLType.IsJson() {
+ if !col.IsJSON {
// !<winxxp>! 增加支持driver.Valuer接口的结构,如sql.NullString
if v, ok := fieldValue.Interface().(driver.Valuer); ok {
return v.Value()
diff --git a/vendor/xorm.io/xorm/schemas/column.go b/vendor/xorm.io/xorm/schemas/column.go
index db66a3a675..4f32afab07 100644
--- a/vendor/xorm.io/xorm/schemas/column.go
+++ b/vendor/xorm.io/xorm/schemas/column.go
@@ -51,6 +51,7 @@ type Column struct {
func NewColumn(name, fieldName string, sqlType SQLType, len1, len2 int, nullable bool) *Column {
return &Column{
Name: name,
+ IsJSON: sqlType.IsJson(),
TableName: "",
FieldName: fieldName,
SQLType: sqlType,
diff --git a/vendor/xorm.io/xorm/schemas/table.go b/vendor/xorm.io/xorm/schemas/table.go
index 6c57a7e382..7ca9531f74 100644
--- a/vendor/xorm.io/xorm/schemas/table.go
+++ b/vendor/xorm.io/xorm/schemas/table.go
@@ -58,12 +58,7 @@ func (table *Table) ColumnsSeq() []string {
}
func (table *Table) columnsByName(name string) []*Column {
- for k, cols := range table.columnsMap {
- if strings.EqualFold(k, name) {
- return cols
- }
- }
- return nil
+ return table.columnsMap[strings.ToLower(name)]
}
// GetColumn returns column according column name, if column not found, return nil
diff --git a/vendor/xorm.io/xorm/session.go b/vendor/xorm.io/xorm/session.go
index b6ab3eb5bf..17abd453a8 100644
--- a/vendor/xorm.io/xorm/session.go
+++ b/vendor/xorm.io/xorm/session.go
@@ -503,7 +503,7 @@ func (session *Session) slice2Bean(scanResults []interface{}, fields []string, b
fieldType := fieldValue.Type()
hasAssigned := false
- if col.SQLType.IsJson() {
+ if col.IsJSON {
var bs []byte
if rawValueType.Kind() == reflect.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)
hasAssigned = false
}
- } else if col.SQLType.IsJson() {
+ } else if col.IsJSON {
if rawValueType.Kind() == reflect.String {
hasAssigned = true
x := reflect.New(fieldType)
diff --git a/vendor/xorm.io/xorm/session_convert.go b/vendor/xorm.io/xorm/session_convert.go
index a683994731..4a4dd8be00 100644
--- a/vendor/xorm.io/xorm/session_convert.go
+++ b/vendor/xorm.io/xorm/session_convert.go
@@ -168,7 +168,29 @@ func (session *Session) bytes2Value(col *schemas.Column, fieldValue *reflect.Val
} else if strings.EqualFold(sdata, "false") {
x = 0
} 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 {
return fmt.Errorf("arg %v as int: %s", key, err.Error())
diff --git a/vendor/xorm.io/xorm/session_find.go b/vendor/xorm.io/xorm/session_find.go
index 642093f22a..0daea005dd 100644
--- a/vendor/xorm.io/xorm/session_find.go
+++ b/vendor/xorm.io/xorm/session_find.go
@@ -57,6 +57,9 @@ func (session *Session) FindAndCount(rowsSlicePtr interface{}, condiBean ...inte
if session.statement.SelectStr != "" {
session.statement.SelectStr = ""
}
+ if len(session.statement.ColumnMap) > 0 {
+ session.statement.ColumnMap = []string{}
+ }
if session.statement.OrderStr != "" {
session.statement.OrderStr = ""
}
diff --git a/vendor/xorm.io/xorm/session_update.go b/vendor/xorm.io/xorm/session_update.go
index 7df8c75253..0adac25e43 100644
--- a/vendor/xorm.io/xorm/session_update.go
+++ b/vendor/xorm.io/xorm/session_update.go
@@ -273,8 +273,15 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6
k = ct.Elem().Kind()
}
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
- 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 {
return 0, err
}
diff --git a/vendor/xorm.io/xorm/tags/parser.go b/vendor/xorm.io/xorm/tags/parser.go
index add30a1347..a301d12494 100644
--- a/vendor/xorm.io/xorm/tags/parser.go
+++ b/vendor/xorm.io/xorm/tags/parser.go
@@ -253,7 +253,7 @@ func (parser *Parser) Parse(v reflect.Value) (*schemas.Table, error) {
addIndex(indexName, table, col, indexType)
}
}
- } else {
+ } else if fieldValue.CanSet() {
var sqlType schemas.SQLType
if fieldValue.CanAddr() {
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")) {
idFieldColName = col.Name
}
+ } else {
+ continue
}
if col.IsAutoIncrement {
col.Nullable = false
diff --git a/vendor/xorm.io/xorm/tags/tag.go b/vendor/xorm.io/xorm/tags/tag.go
index ee3f1e8240..bb5b583887 100644
--- a/vendor/xorm.io/xorm/tags/tag.go
+++ b/vendor/xorm.io/xorm/tags/tag.go
@@ -226,6 +226,9 @@ func CommentTagHandler(ctx *Context) error {
// SQLTypeTagHandler describes SQL Type tag handler
func SQLTypeTagHandler(ctx *Context) error {
ctx.col.SQLType = schemas.SQLType{Name: ctx.tagName}
+ if strings.EqualFold(ctx.tagName, "JSON") {
+ ctx.col.IsJSON = true
+ }
if len(ctx.params) > 0 {
if ctx.tagName == schemas.Enum {
ctx.col.EnumOptions = make(map[string]int)