fix tidb
Signed-off-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
parent
b4467b717a
commit
4bf7c4d738
|
@ -94,6 +94,9 @@ func (statement *Statement) GenUpsertSQL(doUpdate bool, columns []string, args [
|
||||||
for _, column := range updateColumns[1:] {
|
for _, column := range updateColumns[1:] {
|
||||||
write(", ", column, " = VALUES(", column, ")")
|
write(", ", column, " = VALUES(", column, ")")
|
||||||
}
|
}
|
||||||
|
if len(table.AutoIncrement) > 0 {
|
||||||
|
write(", ", quote(table.AutoIncrement), " = LAST_INSERT_ID(", quote(table.AutoIncrement), ")")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return "", nil, fmt.Errorf("unimplemented") // FIXME: UPSERT
|
return "", nil, fmt.Errorf("unimplemented") // FIXME: UPSERT
|
||||||
|
@ -282,7 +285,7 @@ func (statement *Statement) GenUpsertMapSQL(doUpdate bool, columns []string, arg
|
||||||
write(", ", column, " = VALUES(", column, ")")
|
write(", ", column, " = VALUES(", column, ")")
|
||||||
}
|
}
|
||||||
if len(table.AutoIncrement) > 0 {
|
if len(table.AutoIncrement) > 0 {
|
||||||
write(", ", quote(table.AutoIncrement), " = ", quote(table.AutoIncrement))
|
write(", ", quote(table.AutoIncrement), " = LAST_INSERT_ID(", quote(table.AutoIncrement), ")")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -212,8 +212,6 @@ func (session *Session) upsertStruct(doUpdate bool, bean interface{}) (int64, er
|
||||||
session.incrVersionFieldValue(verValue)
|
session.incrVersionFieldValue(verValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
id, iderr := res.LastInsertId()
|
|
||||||
n, err := res.RowsAffected()
|
n, err := res.RowsAffected()
|
||||||
if err != nil || n == 0 {
|
if err != nil || n == 0 {
|
||||||
return 0, err
|
return 0, err
|
||||||
|
@ -224,14 +222,15 @@ func (session *Session) upsertStruct(doUpdate bool, bean interface{}) (int64, er
|
||||||
n = 1
|
n = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if iderr != nil || id <= 0 {
|
|
||||||
return n, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if table.AutoIncrement == "" {
|
if table.AutoIncrement == "" {
|
||||||
return n, nil
|
return n, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
id, err := res.LastInsertId()
|
||||||
|
if err != nil || id <= 0 {
|
||||||
|
return n, err
|
||||||
|
}
|
||||||
|
|
||||||
aiValue, err := table.AutoIncrColumn().ValueOf(bean)
|
aiValue, err := table.AutoIncrColumn().ValueOf(bean)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
session.engine.logger.Errorf("%v", err)
|
session.engine.logger.Errorf("%v", err)
|
||||||
|
|
Loading…
Reference in New Issue