diff options
author | mattn <mattn.jp@gmail.com> | 2018-11-22 01:48:38 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-22 01:48:38 +0900 |
commit | 873ec5700501bf28c8e6afd40344776235403c03 (patch) | |
tree | b421208f4ee885b0e5fb2c3fd57f8504525c5016 /sqlite3_test.go | |
parent | Merge pull request #644 from akalin/fix-pointer-conversion (diff) | |
parent | Fix bug (diff) | |
download | golite-873ec5700501bf28c8e6afd40344776235403c03.tar.gz golite-873ec5700501bf28c8e6afd40344776235403c03.tar.xz |
Merge pull request #643 from akalin/zero-length-blob
Distinguish between NULL and zero-length blobs on query
Diffstat (limited to 'sqlite3_test.go')
-rw-r--r-- | sqlite3_test.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/sqlite3_test.go b/sqlite3_test.go index a67cf42..0667893 100644 --- a/sqlite3_test.go +++ b/sqlite3_test.go @@ -1770,6 +1770,7 @@ var tests = []testing.InternalTest{ {Name: "TestResult", F: testResult}, {Name: "TestBlobs", F: testBlobs}, {Name: "TestMultiBlobs", F: testMultiBlobs}, + {Name: "TestNullZeroLengthBlobs", F: testNullZeroLengthBlobs}, {Name: "TestManyQueryRow", F: testManyQueryRow}, {Name: "TestTxQuery", F: testTxQuery}, {Name: "TestPreparedStmt", F: testPreparedStmt}, @@ -1975,6 +1976,36 @@ func testMultiBlobs(t *testing.T) { } } +// testBlobs tests that we distinguish between null and zero-length blobs +func testNullZeroLengthBlobs(t *testing.T) { + db.tearDown() + db.mustExec("create table foo (id integer primary key, bar " + db.blobType(16) + ")") + db.mustExec(db.q("insert into foo (id, bar) values(?,?)"), 0, nil) + db.mustExec(db.q("insert into foo (id, bar) values(?,?)"), 1, []byte{}) + + r0 := db.QueryRow(db.q("select bar from foo where id=0")) + var b0 []byte + err := r0.Scan(&b0) + if err != nil { + t.Fatal(err) + } + if b0 != nil { + t.Errorf("for id=0, got %x; want nil", b0) + } + + r1 := db.QueryRow(db.q("select bar from foo where id=1")) + var b1 []byte + err = r1.Scan(&b1) + if err != nil { + t.Fatal(err) + } + if b1 == nil { + t.Error("for id=1, got nil; want zero-length slice") + } else if len(b1) > 0 { + t.Errorf("for id=1, got %x; want zero-length slice", b1) + } +} + // testManyQueryRow is test for many query row func testManyQueryRow(t *testing.T) { if testing.Short() { |