mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 13:50:54 +00:00
orm: fix miss pk when pk is negative
This commit is contained in:
parent
c8bbfb75f0
commit
a3d4218d9d
@ -181,7 +181,7 @@ func (d *dbBase) collectFieldValue(mi *modelInfo, fi *fieldInfo, ind reflect.Val
|
|||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
switch {
|
switch {
|
||||||
case fi.fieldType&IsPostiveIntegerField > 0:
|
case fi.fieldType&IsPositiveIntegerField > 0:
|
||||||
if field.Kind() == reflect.Ptr {
|
if field.Kind() == reflect.Ptr {
|
||||||
if field.IsNil() {
|
if field.IsNil() {
|
||||||
value = nil
|
value = nil
|
||||||
@ -516,7 +516,7 @@ func (d *dbBase) Delete(q dbQuerier, mi *modelInfo, ind reflect.Value, tz *time.
|
|||||||
}
|
}
|
||||||
if num > 0 {
|
if num > 0 {
|
||||||
if mi.fields.pk.auto {
|
if mi.fields.pk.auto {
|
||||||
if mi.fields.pk.fieldType&IsPostiveIntegerField > 0 {
|
if mi.fields.pk.fieldType&IsPositiveIntegerField > 0 {
|
||||||
ind.FieldByIndex(mi.fields.pk.fieldIndex).SetUint(0)
|
ind.FieldByIndex(mi.fields.pk.fieldIndex).SetUint(0)
|
||||||
} else {
|
} else {
|
||||||
ind.FieldByIndex(mi.fields.pk.fieldIndex).SetInt(0)
|
ind.FieldByIndex(mi.fields.pk.fieldIndex).SetInt(0)
|
||||||
@ -1140,7 +1140,7 @@ setValue:
|
|||||||
tErr = err
|
tErr = err
|
||||||
goto end
|
goto end
|
||||||
}
|
}
|
||||||
if fieldType&IsPostiveIntegerField > 0 {
|
if fieldType&IsPositiveIntegerField > 0 {
|
||||||
v, _ := str.Uint64()
|
v, _ := str.Uint64()
|
||||||
value = v
|
value = v
|
||||||
} else {
|
} else {
|
||||||
@ -1292,7 +1292,7 @@ setValue:
|
|||||||
field.Set(reflect.ValueOf(&v))
|
field.Set(reflect.ValueOf(&v))
|
||||||
}
|
}
|
||||||
case fieldType&IsIntegerField > 0:
|
case fieldType&IsIntegerField > 0:
|
||||||
if fieldType&IsPostiveIntegerField > 0 {
|
if fieldType&IsPositiveIntegerField > 0 {
|
||||||
if isNative {
|
if isNative {
|
||||||
if value == nil {
|
if value == nil {
|
||||||
value = uint64(0)
|
value = uint64(0)
|
||||||
|
@ -33,13 +33,13 @@ func getExistPk(mi *modelInfo, ind reflect.Value) (column string, value interfac
|
|||||||
fi := mi.fields.pk
|
fi := mi.fields.pk
|
||||||
|
|
||||||
v := ind.FieldByIndex(fi.fieldIndex)
|
v := ind.FieldByIndex(fi.fieldIndex)
|
||||||
if fi.fieldType&IsPostiveIntegerField > 0 {
|
if fi.fieldType&IsPositiveIntegerField > 0 {
|
||||||
vu := v.Uint()
|
vu := v.Uint()
|
||||||
exist = vu > 0
|
exist = vu > 0
|
||||||
value = vu
|
value = vu
|
||||||
} else if fi.fieldType&IsIntegerField > 0 {
|
} else if fi.fieldType&IsIntegerField > 0 {
|
||||||
vu := v.Int()
|
vu := v.Int()
|
||||||
exist = vu > 0
|
exist = true
|
||||||
value = vu
|
value = vu
|
||||||
} else {
|
} else {
|
||||||
vu := v.String()
|
vu := v.String()
|
||||||
|
@ -46,10 +46,10 @@ const (
|
|||||||
|
|
||||||
// Define some logic enum
|
// Define some logic enum
|
||||||
const (
|
const (
|
||||||
IsIntegerField = ^-TypePositiveBigIntegerField >> 4 << 5
|
IsIntegerField = ^-TypePositiveBigIntegerField >> 4 << 5
|
||||||
IsPostiveIntegerField = ^-TypePositiveBigIntegerField >> 8 << 9
|
IsPositiveIntegerField = ^-TypePositiveBigIntegerField >> 8 << 9
|
||||||
IsRelField = ^-RelReverseMany >> 14 << 15
|
IsRelField = ^-RelReverseMany >> 14 << 15
|
||||||
IsFieldType = ^-RelReverseMany<<1 + 1
|
IsFieldType = ^-RelReverseMany<<1 + 1
|
||||||
)
|
)
|
||||||
|
|
||||||
// BooleanField A true/false field.
|
// BooleanField A true/false field.
|
||||||
|
@ -159,7 +159,7 @@ func (o *orm) Insert(md interface{}) (int64, error) {
|
|||||||
// set auto pk field
|
// set auto pk field
|
||||||
func (o *orm) setPk(mi *modelInfo, ind reflect.Value, id int64) {
|
func (o *orm) setPk(mi *modelInfo, ind reflect.Value, id int64) {
|
||||||
if mi.fields.pk.auto {
|
if mi.fields.pk.auto {
|
||||||
if mi.fields.pk.fieldType&IsPostiveIntegerField > 0 {
|
if mi.fields.pk.fieldType&IsPositiveIntegerField > 0 {
|
||||||
ind.FieldByIndex(mi.fields.pk.fieldIndex).SetUint(uint64(id))
|
ind.FieldByIndex(mi.fields.pk.fieldIndex).SetUint(uint64(id))
|
||||||
} else {
|
} else {
|
||||||
ind.FieldByIndex(mi.fields.pk.fieldIndex).SetInt(id)
|
ind.FieldByIndex(mi.fields.pk.fieldIndex).SetInt(id)
|
||||||
|
@ -50,7 +50,7 @@ func (o *insertSet) Insert(md interface{}) (int64, error) {
|
|||||||
}
|
}
|
||||||
if id > 0 {
|
if id > 0 {
|
||||||
if o.mi.fields.pk.auto {
|
if o.mi.fields.pk.auto {
|
||||||
if o.mi.fields.pk.fieldType&IsPostiveIntegerField > 0 {
|
if o.mi.fields.pk.fieldType&IsPositiveIntegerField > 0 {
|
||||||
ind.FieldByIndex(o.mi.fields.pk.fieldIndex).SetUint(uint64(id))
|
ind.FieldByIndex(o.mi.fields.pk.fieldIndex).SetUint(uint64(id))
|
||||||
} else {
|
} else {
|
||||||
ind.FieldByIndex(o.mi.fields.pk.fieldIndex).SetInt(id)
|
ind.FieldByIndex(o.mi.fields.pk.fieldIndex).SetInt(id)
|
||||||
|
Loading…
Reference in New Issue
Block a user