mirror of
https://github.com/glebarez/go-sqlite.git
synced 2025-10-04 07:26:28 +08:00
Fix handling of nil []byte as NULL values
This fixes a regression introduced in 87412bbfa9b5b979ca4d4e8ba69c347819b9c4da, which changed nil []byte values by storing them as zero-sized blobs, instead of NULLs. Closes #100
This commit is contained in:

committed by
glebarez

parent
980139ad3e
commit
8e88a000fe
@@ -1147,7 +1147,7 @@ func (c *conn) bindText(pstmt uintptr, idx1 int, value string) (uintptr, error)
|
||||
|
||||
// int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));
|
||||
func (c *conn) bindBlob(pstmt uintptr, idx1 int, value []byte) (uintptr, error) {
|
||||
if len(value) == 0 {
|
||||
if value != nil && len(value) == 0 {
|
||||
if rc := sqlite3.Xsqlite3_bind_zeroblob(c.tls, pstmt, int32(idx1), 0); rc != sqlite3.SQLITE_OK {
|
||||
return 0, c.errstr(rc)
|
||||
}
|
||||
@@ -1158,7 +1158,9 @@ func (c *conn) bindBlob(pstmt uintptr, idx1 int, value []byte) (uintptr, error)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
copy((*libc.RawMem)(unsafe.Pointer(p))[:len(value):len(value)], value)
|
||||
if len(value) != 0 {
|
||||
copy((*libc.RawMem)(unsafe.Pointer(p))[:len(value):len(value)], value)
|
||||
}
|
||||
if rc := sqlite3.Xsqlite3_bind_blob(c.tls, pstmt, int32(idx1), p, int32(len(value)), 0); rc != sqlite3.SQLITE_OK {
|
||||
c.free(p)
|
||||
return 0, c.errstr(rc)
|
||||
|
Reference in New Issue
Block a user