Added SanitizeSql bool support

pgx-vs-pq
Jack Christensen 2013-08-06 10:20:32 -05:00
parent 2699bf6187
commit f079d84728
2 changed files with 6 additions and 0 deletions

View File

@ -60,6 +60,8 @@ func (c *Connection) SanitizeSql(sql string, args ...interface{}) (output string
return strconv.FormatFloat(float64(arg), 'f', -1, 32)
case float64:
return strconv.FormatFloat(arg, 'f', -1, 64)
case bool:
return strconv.FormatBool(arg)
case []byte:
return `E'\\x` + hex.EncodeToString(arg) + `'`
case []int16:

View File

@ -31,6 +31,10 @@ func TestSanitizeSql(t *testing.T) {
t.Errorf("Failed to pass through float: %v - %v", san, err)
}
if san, err := conn.SanitizeSql("select $1", true); err != nil || san != "select true" {
t.Errorf("Failed to pass through bool: %v - %v", san, err)
}
if san, err := conn.SanitizeSql("select $1, $2, $3", "Jack's", 42, 1.23); err != nil || san != "select 'Jack''s', 42, 1.23" {
t.Errorf("Failed to sanitize multiple params: %v - %v", san, err)
}