fix the error in mysql: unknown colType UNSIGNED FLOAT #2143
@ -328,7 +328,7 @@ func (db *mssql) SQLType(c *schemas.Column) string {
|
||||
res = schemas.Int
|
||||
case schemas.Text, schemas.MediumText, schemas.TinyText, schemas.LongText, schemas.Json:
|
||||
res = db.defaultVarchar + "(MAX)"
|
||||
case schemas.Double:
|
||||
case schemas.Double, schemas.UnsignedFloat:
|
||||
res = schemas.Real
|
||||
case schemas.Uuid:
|
||||
res = schemas.Varchar
|
||||
|
@ -319,6 +319,9 @@ func (db *mysql) SQLType(c *schemas.Column) string {
|
||||
case schemas.UnsignedTinyInt:
|
||||
res = schemas.TinyInt
|
||||
isUnsigned = true
|
||||
case schemas.UnsignedFloat:
|
||||
res = schemas.Float
|
||||
isUnsigned = true
|
||||
default:
|
||||
res = t
|
||||
}
|
||||
@ -510,11 +513,10 @@ func (db *mysql) GetColumns(queryer core.Queryer, ctx context.Context, tableName
|
||||
}
|
||||
col.Length = len1
|
||||
col.Length2 = len2
|
||||
if _, ok := schemas.SqlTypes[colType]; ok {
|
||||
col.SQLType = schemas.SQLType{Name: colType, DefaultLength: len1, DefaultLength2: len2}
|
||||
} else {
|
||||
if _, ok := schemas.SqlTypes[colType]; !ok {
|
||||
return nil, nil, fmt.Errorf("unknown colType %v", colType)
|
||||
}
|
||||
col.SQLType = schemas.SQLType{Name: colType, DefaultLength: len1, DefaultLength2: len2}
|
||||
|
||||
if colKey == "PRI" {
|
||||
col.IsPrimaryKey = true
|
||||
|
@ -928,7 +928,7 @@ func (db *postgres) SQLType(c *schemas.Column) string {
|
||||
return schemas.Uuid
|
||||
case schemas.Blob, schemas.TinyBlob, schemas.MediumBlob, schemas.LongBlob:
|
||||
return schemas.Bytea
|
||||
case schemas.Double:
|
||||
case schemas.Double, schemas.UnsignedFloat:
|
||||
return "DOUBLE PRECISION"
|
||||
default:
|
||||
if c.IsAutoIncrement {
|
||||
|
@ -139,9 +139,10 @@ var (
|
||||
Money = "MONEY"
|
||||
SmallMoney = "SMALLMONEY"
|
||||
|
||||
Real = "REAL"
|
||||
Float = "FLOAT"
|
||||
Double = "DOUBLE"
|
||||
Real = "REAL"
|
||||
Float = "FLOAT"
|
||||
UnsignedFloat = "UNSIGNED FLOAT"
|
||||
Double = "DOUBLE"
|
||||
|
||||
Binary = "BINARY"
|
||||
VarBinary = "VARBINARY"
|
||||
@ -208,13 +209,14 @@ var (
|
||||
SmallDateTime: TIME_TYPE,
|
||||
Year: TIME_TYPE,
|
||||
|
||||
Decimal: NUMERIC_TYPE,
|
||||
Numeric: NUMERIC_TYPE,
|
||||
Real: NUMERIC_TYPE,
|
||||
Float: NUMERIC_TYPE,
|
||||
Double: NUMERIC_TYPE,
|
||||
Money: NUMERIC_TYPE,
|
||||
SmallMoney: NUMERIC_TYPE,
|
||||
Decimal: NUMERIC_TYPE,
|
||||
Numeric: NUMERIC_TYPE,
|
||||
Real: NUMERIC_TYPE,
|
||||
Float: NUMERIC_TYPE,
|
||||
UnsignedFloat: NUMERIC_TYPE,
|
||||
Double: NUMERIC_TYPE,
|
||||
Money: NUMERIC_TYPE,
|
||||
SmallMoney: NUMERIC_TYPE,
|
||||
|
||||
Binary: BLOB_TYPE,
|
||||
VarBinary: BLOB_TYPE,
|
||||
|
@ -325,6 +325,48 @@ func TestUint64Id(t *testing.T) {
|
||||
assert.EqualValues(t, 1, cnt)
|
||||
}
|
||||
|
||||
func TestUnsignedfloat(t *testing.T) {
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type UnsignedFloat struct {
|
||||
Id int64
|
||||
UnsignedFloat float64 `xorm:"UNSIGNED FLOAT"`
|
||||
}
|
||||
|
||||
err := testEngine.DropTables(&UnsignedFloat{})
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = testEngine.CreateTables(&UnsignedFloat{})
|
||||
assert.NoError(t, err)
|
||||
|
||||
tables, err := testEngine.DBMetas()
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.EqualValues(t, 1, len(tables))
|
||||
cols := tables[0].Columns()
|
||||
assert.EqualValues(t, 2, len(cols))
|
||||
if testEngine.Dialect().URI().DBType == schemas.MYSQL {
|
||||
assert.EqualValues(t, "UNSIGNED FLOAT", cols[1].SQLType.Name)
|
||||
}
|
||||
|
||||
idbean := &UnsignedFloat{UnsignedFloat: 12345678.90123456}
|
||||
cnt, err := testEngine.Insert(idbean)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 1, cnt)
|
||||
|
||||
bean := new(UnsignedFloat)
|
||||
has, err := testEngine.Get(bean)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, has)
|
||||
assert.EqualValues(t, bean.Id, idbean.Id)
|
||||
|
||||
beans := make([]UnsignedFloat, 0)
|
||||
err = testEngine.Find(&beans)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 1, len(beans))
|
||||
assert.EqualValues(t, *bean, beans[0])
|
||||
}
|
||||
|
||||
func TestStringPK(t *testing.T) {
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user