Skip Menu |
 

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

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

People
Owner: Nobody in particular
Requestors: david [...] kineticode.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in:
  • 0.05
  • 0.06
  • 0.07
  • 0.08
  • 0.09
  • 0.10
  • 0.11
  • 0.12
  • 0.13
  • 0.14
  • 0.15
  • 0.16
  • 0.17
  • 0.18
  • 0.19
  • 0.20
  • 0.21
  • 0.22
  • 0.23
  • 0.24
  • 0.25
  • 0.26
  • 0.27
  • 0.28
  • 0.29
  • 0.30
  • 0.31
  • 1.00
  • 1.01
  • 1.02
  • 1.03
  • 1.04
  • 1.05
  • 1.06
  • 1.07
  • 1.08
  • 1.09
  • 1.10
  • 1.11
  • 1.12
Fixed in: (no value)



Subject: utf8 Flag on For BLOB Data
Date: Wed, 24 May 2006 16:29:56 -0700
To: bug-dbd-sqlite [...] rt.cpan.org
From: David Wheeler <david [...] kineticode.com>
Download (untitled) / with headers
text/plain 2.6k
Matt, In testing BLOB support in DBD::SQLite, I took note of these comments in the documentation: Show quoted text
> Also note that due to some bizareness in SQLite's type > system (see > http://www.sqlite.org/datatype3.html), if you want to > retain blob- > style behavior for some columns under "$dbh->{unicode} = > 1" (say, > to store images in the database), you have to state so > explicitely > using the 3-argument form of "bind_param" in DBI when doing > updates: > > use DBI qw(:sql_types); > $dbh->{unicode} = 1; > my $sth = $dbh->prepare > ("INSERT INTO mytable (blobcolumn) VALUES (?)"); > $sth->bind_param(1, $binary_data, SQL_BLOB); # > binary_data will > # be stored as-is. > > Defining the column type as BLOB in the DDL is not > sufficient.
That's great for getting data into the database, but not for getting it out. This script demonstrates the problem: When unicode => 1 is enabled (and shouldn't that be sqlite_unicode to be compatible with DBI's naming conventions?), BLOB data has the utf8 flag switched on, even if I tell SQLite that the data is binary. This script demonstrates the issue: It should output "utf8: no" but outputs "utf8: yes". #!/usr/local/bin/perl -w use strict; use DBI qw(:sql_types); use File::Basename; use Encode qw(is_utf8); my $filename = shift or die "Usage: $0 filename\n"; my $dbh = DBI->connect( 'dbi:SQLite:dbname=try.db', '', '', { RaiseError => 1, PrintError => 0, unicode => 1 }, ); END { $dbh->disconnect; unlink 'try.db'; } $dbh->do(q{ CREATE TABLE bin ( id integer primary key autoincrement, content blob, filename text ) }); my $ins = $dbh->prepare(q{ INSERT INTO bin (content, filename) values (?, ?) }); open my $fh, '<:bytes', $filename or die "Cannot open '$filename': $!\n"; my $content = do { local $/; <$fh> }; close $fh or die "Cannot close '$filename': $!\n"; $filename = basename($filename); $ins->bind_param(1, $content, { TYPE => SQL_BLOB }); $ins->execute($content, $filename); my $sel = $dbh->prepare(q{ SELECT content, filename FROM bin }); $sel->execute; my ($cont, $fn); $sel->bind_col(1, \$cont, { TYPE => SQL_BLOB }); $sel->bind_col(2, \$fn); #$sel->bind_columns(\($cont, $fn)); while ($sel->fetch) { print 'utf8: ', is_utf8($cont) ? "yes\n" : "no\n"; # open my $out, '>:bytes', $fn # or die "Cannot open '$fn': $!\n"; # print $out $cont; # close $out or die "Cannot close '$fn': $!\n"; }
Download (untitled) / with headers
text/plain 105b
Sending the previous mail has failed. Please contact your admin, they can find more details in the logs.
Download (untitled) / with headers
text/plain 148b
OK, I think I've got this licked now. The problem was that DBI ignores the params on bind_col in the default implementation. Will be fixed in 1.13
Subject: Re: [rt.cpan.org #19471] utf8 Flag on For BLOB Data
Date: Thu, 7 Sep 2006 12:14:50 -0700
To: bug-DBD-SQLite [...] rt.cpan.org
From: "David E. Wheeler" <david [...] kineticode.com>
Download (untitled) / with headers
text/plain 245b
On Sep 7, 2006, at 11:56, via RT wrote: Show quoted text
> OK, I think I've got this licked now. The problem was that DBI > ignores the params on bind_col in > the default implementation.
Ah, so is this a bug in the DBI that should be fixed? Cheers, David
Download (untitled) / with headers
text/plain 260b
On Thu Sep 07 15:15:16 2006, david@kineticode.com wrote: Show quoted text
> Ah, so is this a bug in the DBI that should be fixed?
Not really. It's just optional to do stuff with the attributes passed to bind_col. (please only reply if you intend to re-open the bug, 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.