rt_29629_sqlite_where_length.t [plain text]
use strict;
BEGIN {
$| = 1;
$^W = 1;
}
use t::lib::Test;
use Test::More tests => 17;
use Test::NoWarnings;
use DBI qw(:sql_types);
my $dbh = connect_ok();
$dbh->do('drop table if exists artist');
$dbh->do(<<'END_SQL');
create table artist (
id int not null primary key,
name text not null
)
END_SQL
ok( $dbh->do(q/insert into artist (id,name) values(1, 'Leonardo da Vinci')/), 'insert');
my $sth = $dbh->prepare('select length(name) from artist where id=?');
ok( $sth->execute(1), 'execute, select length' );
is( $sth->fetchrow_arrayref->[0], 17, 'select length result' );
my $statement = 'select count(*) from artist where length(name) > ?';
$sth = $dbh->prepare($statement);
ok( $sth->execute(2), "execute: $statement : [2]" );
TODO: {
local $TODO = 'This test is currently broken again. Wait for a better fix, or use known workarounds.';
is( $sth->fetchrow_arrayref->[0], 1, "result of: $statement : [2]" );
}
$statement =~ s/\?/2/;
$sth = $dbh->prepare($statement);
ok( $sth->execute, "execute: $statement" );
is( $sth->fetchrow_arrayref->[0], 1, "result of: $statement" );
$statement =~ s/2/1/;
$sth = $dbh->prepare($statement);
ok( $sth->execute, "execute: $statement" );
is( $sth->fetchrow_arrayref->[0], 1, "result of: $statement" );
$statement =~ s/1/?/;
$sth = $dbh->prepare($statement);
ok( $sth->execute(1), "execute: $statement : [1]" );
TODO: {
local $TODO = 'This test is currently broken again. Wait for a better fix, or use known workarounds.';
is( $sth->fetchrow_arrayref->[0], 1, "result of: $statement [1]" );
}
$sth = $dbh->prepare($statement);
$sth->bind_param(1, 2, { TYPE => SQL_INTEGER });
ok( $sth->execute, "execute: $statement : [2]" );
is( $sth->fetchrow_arrayref->[0], 1, "result of: $statement : [2]" );
$statement =~ s/\?/\?\+0/;
$sth = $dbh->prepare($statement);
ok( $sth->execute(2), "execute: $statement : [2]" );
is( $sth->fetchrow_arrayref->[0], 1, "result of: $statement : [2]" );