This commit is contained in:
Evgeniy Makeev 2017-06-20 17:36:44 -07:00
parent a819994f72
commit ef9f773b24
1 changed files with 4 additions and 7 deletions

View File

@ -747,7 +747,7 @@ type bindArg struct {
v driver.Value v driver.Value
} }
var placeHolder byte = 0 var placeHolder = []byte{0}
func (s *SQLiteStmt) bind(args []namedValue) error { func (s *SQLiteStmt) bind(args []namedValue) error {
rv := C.sqlite3_reset(s.s) rv := C.sqlite3_reset(s.s)
@ -770,7 +770,7 @@ func (s *SQLiteStmt) bind(args []namedValue) error {
rv = C.sqlite3_bind_null(s.s, n) rv = C.sqlite3_bind_null(s.s, n)
case string: case string:
if len(v) == 0 { if len(v) == 0 {
rv = C._sqlite3_bind_text(s.s, n, (*C.char)(unsafe.Pointer(&placeHolder)), C.int(0)) rv = C._sqlite3_bind_text(s.s, n, (*C.char)(unsafe.Pointer(&placeHolder[0])), C.int(0))
} else { } else {
b := []byte(v) b := []byte(v)
rv = C._sqlite3_bind_text(s.s, n, (*C.char)(unsafe.Pointer(&b[0])), C.int(len(b))) rv = C._sqlite3_bind_text(s.s, n, (*C.char)(unsafe.Pointer(&b[0])), C.int(len(b)))
@ -786,13 +786,10 @@ func (s *SQLiteStmt) bind(args []namedValue) error {
case float64: case float64:
rv = C.sqlite3_bind_double(s.s, n, C.double(v)) rv = C.sqlite3_bind_double(s.s, n, C.double(v))
case []byte: case []byte:
var ptr *byte
if len(v) == 0 { if len(v) == 0 {
ptr = &placeHolder v = placeHolder
} else {
ptr = &v[0]
} }
rv = C._sqlite3_bind_blob(s.s, n, unsafe.Pointer(ptr), C.int(len(v))) rv = C._sqlite3_bind_blob(s.s, n, unsafe.Pointer(&v[0]), C.int(len(v)))
case time.Time: case time.Time:
b := []byte(v.Format(SQLiteTimestampFormats[0])) b := []byte(v.Format(SQLiteTimestampFormats[0]))
rv = C._sqlite3_bind_text(s.s, n, (*C.char)(unsafe.Pointer(&b[0])), C.int(len(b))) rv = C._sqlite3_bind_text(s.s, n, (*C.char)(unsafe.Pointer(&b[0])), C.int(len(b)))