This commit is contained in:
Lunny Xiao 2021-08-04 13:04:05 +08:00
parent 39bd57f7f6
commit ae94d26bde
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
3 changed files with 18 additions and 8 deletions

View File

@ -317,10 +317,10 @@ func (db *mssql) SQLType(c *schemas.Column) string {
if c.Length > 3 { if c.Length > 3 {
res = "DATETIME2" res = "DATETIME2"
} else { } else {
res = schemas.DateTime return schemas.DateTime
} }
case schemas.TimeStampz: case schemas.TimeStampz:
res = "DATETIME2" res = "DATETIMEOFFSET"
c.Length = 7 c.Length = 7
case schemas.MediumInt, schemas.TinyInt, schemas.SmallInt, schemas.UnsignedMediumInt, schemas.UnsignedTinyInt, schemas.UnsignedSmallInt: case schemas.MediumInt, schemas.TinyInt, schemas.SmallInt, schemas.UnsignedMediumInt, schemas.UnsignedTinyInt, schemas.UnsignedSmallInt:
res = schemas.Int res = schemas.Int
@ -504,6 +504,10 @@ func (db *mssql) GetColumns(queryer core.Queryer, ctx context.Context, tableName
} }
case "DATETIME2": case "DATETIME2":
col.SQLType = schemas.SQLType{Name: schemas.DateTime, DefaultLength: 7, DefaultLength2: 0} col.SQLType = schemas.SQLType{Name: schemas.DateTime, DefaultLength: 7, DefaultLength2: 0}
col.Length = scale
case "DATETIME":
col.SQLType = schemas.SQLType{Name: schemas.DateTime, DefaultLength: 3, DefaultLength2: 0}
col.Length = scale
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":

View File

@ -31,16 +31,20 @@ func FormatColumnTime(dialect Dialect, dbLocation *time.Location, col *schemas.C
t = t.In(tmZone) t = t.In(tmZone)
switch col.SQLType.Name { switch col.SQLType.Name {
case schemas.Time:
s := t.Format("2006-01-02 15:04:05") // time.RFC3339
return s[11:19], nil
case schemas.Date: case schemas.Date:
return t.Format("2006-01-02"), nil return t.Format("2006-01-02"), nil
case schemas.DateTime, schemas.TimeStamp: case schemas.Time:
var layout = "15:04:05"
if col.Length > 0 { if col.Length > 0 {
return t.Format("2006-01-02 15:04:05." + strings.Repeat("0", col.Length)), nil layout += "." + strings.Repeat("0", col.Length)
} }
return t.Format("2006-01-02 15:04:05"), nil return t.Format(layout), nil
case schemas.DateTime, schemas.TimeStamp:
var layout = "2006-01-02 15:04:05"
if col.Length > 0 {
layout += "." + strings.Repeat("0", col.Length)
}
return t.Format(layout), nil
case schemas.Varchar: case schemas.Varchar:
return t.Format("2006-01-02 15:04:05"), nil return t.Format("2006-01-02 15:04:05"), nil
case schemas.TimeStampz: case schemas.TimeStampz:

View File

@ -116,6 +116,8 @@ func TestDump(t *testing.T) {
os.Remove(fp) os.Remove(fp)
assert.NoError(t, testEngine.DumpAllToFile(fp)) assert.NoError(t, testEngine.DumpAllToFile(fp))
//panic("")
assert.NoError(t, PrepareEngine()) assert.NoError(t, PrepareEngine())
sess := testEngine.NewSession() sess := testEngine.NewSession()