Try getting the LastInsertID before the rows affected
Signed-off-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
parent
5a188e58d1
commit
b4467b717a
|
@ -212,6 +212,8 @@ 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
|
||||||
|
@ -222,14 +224,12 @@ func (session *Session) upsertStruct(doUpdate bool, bean interface{}) (int64, er
|
||||||
n = 1
|
n = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if table.AutoIncrement == "" {
|
if iderr != nil || id <= 0 {
|
||||||
return n, nil
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var id int64
|
if table.AutoIncrement == "" {
|
||||||
id, err = res.LastInsertId()
|
return n, nil
|
||||||
if err != nil || id <= 0 {
|
|
||||||
return n, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
aiValue, err := table.AutoIncrColumn().ValueOf(bean)
|
aiValue, err := table.AutoIncrColumn().ValueOf(bean)
|
||||||
|
|
Loading…
Reference in New Issue