Skip to content

Commit 308f5f1

Browse files
committed
Treat []byte{} as empty bytes instead of NULL.
1 parent 83772a7 commit 308f5f1

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

sqlite3.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -772,11 +772,13 @@ func (s *SQLiteStmt) bind(args []namedValue) error {
772772
case float64:
773773
rv = C.sqlite3_bind_double(s.s, n, C.double(v))
774774
case []byte:
775+
var ptr *byte
775776
if len(v) == 0 {
776-
rv = C._sqlite3_bind_blob(s.s, n, nil, 0)
777+
ptr = &(make([]byte, 1)[0])
777778
} else {
778-
rv = C._sqlite3_bind_blob(s.s, n, unsafe.Pointer(&v[0]), C.int(len(v)))
779+
ptr = &v[0]
779780
}
781+
rv = C._sqlite3_bind_blob(s.s, n, unsafe.Pointer(ptr), C.int(len(v)))
780782
case time.Time:
781783
b := []byte(v.Format(SQLiteTimestampFormats[0]))
782784
rv = C._sqlite3_bind_text(s.s, n, (*C.char)(unsafe.Pointer(&b[0])), C.int(len(b)))

0 commit comments

Comments
 (0)