1
0
Fork 0
forked from forgejo/forgejo

Update xorm and dependencies vendor for feature to dump to other database (#565)

* update xorm and dependencies vendor for feature to dump to other database

* fix golint
This commit is contained in:
Lunny Xiao 2017-01-03 16:20:28 +08:00 committed by GitHub
parent 70900bd167
commit 980dd0bf51
54 changed files with 3135 additions and 2619 deletions

View file

@ -258,7 +258,7 @@ func buildUpdates(engine *Engine, table *core.Table, bean interface{},
if col.IsDeleted && !unscoped {
continue
}
if use, ok := columnMap[col.Name]; ok && !use {
if use, ok := columnMap[strings.ToLower(col.Name)]; ok && !use {
continue
}
@ -273,9 +273,8 @@ func buildUpdates(engine *Engine, table *core.Table, bean interface{},
requiredField := useAllCols
includeNil := useAllCols
lColName := strings.ToLower(col.Name)
if b, ok := mustColumnMap[lColName]; ok {
if b, ok := getFlagForColumn(mustColumnMap, col); ok {
if b {
requiredField = true
} else {
@ -284,7 +283,7 @@ func buildUpdates(engine *Engine, table *core.Table, bean interface{},
}
// !evalphobia! set fieldValue as nil when column is nullable and zero-value
if b, ok := nullableMap[lColName]; ok {
if b, ok := getFlagForColumn(nullableMap, col); ok {
if b && col.Nullable && isZero(fieldValue.Interface()) {
var nilValue *int
fieldValue = reflect.ValueOf(nilValue)
@ -498,7 +497,7 @@ func buildConds(engine *Engine, table *core.Table, bean interface{},
continue
}
if engine.dialect.DBType() == core.MSSQL && col.SQLType.Name == core.Text {
if engine.dialect.DBType() == core.MSSQL && (col.SQLType.Name == core.Text || col.SQLType.IsBlob() || col.SQLType.Name == core.TimeStampz) {
continue
}
if col.SQLType.IsJson() {
@ -523,7 +522,11 @@ func buildConds(engine *Engine, table *core.Table, bean interface{},
}
if col.IsDeleted && !unscoped { // tag "deleted" is enabled
conds = append(conds, builder.IsNull{colName}.Or(builder.Eq{colName: "0001-01-01 00:00:00"}))
if engine.dialect.DBType() == core.MSSQL {
conds = append(conds, builder.IsNull{colName})
} else {
conds = append(conds, builder.IsNull{colName}.Or(builder.Eq{colName: "0001-01-01 00:00:00"}))
}
}
fieldValue := *fieldValuePtr
@ -533,7 +536,8 @@ func buildConds(engine *Engine, table *core.Table, bean interface{},
fieldType := reflect.TypeOf(fieldValue.Interface())
requiredField := useAllCols
if b, ok := mustColumnMap[strings.ToLower(col.Name)]; ok {
if b, ok := getFlagForColumn(mustColumnMap, col); ok {
if b {
requiredField = true
} else {
@ -703,7 +707,14 @@ func (statement *Statement) TableName() string {
}
// Id generate "where id = ? " statment or for composite key "where key1 = ? and key2 = ?"
//
// Deprecated: use ID instead
func (statement *Statement) Id(id interface{}) *Statement {
return statement.ID(id)
}
// ID generate "where id = ? " statment or for composite key "where key1 = ? and key2 = ?"
func (statement *Statement) ID(id interface{}) *Statement {
idValue := reflect.ValueOf(id)
idType := reflect.TypeOf(idValue.Interface())
@ -985,15 +996,16 @@ func (statement *Statement) Unscoped() *Statement {
}
func (statement *Statement) genColumnStr() string {
var buf bytes.Buffer
if statement.RefTable == nil {
return ""
}
columns := statement.RefTable.Columns()
for _, col := range columns {
if statement.OmitStr != "" {
if _, ok := statement.columnMap[strings.ToLower(col.Name)]; ok {
if _, ok := getFlagForColumn(statement.columnMap, col); ok {
continue
}
}
@ -1102,7 +1114,7 @@ func (statement *Statement) genConds(bean interface{}) (string, []interface{}, e
statement.cond = statement.cond.And(autoCond)
}
statement.processIdParam()
statement.processIDParam()
return builder.ToSQL(statement.cond)
}
@ -1144,14 +1156,15 @@ func (statement *Statement) genCountSQL(bean interface{}) (string, []interface{}
condSQL, condArgs, _ := statement.genConds(bean)
var selectSql = statement.selectStr
if len(selectSql) <= 0 {
var selectSQL = statement.selectStr
if len(selectSQL) <= 0 {
if statement.IsDistinct {
selectSql = fmt.Sprintf("count(DISTINCT %s)", statement.ColumnStr)
selectSQL = fmt.Sprintf("count(DISTINCT %s)", statement.ColumnStr)
} else {
selectSQL = "count(*)"
}
selectSql = "count(*)"
}
return statement.genSelectSQL(selectSql, condSQL), append(statement.joinArgs, condArgs...)
return statement.genSelectSQL(selectSQL, condSQL), append(statement.joinArgs, condArgs...)
}
func (statement *Statement) genSumSQL(bean interface{}, columns ...string) (string, []interface{}) {
@ -1178,7 +1191,7 @@ func (statement *Statement) genSelectSQL(columnStr, condSQL string) (a string) {
var top string
var mssqlCondi string
statement.processIdParam()
statement.processIDParam()
var buf bytes.Buffer
if len(condSQL) > 0 {
@ -1275,7 +1288,7 @@ func (statement *Statement) genSelectSQL(columnStr, condSQL string) (a string) {
return
}
func (statement *Statement) processIdParam() {
func (statement *Statement) processIDParam() {
if statement.IdParam == nil {
return
}
@ -1316,7 +1329,12 @@ func (statement *Statement) convertIDSQL(sqlStr string) string {
return ""
}
return fmt.Sprintf("SELECT %s FROM %v", colstrs, sqls[1])
var top string
if statement.LimitN > 0 && statement.Engine.dialect.DBType() == core.MSSQL {
top = fmt.Sprintf("TOP %d ", statement.LimitN)
}
return fmt.Sprintf("SELECT %s%s FROM %v", top, colstrs, sqls[1])
}
return ""
}