Add nil check in bind and a test

This commit is contained in:
Lucas Manuel Rodriguez
2018-05-30 21:39:01 -03:00
parent 5a7d2e245e
commit 8d6d326be6
2 changed files with 23 additions and 4 deletions

View File

@@ -1511,11 +1511,15 @@ func (s *SQLiteStmt) bind(args []namedValue) error {
case float64:
rv = C.sqlite3_bind_double(s.s, n, C.double(v))
case []byte:
ln := len(v)
if ln == 0 {
v = placeHolder
if v == nil {
rv = C.sqlite3_bind_null(s.s, n)
} else {
ln := len(v)
if ln == 0 {
v = placeHolder
}
rv = C._sqlite3_bind_blob(s.s, n, unsafe.Pointer(&v[0]), C.int(ln))
}
rv = C._sqlite3_bind_blob(s.s, n, unsafe.Pointer(&v[0]), C.int(ln))
case time.Time:
b := []byte(v.Format(SQLiteTimestampFormats[0]))
rv = C._sqlite3_bind_text(s.s, n, (*C.char)(unsafe.Pointer(&b[0])), C.int(len(b)))