Fix update bug (#1823)
Fix #1821 Reviewed-on: https://gitea.com/xorm/xorm/pulls/1823 Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
parent
b65276da85
commit
26b248c569
|
@ -399,6 +399,10 @@ func TestSync2_Default(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestModifyColum(t *testing.T) {
|
func TestModifyColum(t *testing.T) {
|
||||||
|
// Since SQLITE don't support modify column SQL, currrently just ignore
|
||||||
|
if testEngine.Dialect().URI().DBType == schemas.SQLITE {
|
||||||
|
return
|
||||||
|
}
|
||||||
type TestModifyColumn struct {
|
type TestModifyColumn struct {
|
||||||
Id int64
|
Id int64
|
||||||
UserId int64 `xorm:"default(1)"`
|
UserId int64 `xorm:"default(1)"`
|
||||||
|
|
|
@ -15,6 +15,7 @@ import (
|
||||||
"xorm.io/xorm/internal/statements"
|
"xorm.io/xorm/internal/statements"
|
||||||
"xorm.io/xorm/internal/utils"
|
"xorm.io/xorm/internal/utils"
|
||||||
"xorm.io/xorm/names"
|
"xorm.io/xorm/names"
|
||||||
|
"xorm.io/xorm/schemas"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestUpdateMap(t *testing.T) {
|
func TestUpdateMap(t *testing.T) {
|
||||||
|
@ -48,6 +49,19 @@ func TestUpdateMap(t *testing.T) {
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
assert.True(t, statements.IsIDConditionWithNoTableErr(err))
|
assert.True(t, statements.IsIDConditionWithNoTableErr(err))
|
||||||
assert.EqualValues(t, 0, cnt)
|
assert.EqualValues(t, 0, cnt)
|
||||||
|
|
||||||
|
cnt, err = testEngine.Table("update_table").Update(map[string]interface{}{
|
||||||
|
"name": "test2",
|
||||||
|
"age": 36,
|
||||||
|
}, &UpdateTable{
|
||||||
|
Id: tb.Id,
|
||||||
|
})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
if testEngine.Dialect().URI().DBType == schemas.SQLITE {
|
||||||
|
assert.EqualValues(t, 1, cnt)
|
||||||
|
} else {
|
||||||
|
assert.EqualValues(t, 0, cnt)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdateLimit(t *testing.T) {
|
func TestUpdateLimit(t *testing.T) {
|
||||||
|
|
|
@ -273,8 +273,15 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6
|
||||||
k = ct.Elem().Kind()
|
k = ct.Elem().Kind()
|
||||||
}
|
}
|
||||||
if k == reflect.Struct {
|
if k == reflect.Struct {
|
||||||
|
var refTable = session.statement.RefTable
|
||||||
|
if refTable == nil {
|
||||||
|
refTable, err = session.engine.TableInfo(condiBean[0])
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
}
|
||||||
var err error
|
var err error
|
||||||
autoCond, err = session.statement.BuildConds(session.statement.RefTable, condiBean[0], true, true, false, true, false)
|
autoCond, err = session.statement.BuildConds(refTable, condiBean[0], true, true, false, true, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue