@@ -338,6 +338,7 @@ func (db *mssql) TableCheckSql(tableName string) (string, []interface{}) {
338338func (db * mssql ) GetColumns (tableName string ) ([]string , map [string ]* core.Column , error ) {
339339 args := []interface {}{}
340340 s := `select a.name as name, b.name as ctype,a.max_length,a.precision,a.scale,a.is_nullable as nullable,
341+ "default_is_null" = (CASE WHEN c.text is null THEN 1 ELSE 0 END),
341342 replace(replace(isnull(c.text,''),'(',''),')','') as vdefault,
342343 ISNULL(i.is_primary_key, 0)
343344 from sys.columns a
@@ -361,8 +362,8 @@ func (db *mssql) GetColumns(tableName string) ([]string, map[string]*core.Column
361362 for rows .Next () {
362363 var name , ctype , vdefault string
363364 var maxLen , precision , scale int
364- var nullable , isPK bool
365- err = rows .Scan (& name , & ctype , & maxLen , & precision , & scale , & nullable , & vdefault , & isPK )
365+ var nullable , isPK , defaultIsNull bool
366+ err = rows .Scan (& name , & ctype , & maxLen , & precision , & scale , & nullable , & defaultIsNull , & vdefault , & isPK )
366367 if err != nil {
367368 return nil , nil , err
368369 }
@@ -371,7 +372,10 @@ func (db *mssql) GetColumns(tableName string) ([]string, map[string]*core.Column
371372 col .Indexes = make (map [string ]int )
372373 col .Name = strings .Trim (name , "` " )
373374 col .Nullable = nullable
374- col .Default = vdefault
375+ col .DefaultIsEmpty = defaultIsNull
376+ if ! defaultIsNull {
377+ col .Default = vdefault
378+ }
375379 col .IsPrimaryKey = isPK
376380 ct := strings .ToUpper (ctype )
377381 if ct == "DECIMAL" {
@@ -395,15 +399,6 @@ func (db *mssql) GetColumns(tableName string) ([]string, map[string]*core.Column
395399 }
396400 }
397401
398- if col .SQLType .IsText () || col .SQLType .IsTime () {
399- if col .Default != "" {
400- col .Default = "'" + col .Default + "'"
401- } else {
402- if col .DefaultIsEmpty {
403- col .Default = "''"
404- }
405- }
406- }
407402 cols [col .Name ] = col
408403 colSeq = append (colSeq , col .Name )
409404 }
0 commit comments