From 21b54e5d61153c57604488a99dbb4c85516993ea Mon Sep 17 00:00:00 2001 From: CyJaySong Date: Fri, 21 Jul 2023 11:12:31 +0800 Subject: [PATCH] fix code --- dialects/mssql.go | 7 +++++-- integrations/session_insert_test.go | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/dialects/mssql.go b/dialects/mssql.go index 5a825c79..dcac9c3f 100644 --- a/dialects/mssql.go +++ b/dialects/mssql.go @@ -320,8 +320,11 @@ func (db *mssql) SQLType(c *schemas.Column) string { res += "(MAX)" } case schemas.TimeStamp, schemas.DateTime: - c.Length = 7 - return "DATETIME2" + if c.Length > 3 { + res = "DATETIME2" + } else { + return schemas.DateTime + } case schemas.TimeStampz: res = "DATETIMEOFFSET" c.Length = 7 diff --git a/integrations/session_insert_test.go b/integrations/session_insert_test.go index 5af5b9e4..58a2a91d 100644 --- a/integrations/session_insert_test.go +++ b/integrations/session_insert_test.go @@ -1209,7 +1209,7 @@ func TestInsertNotDeleted(t *testing.T) { type TestInsertNotDeletedStructNotRight struct { ID uint64 `xorm:"'ID' pk autoincr"` - DeletedAt time.Time `xorm:"'DELETED_AT' deleted notnull"` + DeletedAt time.Time `xorm:"'DELETED_AT' DATETIME(6) deleted notnull"` } // notnull tag will be ignored err := testEngine.Sync(new(TestInsertNotDeletedStructNotRight)) @@ -1217,7 +1217,7 @@ func TestInsertNotDeleted(t *testing.T) { type TestInsertNotDeletedStruct struct { ID uint64 `xorm:"'ID' pk autoincr"` - DeletedAt time.Time `xorm:"'DELETED_AT' deleted"` + DeletedAt time.Time `xorm:"'DELETED_AT' DATETIME(6) deleted"` } assert.NoError(t, testEngine.Sync(new(TestInsertNotDeletedStruct)))