forked from mirror/go-sqlite3
allow to insert zero-length strings into database
&b[0] fails with an index out-of-bounds error for a slice with len()==0
This commit is contained in:
parent
fdbb364aba
commit
01566134d1
|
@ -154,8 +154,13 @@ func (s *SQLiteStmt) bind(args []interface{}) error {
|
||||||
case nil:
|
case nil:
|
||||||
rv = C.sqlite3_bind_null(s.s, n)
|
rv = C.sqlite3_bind_null(s.s, n)
|
||||||
case string:
|
case string:
|
||||||
|
if len(v) == 0 {
|
||||||
|
b := []byte{0}
|
||||||
|
rv = C._sqlite3_bind_text(s.s, n, (*C.char)(unsafe.Pointer(&b[0])), C.int(0))
|
||||||
|
} else {
|
||||||
b := []byte(v)
|
b := []byte(v)
|
||||||
rv = C._sqlite3_bind_text(s.s, n, (*C.char)(unsafe.Pointer(&b[0])), C.int(len(b)))
|
rv = C._sqlite3_bind_text(s.s, n, (*C.char)(unsafe.Pointer(&b[0])), C.int(len(b)))
|
||||||
|
}
|
||||||
case int:
|
case int:
|
||||||
rv = C.sqlite3_bind_int(s.s, n, C.int(v))
|
rv = C.sqlite3_bind_int(s.s, n, C.int(v))
|
||||||
case int64:
|
case int64:
|
||||||
|
|
Loading…
Reference in New Issue