Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 62b7bd5

Browse files
fix/118
* Added TestMultiBlobs * Removed dead code Fixes mattn#118
1 parent f268891 commit 62b7bd5

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

‎sqlite3.go‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1937,8 +1937,6 @@ func (rc *SQLiteRows) Next(dest []driver.Value) error {
19371937
}
19381938
n := int(C.sqlite3_column_bytes(rc.s.s, C.int(i)))
19391939
switch dest[i].(type) {
1940-
case sql.RawBytes:
1941-
dest[i] = (*[1 << 30]byte)(p)[0:n]
19421940
default:
19431941
slice := make([]byte, n)
19441942
copy(slice[:], (*[1 << 30]byte)(p)[0:n])

‎sqlite3_test.go‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,6 +1679,7 @@ var testTables = []string{"foo", "bar", "t", "bench"}
16791679
var tests = []testing.InternalTest{
16801680
{Name: "TestResult", F: testResult},
16811681
{Name: "TestBlobs", F: testBlobs},
1682+
{Name: "TestMultiBlobs", F: testMultiBlobs},
16821683
{Name: "TestManyQueryRow", F: testManyQueryRow},
16831684
{Name: "TestTxQuery", F: testTxQuery},
16841685
{Name: "TestPreparedStmt", F: testPreparedStmt},
@@ -1834,6 +1835,56 @@ func testBlobs(t *testing.T) {
18341835
}
18351836
}
18361837

1838+
func testMultiBlobs(t *testing.T) {
1839+
db.tearDown()
1840+
db.mustExec("create table foo (id integer primary key, bar " + db.blobType(16) + ")")
1841+
var blob0 = []byte{0, 1, 2, 3, 4, 5, 6, 7}
1842+
db.mustExec(db.q("insert into foo (id, bar) values(?,?)"), 0, blob0)
1843+
var blob1 = []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}
1844+
db.mustExec(db.q("insert into foo (id, bar) values(?,?)"), 1, blob1)
1845+
1846+
r, err := db.Query(db.q("select bar from foo order by id"))
1847+
if err != nil {
1848+
t.Fatal(err)
1849+
}
1850+
defer r.Close()
1851+
if !r.Next() {
1852+
if r.Err() != nil {
1853+
t.Fatal(err)
1854+
}
1855+
t.Fatal("expected one rows")
1856+
}
1857+
1858+
want0 := fmt.Sprintf("%x", blob0)
1859+
b0 := make([]byte, 8)
1860+
err = r.Scan(&b0)
1861+
if err != nil {
1862+
t.Fatal(err)
1863+
}
1864+
got0 := fmt.Sprintf("%x", b0)
1865+
1866+
if !r.Next() {
1867+
if r.Err() != nil {
1868+
t.Fatal(err)
1869+
}
1870+
t.Fatal("expected one rows")
1871+
}
1872+
1873+
want1 := fmt.Sprintf("%x", blob1)
1874+
b1 := make([]byte, 16)
1875+
err = r.Scan(&b1)
1876+
if err != nil {
1877+
t.Fatal(err)
1878+
}
1879+
got1 := fmt.Sprintf("%x", b1)
1880+
if got0 != want0 {
1881+
t.Errorf("for []byte, got %q; want %q", got0, want0)
1882+
}
1883+
if got1 != want1 {
1884+
t.Errorf("for []byte, got %q; want %q", got1, want1)
1885+
}
1886+
}
1887+
18371888
// testManyQueryRow is test for many query row
18381889
func testManyQueryRow(t *testing.T) {
18391890
if testing.Short() {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /