Fix mssql test
This commit is contained in:
parent
b054008598
commit
0004399bbf
23
engine.go
23
engine.go
|
@ -444,6 +444,18 @@ func (engine *Engine) DumpTables(tables []*schemas.Table, w io.Writer, tp ...sch
|
|||
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
|
||||
func (engine *Engine) dumpTables(tables []*schemas.Table, w io.Writer, tp ...schemas.DBType) error {
|
||||
var dstDialect dialects.Dialect
|
||||
|
@ -556,6 +568,17 @@ func (engine *Engine) dumpTables(tables []*schemas.Table, w io.Writer, tp ...sch
|
|||
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 {
|
||||
s := scanResult.(*sql.NullString)
|
||||
if s.Valid {
|
||||
|
|
|
@ -39,6 +39,7 @@ const (
|
|||
TIME_TYPE
|
||||
NUMERIC_TYPE
|
||||
ARRAY_TYPE
|
||||
BOOL_TYPE
|
||||
)
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
func (s *SQLType) IsBool() bool {
|
||||
return s.IsType(BOOL_TYPE)
|
||||
}
|
||||
|
||||
// IsNumeric returns true if column is a numeric type
|
||||
func (s *SQLType) IsNumeric() bool {
|
||||
return s.IsType(NUMERIC_TYPE)
|
||||
|
@ -209,7 +214,8 @@ var (
|
|||
Bytea: BLOB_TYPE,
|
||||
UniqueIdentifier: BLOB_TYPE,
|
||||
|
||||
Bool: NUMERIC_TYPE,
|
||||
Bool: BOOL_TYPE,
|
||||
Boolean: BOOL_TYPE,
|
||||
|
||||
Serial: NUMERIC_TYPE,
|
||||
BigSerial: NUMERIC_TYPE,
|
||||
|
|
Loading…
Reference in New Issue