Fix mssql test

This commit is contained in:
Lunny Xiao 2021-07-11 15:08:50 +08:00
parent b054008598
commit 0004399bbf
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
2 changed files with 30 additions and 1 deletions

View File

@ -444,6 +444,18 @@ func (engine *Engine) DumpTables(tables []*schemas.Table, w io.Writer, tp ...sch
return engine.dumpTables(tables, w, tp...) return engine.dumpTables(tables, w, tp...)
} }
func formatBool(s string, dstDialect dialects.Dialect) string {
if dstDialect.URI().DBType == schemas.MSSQL {
switch s {
case "true":
return "1"
case "false":
return "0"
}
}
return s
}
// dumpTables dump database all table structs and data to w with specify db type // dumpTables dump database all table structs and data to w with specify db type
func (engine *Engine) dumpTables(tables []*schemas.Table, w io.Writer, tp ...schemas.DBType) error { func (engine *Engine) dumpTables(tables []*schemas.Table, w io.Writer, tp ...schemas.DBType) error {
var dstDialect dialects.Dialect var dstDialect dialects.Dialect
@ -556,6 +568,17 @@ func (engine *Engine) dumpTables(tables []*schemas.Table, w io.Writer, tp ...sch
return err return err
} }
} }
} else if stp.IsBool() {
s := scanResult.(*sql.NullString)
if s.Valid {
if _, err = io.WriteString(w, formatBool(s.String, dstDialect)); err != nil {
return err
}
} else {
if _, err = io.WriteString(w, "NULL"); err != nil {
return err
}
}
} else { } else {
s := scanResult.(*sql.NullString) s := scanResult.(*sql.NullString)
if s.Valid { if s.Valid {

View File

@ -39,6 +39,7 @@ const (
TIME_TYPE TIME_TYPE
NUMERIC_TYPE NUMERIC_TYPE
ARRAY_TYPE ARRAY_TYPE
BOOL_TYPE
) )
// IsType reutrns ture if the column type is the same as the parameter // IsType reutrns ture if the column type is the same as the parameter
@ -64,6 +65,10 @@ func (s *SQLType) IsTime() bool {
return s.IsType(TIME_TYPE) return s.IsType(TIME_TYPE)
} }
func (s *SQLType) IsBool() bool {
return s.IsType(BOOL_TYPE)
}
// IsNumeric returns true if column is a numeric type // IsNumeric returns true if column is a numeric type
func (s *SQLType) IsNumeric() bool { func (s *SQLType) IsNumeric() bool {
return s.IsType(NUMERIC_TYPE) return s.IsType(NUMERIC_TYPE)
@ -209,7 +214,8 @@ var (
Bytea: BLOB_TYPE, Bytea: BLOB_TYPE,
UniqueIdentifier: BLOB_TYPE, UniqueIdentifier: BLOB_TYPE,
Bool: NUMERIC_TYPE, Bool: BOOL_TYPE,
Boolean: BOOL_TYPE,
Serial: NUMERIC_TYPE, Serial: NUMERIC_TYPE,
BigSerial: NUMERIC_TYPE, BigSerial: NUMERIC_TYPE,