Skip Menu |
 

This queue is for tickets about the DBD-SQLite CPAN distribution.

Report information
The Basics
Id: 71311
Status: resolved
Priority: 0/
Queue: DBD-SQLite

People
Owner: Nobody in particular
Requestors: bohica [...] ntlworld.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 1.33
Fixed in: (no value)



Subject: binding output columns as SQL_BLOB returns nothing
Download (untitled) / with headers
text/plain 3.3k
Here is the mail I posted to sqlite mailing list. It shows a problem as the code stands in that binding a column as an SQL_BLOB returns nothing. The test code expects to have an in.png. Further to the above, I've been experimenting and I also looked at https://rt.cpan.org/Ticket/Display.html?id=19471 which suggested that either binding on input as a SQL_BLOB or binding on output as an SQL_BLOB would not set the utd8 flag. I confirm the former but when binding a column on a select as SQL_BLOB I get no data back at all: Before this test in.png is a valid png file and out.png does not exist. Output is: C:>perl sqlite4.pl UTF8 flag 1 UTF8 flag Use of uninitialized value $col2 in print at sqlite4.pl line 65, <$ifh> line 1. C:>dir out.png 27/09/2011 22:44 0 out.png 1 File(s) 0 bytes 0 Dir(s) 15,804,985,344 bytes free Altering the script to use the bind_col without specifying the type produces: C:>perl sqlite4.pl UTF8 flag 1 UTF8 flag C:>dir out.png 27/09/2011 22:46 12,987 out.png 1 File(s) 12,987 bytes 0 Dir(s) 15,804,968,960 bytes free Also selectall_arrayref with out any bound columns works. In other words, specifying a type on bind_col seems to result in returning no data at all. Some DBDs ignore the TYPE on bind_col (actually, most do) - DBD::SQLite does not appear to be one of those though (based on the above results). I was experimenting with the idea that specifying a type of SQL_BLOB on insert in the params OR specifying a type of SQL_BLOB on select in bound columns would return a blob without the utf8 flag on. The script I was running is: use strict; use warnings; use DBI qw(:sql_types); use Data::Dumper; use Encode; my $euro = "\x{20ac}"; my $h = DBI->connect("dbi:SQLite:dbname=test.db", '', '', {RaiseError => 1, # enable the following or you won't get unicode back: sqlite_unicode => 1}); eval { $h->do(q/drop table test1/); }; $h->do(q/create table test1 (a varchar(50), b blob)/); my $s = $h->prepare(q/insert into test1 values(?, ?)/); open(my $ifh, "<:raw", "in.png"); my $png; { local $/ = undef; $png = <$ifh>; } # if you bind as a SQL_BLOB on insert then when you retrieve the blob # it does not come back with utf8 flag on \o/ $s->bind_param(1, $euro); $s->bind_param(2, $png, {TYPE => SQL_BLOB} ); $s->execute; #$s->execute($euro, $png); my ($col1, $col2); $s = $h->prepare(q/select * from test1/); $s->bind_col(1, \$col1); # works: #$s->bind_col(2, \$col2); # returns nothing: $s->bind_col(2, \$col2, SQL_BLOB); # returns nothing: #$s->bind_col(2, \$col2, {TYPE=>SQL_BLOB}); $s->execute; $s->fetch; #print "$col1\n"; # instead of binding if you do the following it works #my $row = $h->selectrow_arrayref(q/select * from test1/); #($col1, $col2) = @{$row->[0]}; ##print Dumper($row); # print "UTF8 flag ", Encode::is_utf8($col1), "\n"; print "UTF8 flag ", Encode::is_utf8($col2), "\n"; #####$s = $h->prepare(q/update test1 set b = ? where a = ?/); #####$s->execute($euro, $png); ##### #####$row = $h->selectrow_arrayref(q/select * from test1/); ######print Dumper($row); ###### #####print "UTF8 flag ", Encode::is_utf8($row->[0]), "\n"; #####print "UTF8 flag ", Encode::is_utf8($row->[1]), "\n"; open(my $ofh, ">:raw", "out.png"); print $ofh $col2; close $ofh; Martin -- Martin J. Evans Wetherby, UK
Download (untitled) / with headers
text/plain 3.6k
Patched in the trunk. Thanks. On Wed Sep 28 23:51:04 2011, MJEVANS wrote: Show quoted text
> Here is the mail I posted to sqlite mailing list. It shows a problem
as Show quoted text
> the code stands in that binding a column as an SQL_BLOB returns
nothing. Show quoted text
> The test code expects to have an in.png. > > Further to the above, I've been experimenting and I also looked at > https://rt.cpan.org/Ticket/Display.html?id=19471 which suggested that > either binding on input as a SQL_BLOB or binding on output as an > SQL_BLOB would not set the utd8 flag. I confirm the former but when > binding a column on a select as SQL_BLOB I get no data back at all: > > Before this test in.png is a valid png file and out.png does not
exist. Show quoted text
> Output is: > > C:>perl sqlite4.pl > UTF8 flag 1 > UTF8 flag > Use of uninitialized value $col2 in print at sqlite4.pl line 65, <
$ifh> Show quoted text
> line 1. > > C:>dir out.png > 27/09/2011 22:44 0 out.png > 1 File(s) 0 bytes > 0 Dir(s) 15,804,985,344 bytes free > > Altering the script to use the bind_col without specifying the type > produces: > > C:>perl sqlite4.pl > UTF8 flag 1 > UTF8 flag > > C:>dir out.png > 27/09/2011 22:46 12,987 out.png > 1 File(s) 12,987 bytes > 0 Dir(s) 15,804,968,960 bytes free > > Also selectall_arrayref with out any bound columns works. > In other words, specifying a type on bind_col seems to result in > returning no data at all. > Some DBDs ignore the TYPE on bind_col (actually, most do) -
DBD::SQLite Show quoted text
> does not appear to be one of those though (based on the above
results). Show quoted text
> > I was experimenting with the idea that specifying a type of SQL_BLOB
on Show quoted text
> insert in the params OR specifying a type of SQL_BLOB on select in
bound Show quoted text
> columns would return a blob without the utf8 flag on. > > The script I was running is: > > use strict; > use warnings; > use DBI qw(:sql_types); > use Data::Dumper; > use Encode; > > my $euro = "\x{20ac}"; > > my $h = DBI->connect("dbi:SQLite:dbname=test.db", '', '', > {RaiseError => 1, > # enable the following or you won't get unicode back: > sqlite_unicode => 1}); > eval { > $h->do(q/drop table test1/); > }; > $h->do(q/create table test1 (a varchar(50), b blob)/); > > my $s = $h->prepare(q/insert into test1 values(?, ?)/); > > open(my $ifh, "<:raw", "in.png"); > my $png; > { > local $/ = undef; > $png = <$ifh>; > } > # if you bind as a SQL_BLOB on insert then when you retrieve the blob > # it does not come back with utf8 flag on \o/ > $s->bind_param(1, $euro); > $s->bind_param(2, $png, > {TYPE => SQL_BLOB} > ); > $s->execute; > #$s->execute($euro, $png); > > my ($col1, $col2); > $s = $h->prepare(q/select * from test1/); > $s->bind_col(1, \$col1); > # works: > #$s->bind_col(2, \$col2); > # returns nothing: > $s->bind_col(2, \$col2, SQL_BLOB); > # returns nothing: > #$s->bind_col(2, \$col2, {TYPE=>SQL_BLOB}); > $s->execute; > $s->fetch; > #print "$col1\n"; > # instead of binding if you do the following it works > #my $row = $h->selectrow_arrayref(q/select * from test1/); > #($col1, $col2) = @{$row->[0]}; > ##print Dumper($row); > # > print "UTF8 flag ", Encode::is_utf8($col1), "\n"; > print "UTF8 flag ", Encode::is_utf8($col2), "\n"; > > #####$s = $h->prepare(q/update test1 set b = ? where a = ?/); > #####$s->execute($euro, $png); > ##### > #####$row = $h->selectrow_arrayref(q/select * from test1/); > ######print Dumper($row); > ###### > #####print "UTF8 flag ", Encode::is_utf8($row->[0]), "\n"; > #####print "UTF8 flag ", Encode::is_utf8($row->[1]), "\n"; > > open(my $ofh, ">:raw", "out.png"); > print $ofh $col2; > close $ofh; > > Martin
Download (untitled) / with headers
text/plain 210b
On Thu Sep 29 11:30:24 2011, ISHIGAKI wrote: Show quoted text
> Patched in the trunk. Thanks.
Just to confirm this issue seems to be fixed in the trunk now. Thank you for a speedy fix. Martin -- Martin J. Evans Wetherby, UK
Closed this ticket as DBD::SQLite 1.34_02 with a fix is out. Thanks.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.