mirror of
https://gitcode.com/gitea/gitea.git
synced 2025-06-22 12:51:10 +08:00
fix migrate failed and org dashboard failed on MSSQL database (#1448)
This commit is contained in:
38
vendor/github.com/go-xorm/xorm/session_insert.go
generated
vendored
38
vendor/github.com/go-xorm/xorm/session_insert.go
generated
vendored
@ -210,13 +210,29 @@ func (session *Session) innerInsertMulti(rowsSlicePtr interface{}) (int64, error
|
||||
}
|
||||
cleanupProcessorsClosures(&session.beforeClosures)
|
||||
|
||||
statement := fmt.Sprintf("INSERT INTO %s (%v%v%v) VALUES (%v)",
|
||||
session.Engine.Quote(session.Statement.TableName()),
|
||||
session.Engine.QuoteStr(),
|
||||
strings.Join(colNames, session.Engine.QuoteStr()+", "+session.Engine.QuoteStr()),
|
||||
session.Engine.QuoteStr(),
|
||||
strings.Join(colMultiPlaces, "),("))
|
||||
|
||||
var sql = "INSERT INTO %s (%v%v%v) VALUES (%v)"
|
||||
var statement string
|
||||
if session.Engine.dialect.DBType() == core.ORACLE {
|
||||
sql = "INSERT ALL INTO %s (%v%v%v) VALUES (%v) SELECT 1 FROM DUAL"
|
||||
temp := fmt.Sprintf(") INTO %s (%v%v%v) VALUES (",
|
||||
session.Engine.Quote(session.Statement.TableName()),
|
||||
session.Engine.QuoteStr(),
|
||||
strings.Join(colNames, session.Engine.QuoteStr() + ", " + session.Engine.QuoteStr()),
|
||||
session.Engine.QuoteStr())
|
||||
statement = fmt.Sprintf(sql,
|
||||
session.Engine.Quote(session.Statement.TableName()),
|
||||
session.Engine.QuoteStr(),
|
||||
strings.Join(colNames, session.Engine.QuoteStr() + ", " + session.Engine.QuoteStr()),
|
||||
session.Engine.QuoteStr(),
|
||||
strings.Join(colMultiPlaces, temp))
|
||||
} else {
|
||||
statement = fmt.Sprintf(sql,
|
||||
session.Engine.Quote(session.Statement.TableName()),
|
||||
session.Engine.QuoteStr(),
|
||||
strings.Join(colNames, session.Engine.QuoteStr() + ", " + session.Engine.QuoteStr()),
|
||||
session.Engine.QuoteStr(),
|
||||
strings.Join(colMultiPlaces, "),("))
|
||||
}
|
||||
res, err := session.exec(statement, args...)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@ -309,8 +325,8 @@ func (session *Session) innerInsert(bean interface{}) (int64, error) {
|
||||
// remove the expr columns
|
||||
for i, colName := range colNames {
|
||||
if colName == v.colName {
|
||||
colNames = append(colNames[:i], colNames[i+1:]...)
|
||||
args = append(args[:i], args[i+1:]...)
|
||||
colNames = append(colNames[:i], colNames[i + 1:]...)
|
||||
args = append(args[:i], args[i + 1:]...)
|
||||
}
|
||||
}
|
||||
|
||||
@ -319,11 +335,11 @@ func (session *Session) innerInsert(bean interface{}) (int64, error) {
|
||||
exprColVals = append(exprColVals, v.expr)
|
||||
}
|
||||
|
||||
colPlaces := strings.Repeat("?, ", len(colNames)-len(exprColumns))
|
||||
colPlaces := strings.Repeat("?, ", len(colNames) - len(exprColumns))
|
||||
if len(exprColVals) > 0 {
|
||||
colPlaces = colPlaces + strings.Join(exprColVals, ", ")
|
||||
} else {
|
||||
colPlaces = colPlaces[0 : len(colPlaces)-2]
|
||||
colPlaces = colPlaces[0 : len(colPlaces) - 2]
|
||||
}
|
||||
|
||||
sqlStr := fmt.Sprintf("INSERT INTO %s (%v%v%v) VALUES (%v)",
|
||||
|
Reference in New Issue
Block a user