SanitizeSql now supports nil

pgx-vs-pq
Jack Christensen 2014-01-18 22:13:50 -06:00
parent 06d75e0fee
commit d4c2a2f18b
2 changed files with 6 additions and 0 deletions

View File

@ -76,6 +76,8 @@ func (c *Connection) SanitizeSql(sql string, args ...interface{}) (output string
var s string
s, err = int64SliceToArrayString(arg)
return c.QuoteString(s)
case nil:
return "null"
default:
err = fmt.Errorf("Unable to sanitize type: %T", arg)
return ""

View File

@ -19,6 +19,10 @@ func TestQuoteString(t *testing.T) {
func TestSanitizeSql(t *testing.T) {
conn := getSharedConnection(t)
if san, err := conn.SanitizeSql("select $1", nil); err != nil || san != "select null" {
t.Errorf("Failed to translate nil to null: %v - %v", san, err)
}
if san, err := conn.SanitizeSql("select $1", "Jack's"); err != nil || san != "select 'Jack''s'" {
t.Errorf("Failed to sanitize string: %v - %v", san, err)
}