@@ -1770,6 +1770,7 @@ var tests = []testing.InternalTest{
1770
1770
{Name : "TestResult" , F : testResult },
1771
1771
{Name : "TestBlobs" , F : testBlobs },
1772
1772
{Name : "TestMultiBlobs" , F : testMultiBlobs },
1773
+ {Name : "TestNullZeroLengthBlobs" , F : testNullZeroLengthBlobs },
1773
1774
{Name : "TestManyQueryRow" , F : testManyQueryRow },
1774
1775
{Name : "TestTxQuery" , F : testTxQuery },
1775
1776
{Name : "TestPreparedStmt" , F : testPreparedStmt },
@@ -1975,6 +1976,36 @@ func testMultiBlobs(t *testing.T) {
1975
1976
}
1976
1977
}
1977
1978
1979
+ // testBlobs tests that we distinguish between null and zero-length blobs
1980
+ func testNullZeroLengthBlobs (t * testing.T ) {
1981
+ db .tearDown ()
1982
+ db .mustExec ("create table foo (id integer primary key, bar " + db .blobType (16 ) + ")" )
1983
+ db .mustExec (db .q ("insert into foo (id, bar) values(?,?)" ), 0 , nil )
1984
+ db .mustExec (db .q ("insert into foo (id, bar) values(?,?)" ), 1 , []byte {})
1985
+
1986
+ r0 := db .QueryRow (db .q ("select bar from foo where id=0" ))
1987
+ var b0 []byte
1988
+ err := r0 .Scan (& b0 )
1989
+ if err != nil {
1990
+ t .Fatal (err )
1991
+ }
1992
+ if b0 != nil {
1993
+ t .Errorf ("for id=0, got %x; want nil" , b0 )
1994
+ }
1995
+
1996
+ r1 := db .QueryRow (db .q ("select bar from foo where id=1" ))
1997
+ var b1 []byte
1998
+ err = r1 .Scan (& b1 )
1999
+ if err != nil {
2000
+ t .Fatal (err )
2001
+ }
2002
+ if b1 == nil {
2003
+ t .Error ("for id=1, got nil; want zero-length slice" )
2004
+ } else if len (b1 ) > 0 {
2005
+ t .Errorf ("for id=1, got %x; want zero-length slice" , b1 )
2006
+ }
2007
+ }
2008
+
1978
2009
// testManyQueryRow is test for many query row
1979
2010
func testManyQueryRow (t * testing.T ) {
1980
2011
if testing .Short () {
0 commit comments