use strict;
BEGIN {
$| = 1;
$^W = 1;
}
use t::lib::Test;
use Test::More tests => 37;
use Test::NoWarnings;
my $dbh = connect_ok( dbfile => 'foo', RaiseError => 1, PrintError => 1, PrintWarn => 1 );
ok( $dbh->do(<<'END_SQL'), 'CREATE TABLE' );
CREATE TABLE one (
id INTEGER NOT NULL,
name CHAR (64)
)
END_SQL
my $quoted = $dbh->quote('test1');
is( $quoted, "'test1'", '->quote(test1) ok' );
ok( $dbh->disconnect, '->disconnect' );
$dbh = connect_ok( dbfile => 'foo' );
ok( $dbh->do('DROP TABLE one'), 'DROP' );
ok( $dbh->do(<<'END_SQL'), 'CREATE TABLE' );
CREATE TABLE one (
id INTEGER NULL,
name CHAR (64) NULL
)
END_SQL
ok( $dbh->do("INSERT INTO one VALUES ( 1, 'A' )"), 'INSERT 1' );
ok( $dbh->do('DELETE FROM one WHERE id = 1'), 'DELETE 1' );
SCOPE: {
my $sth = $dbh->prepare('SELECT * FROM one WHERE id = 1');
isa_ok( $sth, 'DBI::st' );
my ($pe) = $sth->{PrintError};
$sth->{PrintError} = 0;
my $rv = eval {
$sth->fetchrow;
};
$sth->{PrintError} = $pe;
ok( $sth->execute, '->execute' );
my(@row, $ref);
SCOPE: {
local $^W = 0;
is( $sth->fetch, undef, '->fetch returns undef' );
}
ok( $sth->finish, '->finish' );
}
SCOPE: {
my $sth = $dbh->prepare('SELECT * FROM one WHERE id = 1');
isa_ok( $sth, 'DBI::st' );
is( $sth->rows, -1, '->rows is negative' );
ok( $sth->execute, '->execute ok' );
is( $sth->rows, 0, '->rows returns 0' );
ok( $sth->finish, '->finish' );
}
ok( $dbh->do("INSERT INTO one VALUES ( NULL, 'NULL-valued id' )"), 'INSERT 2' );
SCOPE: {
my $sth = $dbh->prepare("SELECT id FROM one WHERE id IS NULL");
isa_ok( $sth, 'DBI::st' );
ok( $sth->execute, '->execute' );
is_deeply(
$sth->fetchall_arrayref,
[ [ undef ] ],
'NULL returned ok',
);
ok( $sth->finish, '->finish' );
}
ok( $dbh->do("DELETE FROM one WHERE id is NULL AND name = 'NULL-valued id'"), 'DELETE' );
ok( $dbh->do("INSERT INTO one VALUES ( 2, NULL )"), 'INSERT 3' );
SCOPE: {
my $sth = $dbh->prepare("SELECT name FROM one WHERE id = 2 AND name IS NULL");
isa_ok( $sth, 'DBI::st' );
ok( $sth->execute, '->execute' );
is_deeply(
$sth->fetchall_arrayref,
[ [ undef ] ],
'->fetchall_arrayref',
);
ok( $sth->finish, '->finish' );
}
ok( $dbh->do('DELETE FROM ONE WHERE id = 2 AND name IS NULL'), 'DELETE' );
SCOPE: {
my $sth = $dbh->prepare("SELECT * FROM one");
isa_ok( $sth, 'DBI::st' );
ok( $sth->execute, 'Execute' );
ok( $sth->execute, 'Reexecute' );
my @row = $sth->fetchrow_array;
ok( $sth->finish, '->finish' );
}
ok( $dbh->do("INSERT INTO one VALUES( 2, 'Gary Shea' )"), 'INSERT 4' );
SCOPE: {
my $sth = $dbh->prepare("UPDATE one SET id = 3 WHERE name = 'Gary Shea'");
isa_ok( $sth, 'DBI::st' );
}