Merge pull request #267 from ianlancetaylor/go16

bind: pass &v[0] in direct call to C
This commit is contained in:
mattn 2016-02-01 14:34:37 +09:00
commit c5aee96497
1 changed files with 4 additions and 4 deletions

View File

@ -815,11 +815,11 @@ func (s *SQLiteStmt) bind(args []driver.Value) 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 p *byte if len(v) == 0 {
if len(v) > 0 { rv = C._sqlite3_bind_blob(s.s, n, nil, 0)
p = &v[0] } else {
rv = C._sqlite3_bind_blob(s.s, n, unsafe.Pointer(&v[0]), C.int(len(v)))
} }
rv = C._sqlite3_bind_blob(s.s, n, unsafe.Pointer(p), 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)))