1
0
Fork 0
mirror of https://github.com/DBD-SQLite/DBD-SQLite synced 2025-06-07 14:19:10 -04:00

fix RT#96877 ...

but this breakx some previous tests which made incorrect assumptions about utf8 in statements :-(
This commit is contained in:
Laurent Dami 2014-07-04 10:53:33 +02:00
parent 65f69154bd
commit 6c57a3e2aa
2 changed files with 43 additions and 0 deletions

View file

@ -196,6 +196,9 @@ sub prepare {
my $sql = shift;
$sql = '' unless defined $sql;
# sqlite3_prepare wants an utf8-encoded SQL statement
utf8::upgrade($sql);
my $sth = DBI::_new_sth( $dbh, {
Statement => $sql,
} );

View file

@ -0,0 +1,40 @@
#!/usr/bin/perl
# According to the sqlite doc, the SQL argument to sqlite3_prepare_v2
# should be in utf8, but DBD::SQLite does not ensure this (even with
# sqlite_unicode => 1). Only bind values are properly converted.
use strict;
BEGIN {
$| = 1;
$^W = 1;
}
use t::lib::Test;
use Test::More;
BEGIN {
if ( $] >= 5.008005 ) {
plan( tests => 16 );
} else {
plan( skip_all => 'Unicode is not supported before 5.8.5' );
}
}
use Test::NoWarnings;
my $dbh = connect_ok( sqlite_unicode => 1 );
is( $dbh->{sqlite_unicode}, 1, 'Unicode is on' );
ok( $dbh->do(<<'END_SQL'), 'CREATE TABLE' );
CREATE TABLE foo (
bar varchar(255)
)
END_SQL
foreach ( "A", "\xe9", "\x{20ac}" ) {
diag sprintf "testing \\x{%x}", ord($_);
ok( $dbh->do("INSERT INTO foo VALUES ( ? )", {}, $_), 'INSERT with bind' );
ok( $dbh->do("INSERT INTO foo VALUES ( '$_' )"), 'INSERT without bind' );
my $vals = $dbh->selectcol_arrayref("SELECT bar FROM foo");
is $vals->[0], $vals->[1], "both values are equal";
ok( $dbh->do("DELETE FROM foo"), 'DELETE ok' );
}