aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormattn <mattn.jp@gmail.com>2012-08-21 09:23:37 -0700
committermattn <mattn.jp@gmail.com>2012-08-21 09:23:37 -0700
commit3ae2f4307ca4571a2b085db16859860d143c546f (patch)
treec72ceaaa6303472c71b4fae25907abd7868de658
parentMerge pull request #18 from coolaj86/patch-1 (diff)
parentbug fix: Byte slices belong to the caller and so must be copies. (diff)
downloadgolite-3ae2f4307ca4571a2b085db16859860d143c546f.tar.gz
golite-3ae2f4307ca4571a2b085db16859860d143c546f.tar.xz
Merge pull request #19 from leskets/master
bug fix: Byte slice results belong to the caller and so must be copies.
-rw-r--r--sqlite3.go9
1 files changed, 8 insertions, 1 deletions
diff --git a/sqlite3.go b/sqlite3.go
index 161da5e..d3afff5 100644
--- a/sqlite3.go
+++ b/sqlite3.go
@@ -297,7 +297,14 @@ func (rc *SQLiteRows) Next(dest []driver.Value) error {
case C.SQLITE_BLOB:
n := int(C.sqlite3_column_bytes(rc.s.s, C.int(i)))
p := C.sqlite3_column_blob(rc.s.s, C.int(i))
- dest[i] = (*[1 << 30]byte)(unsafe.Pointer(p))[0:n]
+ switch dest[i].(type) {
+ case sql.RawBytes:
+ dest[i] = (*[1 << 30]byte)(unsafe.Pointer(p))[0:n]
+ default:
+ slice := make([]byte, n)
+ copy(slice[:], (*[1 << 30]byte)(unsafe.Pointer(p))[0:n])
+ dest[i] = slice
+ }
case C.SQLITE_NULL:
dest[i] = nil
case C.SQLITE_TEXT: