test for unsigned int32 (#1923)
To confirm #722 has been resolved. Reviewed-on: https://gitea.com/xorm/xorm/pulls/1923 Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
parent
9c0901bd35
commit
0907b7a7fd
|
@ -284,7 +284,7 @@ func (db *mssql) SQLType(c *schemas.Column) string {
|
||||||
case schemas.TimeStampz:
|
case schemas.TimeStampz:
|
||||||
res = "DATETIMEOFFSET"
|
res = "DATETIMEOFFSET"
|
||||||
c.Length = 7
|
c.Length = 7
|
||||||
case schemas.MediumInt, schemas.UnsignedInt:
|
case schemas.MediumInt:
|
||||||
res = schemas.Int
|
res = schemas.Int
|
||||||
case schemas.Text, schemas.MediumText, schemas.TinyText, schemas.LongText, schemas.Json:
|
case schemas.Text, schemas.MediumText, schemas.TinyText, schemas.LongText, schemas.Json:
|
||||||
res = db.defaultVarchar + "(MAX)"
|
res = db.defaultVarchar + "(MAX)"
|
||||||
|
@ -296,7 +296,7 @@ func (db *mssql) SQLType(c *schemas.Column) string {
|
||||||
case schemas.TinyInt:
|
case schemas.TinyInt:
|
||||||
res = schemas.TinyInt
|
res = schemas.TinyInt
|
||||||
c.Length = 0
|
c.Length = 0
|
||||||
case schemas.BigInt, schemas.UnsignedBigInt:
|
case schemas.BigInt, schemas.UnsignedBigInt, schemas.UnsignedInt:
|
||||||
res = schemas.BigInt
|
res = schemas.BigInt
|
||||||
c.Length = 0
|
c.Length = 0
|
||||||
case schemas.NVarchar:
|
case schemas.NVarchar:
|
||||||
|
|
|
@ -838,12 +838,12 @@ func (db *postgres) SQLType(c *schemas.Column) string {
|
||||||
case schemas.Bit:
|
case schemas.Bit:
|
||||||
res = schemas.Boolean
|
res = schemas.Boolean
|
||||||
return res
|
return res
|
||||||
case schemas.MediumInt, schemas.Int, schemas.Integer, schemas.UnsignedInt:
|
case schemas.MediumInt, schemas.Int, schemas.Integer:
|
||||||
if c.IsAutoIncrement {
|
if c.IsAutoIncrement {
|
||||||
return schemas.Serial
|
return schemas.Serial
|
||||||
}
|
}
|
||||||
return schemas.Integer
|
return schemas.Integer
|
||||||
case schemas.BigInt, schemas.UnsignedBigInt:
|
case schemas.BigInt, schemas.UnsignedBigInt, schemas.UnsignedInt:
|
||||||
if c.IsAutoIncrement {
|
if c.IsAutoIncrement {
|
||||||
return schemas.BigSerial
|
return schemas.BigSerial
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ package integrations
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
"math/big"
|
"math/big"
|
||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -378,7 +379,7 @@ func TestCustomType2(t *testing.T) {
|
||||||
fmt.Println(users)
|
fmt.Println(users)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUnsigned(t *testing.T) {
|
func TestUnsignedUint64(t *testing.T) {
|
||||||
type MyUnsignedStruct struct {
|
type MyUnsignedStruct struct {
|
||||||
Id uint64
|
Id uint64
|
||||||
}
|
}
|
||||||
|
@ -403,6 +404,62 @@ func TestUnsigned(t *testing.T) {
|
||||||
default:
|
default:
|
||||||
assert.False(t, true, "Unsigned is not implemented")
|
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
|
type MyDecimal big.Int
|
||||||
|
|
Loading…
Reference in New Issue