aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormattn <mattn.jp@gmail.com>2017-06-15 10:15:43 +0900
committerGitHub <noreply@github.com>2017-06-15 10:15:43 +0900
commit83c59d8440943c680f94ebbe51118df4244414d6 (patch)
tree035930342ee0510d83ab8ee47e4068bdc50247c3
parentMerge pull request #421 from flimzy/readme (diff)
parentUse global variable for better performance. (diff)
downloadgolite-83c59d8440943c680f94ebbe51118df4244414d6.tar.gz
golite-83c59d8440943c680f94ebbe51118df4244414d6.tar.xz
Merge pull request #425 from xxr3376/empty-bytes
Treat []byte{} as empty BLOB instead of NULL.
-rw-r--r--sqlite3.go11
1 files changed, 7 insertions, 4 deletions
diff --git a/sqlite3.go b/sqlite3.go
index 33b9b9c..56e55e2 100644
--- a/sqlite3.go
+++ b/sqlite3.go
@@ -734,6 +734,8 @@ type bindArg struct {
v driver.Value
}
+var placeHolder byte = 0
+
func (s *SQLiteStmt) bind(args []namedValue) error {
rv := C.sqlite3_reset(s.s)
if rv != C.SQLITE_ROW && rv != C.SQLITE_OK && rv != C.SQLITE_DONE {
@@ -755,8 +757,7 @@ func (s *SQLiteStmt) bind(args []namedValue) error {
rv = C.sqlite3_bind_null(s.s, n)
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))
+ rv = C._sqlite3_bind_text(s.s, n, (*C.char)(unsafe.Pointer(&placeHolder)), C.int(0))
} else {
b := []byte(v)
rv = C._sqlite3_bind_text(s.s, n, (*C.char)(unsafe.Pointer(&b[0])), C.int(len(b)))
@@ -772,11 +773,13 @@ func (s *SQLiteStmt) bind(args []namedValue) error {
case float64:
rv = C.sqlite3_bind_double(s.s, n, C.double(v))
case []byte:
+ var ptr *byte
if len(v) == 0 {
- rv = C._sqlite3_bind_blob(s.s, n, nil, 0)
+ ptr = &placeHolder
} else {
- rv = C._sqlite3_bind_blob(s.s, n, unsafe.Pointer(&v[0]), C.int(len(v)))
+ ptr = &v[0]
}
+ rv = C._sqlite3_bind_blob(s.s, n, unsafe.Pointer(ptr), C.int(len(v)))
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)))