Skip to content

Commit ccd1699

Browse files
committed
handle **[]byte for nullable bytes
1 parent 854f833 commit ccd1699

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

sqlite3_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type TestRow struct {
2121
Text string
2222
Textn *string
2323
Blob []byte
24-
Blobn []byte
24+
Blobn *[]byte
2525
Time time.Time
2626
Timen *time.Time
2727
}

stmt.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,17 @@ func (s *Stmt) Bind(args ...interface{}) error {
179179
} else {
180180
rc = C.sqlite3_bind_blob(stmt, bindIndex, cBytes(v), C.int(len(v)), C.SQLITE_TRANSIENT)
181181
}
182+
case *[]byte:
183+
if v == nil {
184+
C.sqlite3_bind_null(stmt, bindIndex)
185+
} else {
186+
vv := *v
187+
if len(vv) == 0 {
188+
rc = C.sqlite3_bind_zeroblob(stmt, bindIndex, 0)
189+
} else {
190+
rc = C.sqlite3_bind_blob(stmt, bindIndex, cBytes(vv), C.int(len(vv)), C.SQLITE_TRANSIENT)
191+
}
192+
}
182193
case time.Time:
183194
rc = C.sqlite3_bind_int64(stmt, bindIndex, C.sqlite3_int64(v.Unix()))
184195
case *time.Time:
@@ -356,6 +367,18 @@ func (s *Stmt) scan(i int, v interface{}) error {
356367
}
357368
case *[]byte:
358369
*v, err = s.ColumnBytes(i)
370+
case **[]byte:
371+
if s.columnTypes[i] != C.SQLITE_NULL {
372+
n, e := s.ColumnBytes(i)
373+
if e != nil {
374+
err = e
375+
} else {
376+
*v = &n
377+
if v == nil {
378+
v = nil
379+
}
380+
}
381+
}
359382
case *RawBytes:
360383
*v, err = s.ColumnRawBytes(i)
361384
case *time.Time:

0 commit comments

Comments
 (0)