bug fixed for #249

This commit is contained in:
Lunny Xiao 2015-11-26 15:52:25 +08:00
parent 0cae9529c1
commit b36f8ed87e
4 changed files with 28 additions and 47 deletions

View File

@ -1 +1 @@
xorm v0.4.4.1124 xorm v0.4.4.1126

View File

@ -55,6 +55,27 @@ func isZero(k interface{}) bool {
return false return false
} }
func int64ToInt(id int64, k reflect.Kind) interface{} {
var v interface{} = id
switch k {
case reflect.Int16:
v = int16(id)
case reflect.Int32:
v = int32(id)
case reflect.Int:
v = int(id)
case reflect.Uint16:
v = uint16(id)
case reflect.Uint32:
v = uint32(id)
case reflect.Uint64:
v = uint64(id)
case reflect.Uint:
v = uint(id)
}
return v
}
func isPKZero(pk core.PK) bool { func isPKZero(pk core.PK) bool {
for _, k := range pk { for _, k := range pk {
if isZero(k) { if isZero(k) {

View File

@ -2171,7 +2171,7 @@ func (session *Session) innerInsertMulti(rowsSlicePtr interface{}) (int64, error
return 0, err return 0, err
} }
fieldValue := *ptrFieldValue fieldValue := *ptrFieldValue
if col.IsAutoIncrement && fieldValue.Int() == 0 { if col.IsAutoIncrement && isZero(fieldValue.Interface()) {
continue continue
} }
if col.MapType == core.ONLYFROMDB { if col.MapType == core.ONLYFROMDB {
@ -2219,7 +2219,7 @@ func (session *Session) innerInsertMulti(rowsSlicePtr interface{}) (int64, error
} }
fieldValue := *ptrFieldValue fieldValue := *ptrFieldValue
if col.IsAutoIncrement && fieldValue.Int() == 0 { if col.IsAutoIncrement && isZero(fieldValue.Interface()) {
continue continue
} }
if col.MapType == core.ONLYFROMDB { if col.MapType == core.ONLYFROMDB {
@ -3219,19 +3219,7 @@ func (session *Session) innerInsert(bean interface{}) (int64, error) {
return 1, nil return 1, nil
} }
var v interface{} = id v := int64ToInt(id, aiValue.Type().Kind())
switch aiValue.Type().Kind() {
case reflect.Int32:
v = int32(id)
case reflect.Int:
v = int(id)
case reflect.Uint32:
v = uint32(id)
case reflect.Uint64:
v = uint64(id)
case reflect.Uint:
v = uint(id)
}
aiValue.Set(reflect.ValueOf(v)) aiValue.Set(reflect.ValueOf(v))
return 1, nil return 1, nil
@ -3278,19 +3266,7 @@ func (session *Session) innerInsert(bean interface{}) (int64, error) {
return 1, nil return 1, nil
} }
var v interface{} = id v := int64ToInt(id, aiValue.Type().Kind())
switch aiValue.Type().Kind() {
case reflect.Int32:
v = int32(id)
case reflect.Int:
v = int(id)
case reflect.Uint32:
v = uint32(id)
case reflect.Uint64:
v = uint64(id)
case reflect.Uint:
v = uint(id)
}
aiValue.Set(reflect.ValueOf(v)) aiValue.Set(reflect.ValueOf(v))
return 1, nil return 1, nil
@ -3334,23 +3310,7 @@ func (session *Session) innerInsert(bean interface{}) (int64, error) {
return res.RowsAffected() return res.RowsAffected()
} }
var v interface{} = id v := int64ToInt(id, aiValue.Type().Kind())
switch aiValue.Type().Kind() {
case reflect.Int16:
v = int16(id)
case reflect.Int32:
v = int32(id)
case reflect.Int:
v = int(id)
case reflect.Uint16:
v = uint16(id)
case reflect.Uint32:
v = uint32(id)
case reflect.Uint64:
v = uint64(id)
case reflect.Uint:
v = uint(id)
}
aiValue.Set(reflect.ValueOf(v)) aiValue.Set(reflect.ValueOf(v))
return res.RowsAffected() return res.RowsAffected()

View File

@ -17,7 +17,7 @@ import (
) )
const ( const (
Version string = "0.4.4.1124" Version string = "0.4.4.1126"
) )
func regDrvsNDialects() bool { func regDrvsNDialects() bool {