diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2017-02-10 23:02:26 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-10 23:02:26 +0800 |
commit | 284c0160c33764b0bffee1e2274eae8fae6a0ca5 (patch) | |
tree | 20d2e7aded1e4b07a527a615c61310e9db3fabd5 /vendor/github.com | |
parent | 2f13d31ff07ca7993b8451446eb756d0521ec897 (diff) | |
download | gitea-284c0160c33764b0bffee1e2274eae8fae6a0ca5.tar.gz gitea-284c0160c33764b0bffee1e2274eae8fae6a0ca5.zip |
update xorm vendor and also fix #740 (#886)
Diffstat (limited to 'vendor/github.com')
-rw-r--r-- | vendor/github.com/go-xorm/core/column.go | 16 | ||||
-rw-r--r-- | vendor/github.com/go-xorm/xorm/engine.go | 8 |
2 files changed, 14 insertions, 10 deletions
diff --git a/vendor/github.com/go-xorm/core/column.go b/vendor/github.com/go-xorm/core/column.go index 36016ef697..c59d01021f 100644 --- a/vendor/github.com/go-xorm/core/column.go +++ b/vendor/github.com/go-xorm/core/column.go @@ -32,7 +32,6 @@ type Column struct { IsDeleted bool IsCascade bool IsVersion bool - fieldPath []string DefaultIsEmpty bool EnumOptions map[string]int SetOptions map[string]int @@ -59,7 +58,6 @@ func NewColumn(name, fieldName string, sqlType SQLType, len1, len2 int, nullable IsDeleted: false, IsCascade: false, IsVersion: false, - fieldPath: nil, DefaultIsEmpty: false, EnumOptions: make(map[string]int), } @@ -121,12 +119,10 @@ func (col *Column) ValueOf(bean interface{}) (*reflect.Value, error) { func (col *Column) ValueOfV(dataStruct *reflect.Value) (*reflect.Value, error) { var fieldValue reflect.Value - if col.fieldPath == nil { - col.fieldPath = strings.Split(col.FieldName, ".") - } + fieldPath := strings.Split(col.FieldName, ".") if dataStruct.Type().Kind() == reflect.Map { - keyValue := reflect.ValueOf(col.fieldPath[len(col.fieldPath)-1]) + keyValue := reflect.ValueOf(fieldPath[len(fieldPath)-1]) fieldValue = dataStruct.MapIndex(keyValue) return &fieldValue, nil } else if dataStruct.Type().Kind() == reflect.Interface { @@ -134,19 +130,19 @@ func (col *Column) ValueOfV(dataStruct *reflect.Value) (*reflect.Value, error) { dataStruct = &structValue } - level := len(col.fieldPath) - fieldValue = dataStruct.FieldByName(col.fieldPath[0]) + level := len(fieldPath) + fieldValue = dataStruct.FieldByName(fieldPath[0]) for i := 0; i < level-1; i++ { if !fieldValue.IsValid() { break } if fieldValue.Kind() == reflect.Struct { - fieldValue = fieldValue.FieldByName(col.fieldPath[i+1]) + fieldValue = fieldValue.FieldByName(fieldPath[i+1]) } else if fieldValue.Kind() == reflect.Ptr { if fieldValue.IsNil() { fieldValue.Set(reflect.New(fieldValue.Type().Elem())) } - fieldValue = fieldValue.Elem().FieldByName(col.fieldPath[i+1]) + fieldValue = fieldValue.Elem().FieldByName(fieldPath[i+1]) } else { return nil, fmt.Errorf("field %v is not valid", col.FieldName) } diff --git a/vendor/github.com/go-xorm/xorm/engine.go b/vendor/github.com/go-xorm/xorm/engine.go index 7bd0df6e89..be90ddbe4e 100644 --- a/vendor/github.com/go-xorm/xorm/engine.go +++ b/vendor/github.com/go-xorm/xorm/engine.go @@ -521,6 +521,14 @@ func (engine *Engine) dumpTables(tables []*core.Table, w io.Writer, tp ...core.D return err } } + + // FIXME: Hack for postgres + if string(dialect.DBType()) == core.POSTGRES && table.AutoIncrColumn() != nil { + _, err = io.WriteString(w, "SELECT setval('table_id_seq', COALESCE((SELECT MAX("+table.AutoIncrColumn().Name+") FROM "+dialect.Quote(table.Name)+"), 1), false);\n") + if err != nil { + return err + } + } } return nil } |