test for unsigned int32 #1923

Merged
lunny merged 3 commits from lunny/test_unsigned into master 2021-06-12 05:27:57 +00:00
3 changed files with 62 additions and 5 deletions

View File

@ -284,7 +284,7 @@ func (db *mssql) SQLType(c *schemas.Column) string {
case schemas.TimeStampz:
res = "DATETIMEOFFSET"
c.Length = 7
case schemas.MediumInt, schemas.UnsignedInt:
case schemas.MediumInt:
res = schemas.Int
case schemas.Text, schemas.MediumText, schemas.TinyText, schemas.LongText, schemas.Json:
res = db.defaultVarchar + "(MAX)"
@ -296,7 +296,7 @@ func (db *mssql) SQLType(c *schemas.Column) string {
case schemas.TinyInt:
res = schemas.TinyInt
c.Length = 0
case schemas.BigInt, schemas.UnsignedBigInt:
case schemas.BigInt, schemas.UnsignedBigInt, schemas.UnsignedInt:
res = schemas.BigInt
c.Length = 0
case schemas.NVarchar:

View File

@ -838,12 +838,12 @@ func (db *postgres) SQLType(c *schemas.Column) string {
case schemas.Bit:
res = schemas.Boolean
return res
case schemas.MediumInt, schemas.Int, schemas.Integer, schemas.UnsignedInt:
case schemas.MediumInt, schemas.Int, schemas.Integer:
if c.IsAutoIncrement {
return schemas.Serial
}
return schemas.Integer
case schemas.BigInt, schemas.UnsignedBigInt:
case schemas.BigInt, schemas.UnsignedBigInt, schemas.UnsignedInt:
if c.IsAutoIncrement {
return schemas.BigSerial
}

View File

@ -7,6 +7,7 @@ package integrations
import (
"errors"
"fmt"
"math"
"math/big"
"strconv"
"testing"
@ -378,7 +379,7 @@ func TestCustomType2(t *testing.T) {
fmt.Println(users)
}
func TestUnsigned(t *testing.T) {
func TestUnsignedUint64(t *testing.T) {
type MyUnsignedStruct struct {
Id uint64
}
@ -403,6 +404,62 @@ func TestUnsigned(t *testing.T) {
default:
assert.False(t, true, "Unsigned is not implemented")
}
// Only MYSQL database supports unsigned bigint
if testEngine.Dialect().URI().DBType != schemas.MYSQL {
return
}
cnt, err := testEngine.Insert(&MyUnsignedStruct{
Id: math.MaxUint64,
})
assert.NoError(t, err)
assert.EqualValues(t, 1, cnt)
var v MyUnsignedStruct
has, err := testEngine.Get(&v)
assert.NoError(t, err)
assert.True(t, has)
assert.EqualValues(t, uint64(math.MaxUint64), v.Id)
}
func TestUnsignedUint32(t *testing.T) {
type MyUnsignedInt32Struct struct {
Id uint32
}
assert.NoError(t, PrepareEngine())
assertSync(t, new(MyUnsignedInt32Struct))
tables, err := testEngine.DBMetas()
assert.NoError(t, err)
assert.EqualValues(t, 1, len(tables))
assert.EqualValues(t, 1, len(tables[0].Columns()))
switch testEngine.Dialect().URI().DBType {
case schemas.SQLITE:
assert.EqualValues(t, "INTEGER", tables[0].Columns()[0].SQLType.Name)
case schemas.MYSQL:
assert.EqualValues(t, "UNSIGNED INT", tables[0].Columns()[0].SQLType.Name)
case schemas.POSTGRES:
assert.EqualValues(t, "BIGINT", tables[0].Columns()[0].SQLType.Name)
case schemas.MSSQL:
assert.EqualValues(t, "BIGINT", tables[0].Columns()[0].SQLType.Name)
default:
assert.False(t, true, "Unsigned is not implemented")
}
cnt, err := testEngine.Insert(&MyUnsignedInt32Struct{
Id: math.MaxUint32,
})
assert.NoError(t, err)
assert.EqualValues(t, 1, cnt)
var v MyUnsignedInt32Struct
has, err := testEngine.Get(&v)
assert.NoError(t, err)
assert.True(t, has)
assert.EqualValues(t, uint64(math.MaxUint32), v.Id)
}
type MyDecimal big.Int