diff options
author | mattn <mattn.jp@gmail.com> | 2018-05-31 22:29:18 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-31 22:29:18 +0900 |
commit | 6d0b39d7bc5136196a370d1b5b899af93baa5799 (patch) | |
tree | 959de205047b73eab66fccc17b0b6146510be00a /sqlite3.go | |
parent | Merge pull request #577 from GJRTimmer/update/docs (diff) | |
parent | Add zero-length slice test (diff) | |
download | golite-6d0b39d7bc5136196a370d1b5b899af93baa5799.tar.gz golite-6d0b39d7bc5136196a370d1b5b899af93baa5799.tar.xz |
Merge pull request #583 from lucasmrod/bug/#542-nil-byte-slice-to-null-blob
Add nil check in bind and a test
Diffstat (limited to 'sqlite3.go')
-rw-r--r-- | sqlite3.go | 12 |
1 files changed, 8 insertions, 4 deletions
@@ -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))) |