This commit is contained in:
Lunny Xiao 2014-05-09 21:53:00 +08:00
parent 3ce5a01d31
commit 78ddfebcfb
2 changed files with 16 additions and 3 deletions

View File

@ -748,7 +748,17 @@ func (engine *Engine) mapType(v reflect.Value) *core.Table {
}
}
} else {
sqlType := core.Type2SQLType(fieldType)
var sqlType core.SQLType
if fieldValue.CanAddr() {
if _, ok := fieldValue.Addr().Interface().(core.Conversion); ok {
sqlType = core.SQLType{core.Text, 0, 0}
}
}
if _, ok := fieldValue.Interface().(core.Conversion); ok {
sqlType = core.SQLType{core.Text, 0, 0}
} else {
sqlType = core.Type2SQLType(fieldType)
}
col = core.NewColumn(engine.ColumnMapper.Obj2Table(t.Field(i).Name),
t.Field(i).Name, sqlType, sqlType.DefaultLength,
sqlType.DefaultLength2, true)

View File

@ -1469,9 +1469,12 @@ func (session *Session) row2Bean(rows *core.Rows, fields []string, fieldsCount i
}
}
if structConvert, ok := fieldValue.Interface().(core.Conversion); ok {
if _, ok := fieldValue.Interface().(core.Conversion); ok {
if data, err := value2Bytes(&rawValue); err == nil {
structConvert.FromDB(data)
if fieldValue.Kind() == reflect.Ptr && fieldValue.IsNil() {
fieldValue.Set(reflect.New(fieldValue.Type().Elem()))
}
fieldValue.Interface().(core.Conversion).FromDB(data)
} else {
session.Engine.LogError(err)
}