Subject: | BLOB cannot handle NUL (\x00) characters |
SQLite documentation says that BLOB's can contain NUL characters, but data is truncated at first ocurrence of NUL. The problem seems to be in the retrieval function, as data can be found into database file.
Maybe this is a bug of SQLite itself (standalone program sqlite3 exibits the same behaviour), see discussion at:
http://www.perlmonks.org/?node_id=491622
- - - - - -
# The following code outputs just "ABC":
use DBI;
my $dbh = DBI->connect('DBI:SQLite:dbname=test_blob.db', '', '');
$dbh->do('CREATE TABLE test_blob( Bindata BLOB )');
my $bindata = "ABC" . "\x00" . "DEF";
my $sth1 = $dbh->prepare('INSERT INTO test_blob VALUES(?)' );
$sth1->execute($bindata);
my $sth2 = $dbh->prepare('SELECT Bindata FROM test_blob');
$sth2->execute();
my $row = $sth2->fetch();
my $fetched_data = $row->[0];
$sth2->finish();
$dbh->disconnect;
print $fetched_data;