Added SanitizeSql bool support
This commit is contained in:
@@ -60,6 +60,8 @@ func (c *Connection) SanitizeSql(sql string, args ...interface{}) (output string
|
|||||||
return strconv.FormatFloat(float64(arg), 'f', -1, 32)
|
return strconv.FormatFloat(float64(arg), 'f', -1, 32)
|
||||||
case float64:
|
case float64:
|
||||||
return strconv.FormatFloat(arg, 'f', -1, 64)
|
return strconv.FormatFloat(arg, 'f', -1, 64)
|
||||||
|
case bool:
|
||||||
|
return strconv.FormatBool(arg)
|
||||||
case []byte:
|
case []byte:
|
||||||
return `E'\\x` + hex.EncodeToString(arg) + `'`
|
return `E'\\x` + hex.EncodeToString(arg) + `'`
|
||||||
case []int16:
|
case []int16:
|
||||||
|
|||||||
@@ -31,6 +31,10 @@ func TestSanitizeSql(t *testing.T) {
|
|||||||
t.Errorf("Failed to pass through float: %v - %v", san, err)
|
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" {
|
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)
|
t.Errorf("Failed to sanitize multiple params: %v - %v", san, err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user