Repository: mattn/go-sqlite3 (c)

Issue:
Dead code in SQLiteRows.Next
Hello,
The following test (line 502 of sqlite.go) is useless:

```
                    switch dest[i].(type) {
                    case sql.RawBytes:
                            dest[i] = (*[1 << 30]byte)(unsafe.Pointer(p))[0:n]
                    default:
```

Just take a look at the caller:
http://golang.org/src/pkg/database/sql/sql.go?s=38519:38546#L1492

```
if rs.lastcols == nil {
    rs.lastcols = make([]driver.Value, len(rs.rowsi.Columns()))
}
rs.lasterr = rs.rowsi.Next(rs.lastcols)
```

The final/target type is not known when driver.Rows.Next is called...

Regards.


Pull request description:
fix/118
* Added TestMultiBlobs
* Removed dead code

Fixes #118

Patch:
diff --git a/sqlite3.go b/sqlite3.go
index 17291dc..d8fe4b0 100644
--- a/sqlite3.go
+++ b/sqlite3.go
@@ -1937,8 +1937,6 @@ func (rc *SQLiteRows) Next(dest []driver.Value) error {
 			}
 			n := int(C.sqlite3_column_bytes(rc.s.s, C.int(i)))
 			switch dest[i].(type) {
-			case sql.RawBytes:
-				dest[i] = (*[1 << 30]byte)(p)[0:n]
 			default:
 				slice := make([]byte, n)
 				copy(slice[:], (*[1 << 30]byte)(p)[0:n])


Test patch:
diff --git a/sqlite3_test.go b/sqlite3_test.go
index eadcf4a..186a2dd 100644
--- a/sqlite3_test.go
+++ b/sqlite3_test.go
@@ -1679,6 +1679,7 @@ var testTables = []string{"foo", "bar", "t", "bench"}
 var tests = []testing.InternalTest{
 	{Name: "TestResult", F: testResult},
 	{Name: "TestBlobs", F: testBlobs},
+	{Name: "TestMultiBlobs", F: testMultiBlobs},
 	{Name: "TestManyQueryRow", F: testManyQueryRow},
 	{Name: "TestTxQuery", F: testTxQuery},
 	{Name: "TestPreparedStmt", F: testPreparedStmt},
@@ -1834,6 +1835,56 @@ func testBlobs(t *testing.T) {
 	}
 }
 
+func testMultiBlobs(t *testing.T) {
+	db.tearDown()
+	db.mustExec("create table foo (id integer primary key, bar " + db.blobType(16) + ")")
+	var blob0 = []byte{0, 1, 2, 3, 4, 5, 6, 7}
+	db.mustExec(db.q("insert into foo (id, bar) values(?,?)"), 0, blob0)
+	var blob1 = []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}
+	db.mustExec(db.q("insert into foo (id, bar) values(?,?)"), 1, blob1)
+
+	r, err := db.Query(db.q("select bar from foo order by id"))
+	if err != nil {
+		t.Fatal(err)
+	}
+	defer r.Close()
+	if !r.Next() {
+		if r.Err() != nil {
+			t.Fatal(err)
+		}
+		t.Fatal("expected one rows")
+	}
+
+	want0 := fmt.Sprintf("%x", blob0)
+	b0 := make([]byte, 8)
+	err = r.Scan(&b0)
+	if err != nil {
+		t.Fatal(err)
+	}
+	got0 := fmt.Sprintf("%x", b0)
+
+	if !r.Next() {
+		if r.Err() != nil {
+			t.Fatal(err)
+		}
+		t.Fatal("expected one rows")
+	}
+
+	want1 := fmt.Sprintf("%x", blob1)
+	b1 := make([]byte, 16)
+	err = r.Scan(&b1)
+	if err != nil {
+		t.Fatal(err)
+	}
+	got1 := fmt.Sprintf("%x", b1)
+	if got0 != want0 {
+		t.Errorf("for []byte, got %q; want %q", got0, want0)
+	}
+	if got1 != want1 {
+		t.Errorf("for []byte, got %q; want %q", got1, want1)
+	}
+}
+
 // testManyQueryRow is test for many query row
 func testManyQueryRow(t *testing.T) {
 	if testing.Short() {