handle mssql properly

Signed-off-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
Andrew Thornton 2022-01-05 23:25:16 +00:00
parent d03d953a3f
commit 83817e383e
No known key found for this signature in database
GPG Key ID: 3CDE74631F13A748
1 changed files with 9 additions and 5 deletions

View File

@ -776,14 +776,18 @@ func (engine *Engine) dumpTables(ctx context.Context, tables []*schemas.Table, w
}
}
}
} else if dstDialect.URI().DBType == schemas.MSSQL {
if dstTable.Columns()[i].SQLType.IsBlob() {
// MSSQL uses CONVERT(VARBINARY(MAX), '0xDEADBEEF', 1)
if _, err := fmt.Fprintf(w, "CONVERT(VARBINARY(MAX), '0x%x', 1)", s.String); err != nil {
return err
}
} else {
// In MSSQL we have to use NChar format to get unicode strings.
if dstDialect.URI().DBType == schemas.MSSQL && dstTable.Columns()[i].SQLType.IsText() {
if _, err = io.WriteString(w, "N"); err != nil {
if _, err = io.WriteString(w, "N'"+strings.ReplaceAll(s.String, "'", "''")+"'"); err != nil {
return err
}
}
} else {
if _, err = io.WriteString(w, "'"+strings.ReplaceAll(s.String, "'", "''")+"'"); err != nil {
return err
}