diff --git a/dialects/oci8/oci8.go b/dialects/oci8/oci8.go index 93df4ca9..4e37f999 100644 --- a/dialects/oci8/oci8.go +++ b/dialects/oci8/oci8.go @@ -139,14 +139,29 @@ func (s *oci8) DataTypeOf(field *gorm.StructField) string { if sqlType == "" { switch dataValue.Kind() { - case reflect.Bool, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Uint, reflect.Uint8, + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uintptr, reflect.Int64, reflect.Uint32, reflect.Uint64, reflect.Float32, reflect.Float64: if s.fieldCanAutoIncrement(field) { sqlType = "NUMBER GENERATED BY DEFAULT AS IDENTITY" } else { - sqlType = "NUMBER" + switch dataValue.Kind() { + case reflect.Int8, + reflect.Uint8, + reflect.Uintptr: + sqlType = "SHORTINTEGER" + case reflect.Int, reflect.Int16, reflect.Int32, + reflect.Uint, reflect.Uint16, reflect.Uint32: + sqlType = "INTEGER" + case reflect.Int64, + reflect.Uint64: + sqlType = "INTEGER" + default: + sqlType = "NUMBER" + } } + case reflect.Bool: + sqlType = "INTEGER" case reflect.String: if _, ok := field.TagSettingsGet("SIZE"); !ok { size = 0 // if SIZE haven't been set, use `text` as the default type, as there are no performance different @@ -164,24 +179,15 @@ func (s *oci8) DataTypeOf(field *gorm.StructField) string { if _, ok := dataValue.Interface().(time.Time); ok { sqlType = "TIMESTAMP WITH TIME ZONE" } - case reflect.Map: - if dataValue.Type().Name() == "Hstore" { - sqlType = "hstore" - } default: if gorm.IsByteArrayOrSlice(dataValue) { - // switch { - // case size > 0 && size < 4000: - // sqlType = fmt.Sprintf("VARCHAR2(%d)", size) - // case size == 0: - // sqlType = "VARCHAR2 (4000)" // no size specified, so default to something that can be indexed - // default: sqlType = "BLOB" - // } } } } - + if strings.EqualFold(sqlType, "text") { + sqlType = "CLOB" + } if sqlType == "" { panic(fmt.Sprintf("invalid sql type %s (%s) for oracle", dataValue.Type().Name(), dataValue.Kind().String())) }