Properly handle MAX
Signed-off-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
parent
c825309e5b
commit
749818bddd
|
@ -242,7 +242,7 @@ func (db *mssql) SetParams(params map[string]string) {
|
||||||
var t = strings.ToUpper(defaultChar)
|
var t = strings.ToUpper(defaultChar)
|
||||||
switch t {
|
switch t {
|
||||||
case "NCHAR", "CHAR":
|
case "NCHAR", "CHAR":
|
||||||
db.defaultChar = defaultChar
|
db.defaultChar = t
|
||||||
default:
|
default:
|
||||||
db.defaultChar = "CHAR"
|
db.defaultChar = "CHAR"
|
||||||
}
|
}
|
||||||
|
@ -297,10 +297,26 @@ func (db *mssql) SQLType(c *schemas.Column) string {
|
||||||
case schemas.BigInt:
|
case schemas.BigInt:
|
||||||
res = schemas.BigInt
|
res = schemas.BigInt
|
||||||
c.Length = 0
|
c.Length = 0
|
||||||
|
case schemas.NVarchar:
|
||||||
|
res = t
|
||||||
|
if c.Length == -1 {
|
||||||
|
res += "(MAX)"
|
||||||
|
}
|
||||||
case schemas.Varchar:
|
case schemas.Varchar:
|
||||||
res = db.defaultVarchar
|
res = db.defaultVarchar
|
||||||
|
if c.Length == -1 {
|
||||||
|
res += "(MAX)"
|
||||||
|
}
|
||||||
case schemas.Char:
|
case schemas.Char:
|
||||||
res = db.defaultChar
|
res = db.defaultChar
|
||||||
|
if c.Length == -1 {
|
||||||
|
res += "(MAX)"
|
||||||
|
}
|
||||||
|
case schemas.NChar:
|
||||||
|
res = t
|
||||||
|
if c.Length == -1 {
|
||||||
|
res += "(MAX)"
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
res = t
|
res = t
|
||||||
}
|
}
|
||||||
|
@ -424,13 +440,17 @@ func (db *mssql) GetColumns(queryer core.Queryer, ctx context.Context, tableName
|
||||||
col.SQLType = schemas.SQLType{Name: schemas.TimeStampz, DefaultLength: 0, DefaultLength2: 0}
|
col.SQLType = schemas.SQLType{Name: schemas.TimeStampz, DefaultLength: 0, DefaultLength2: 0}
|
||||||
case "NVARCHAR":
|
case "NVARCHAR":
|
||||||
col.SQLType = schemas.SQLType{Name: schemas.NVarchar, DefaultLength: 0, DefaultLength2: 0}
|
col.SQLType = schemas.SQLType{Name: schemas.NVarchar, DefaultLength: 0, DefaultLength2: 0}
|
||||||
col.Length /= 2
|
if col.Length > 0 {
|
||||||
col.Length2 /= 2
|
col.Length /= 2
|
||||||
|
col.Length2 /= 2
|
||||||
|
}
|
||||||
case "IMAGE":
|
case "IMAGE":
|
||||||
col.SQLType = schemas.SQLType{Name: schemas.VarBinary, DefaultLength: 0, DefaultLength2: 0}
|
col.SQLType = schemas.SQLType{Name: schemas.VarBinary, DefaultLength: 0, DefaultLength2: 0}
|
||||||
case "NCHAR":
|
case "NCHAR":
|
||||||
col.Length /= 2
|
if col.Length > 0 {
|
||||||
col.Length2 /= 2
|
col.Length /= 2
|
||||||
|
col.Length2 /= 2
|
||||||
|
}
|
||||||
fallthrough
|
fallthrough
|
||||||
default:
|
default:
|
||||||
if _, ok := schemas.SqlTypes[ct]; ok {
|
if _, ok := schemas.SqlTypes[ct]; ok {
|
||||||
|
|
|
@ -157,7 +157,7 @@ func TestSyncTable3(t *testing.T) {
|
||||||
Id int64
|
Id int64
|
||||||
Name string
|
Name string
|
||||||
Text string `xorm:"TEXT"`
|
Text string `xorm:"TEXT"`
|
||||||
Char byte `xorm:"CHAR"`
|
Char byte `xorm:"CHAR(1)"`
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.NoError(t, PrepareEngine())
|
assert.NoError(t, PrepareEngine())
|
||||||
|
@ -197,9 +197,9 @@ func TestSyncTable3(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
tableInfo, err := testEngine.TableInfo(new(SyncTable5))
|
tableInfo, err := testEngine.TableInfo(new(SyncTable5))
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.EqualValues(t, testEngine.Dialect().SQLType(tables[0].GetColumn("name")), testEngine.Dialect().SQLType(tableInfo.GetColumn("name")))
|
assert.EqualValues(t, testEngine.Dialect().SQLType(tableInfo.GetColumn("name")), testEngine.Dialect().SQLType(tables[0].GetColumn("name")))
|
||||||
assert.EqualValues(t, testEngine.Dialect().SQLType(tables[0].GetColumn("text")), testEngine.Dialect().SQLType(tableInfo.GetColumn("text")))
|
assert.EqualValues(t, testEngine.Dialect().SQLType(tableInfo.GetColumn("text")), testEngine.Dialect().SQLType(tables[0].GetColumn("text")))
|
||||||
assert.EqualValues(t, testEngine.Dialect().SQLType(tables[0].GetColumn("char")), testEngine.Dialect().SQLType(tableInfo.GetColumn("char")))
|
assert.EqualValues(t, testEngine.Dialect().SQLType(tableInfo.GetColumn("char")), testEngine.Dialect().SQLType(tables[0].GetColumn("char")))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue