Author: turnstep
Date: Tue Apr 22 18:25:29 2008
New Revision: 11137
Modified:
DBD-Pg/trunk/t/12placeholders.t
Log:
Clean up and standardize the tests.
Modified: DBD-Pg/trunk/t/12placeholders.t
==============================================================================
--- DBD-Pg/trunk/t/12placeholders.t (original)
+++ DBD-Pg/trunk/t/12placeholders.t Tue Apr 22 18:25:29 2008
@@ -10,14 +10,14 @@
select(($|=1,select(STDERR),$|=1)[1]);
my $dbh = connect_database();
-my $t;
if (! defined $dbh) {
plan skip_all => 'Connection to database failed, cannot continue
testing';
}
plan tests => 27;
-isnt( $dbh, undef, 'Connect to database for placeholder testing');
+my $t=q{Connect to database for placeholder testing};
+isnt( $dbh, undef, $t);
my ($pglibversion,$pgversion) =
($dbh->{pg_lib_version},$dbh->{pg_server_version});
if ($pgversion >= 80100) {
@@ -25,15 +25,17 @@
}
# Make sure that quoting works properly.
+$t=q{Quoting works properly};
my $quo = $dbh->quote('\\\'?:');
-is( $quo, q{'\\\\''?:'}, 'Properly quoted');
+is( $quo, q{'\\\\''?:'}, $t);
+$t=q{Quoting works with a function call};
# Make sure that quoting works with a function call.
# It has to be in this function, otherwise it doesn't fail the
# way described in https://rt.cpan.org/Ticket/Display.html?id=4996.
sub checkquote {
my $str = shift;
- return is( $dbh->quote(substr($str, 0, 10)), "'$str'", 'First function
quote');
+ return is( $dbh->quote(substr($str, 0, 10)), "'$str'", $t);
}
checkquote('one');
@@ -48,71 +50,77 @@
$sth = $dbh->prepare($sql);
$sth->execute();
+$t=q{Fetch returns the correct quoted value};
my ($retr) = $sth->fetchrow_array();
-ok( (defined($retr) && $retr eq '\\\'?:'), 'fetch');
+is( $retr, '\\\'?:', $t);
+$t=q{Execute with one bind param where none expected fails};
eval {
$sth = $dbh->prepare($sql);
$sth->execute('foo');
};
-isnt( $@, q{}, 'execute with one bind param where none expected fails');
+like( $@, qr{when 0 are needed}, $t);
$sql = 'SELECT pname FROM dbd_pg_test WHERE pname = ?';
$sth = $dbh->prepare($sql);
$sth->execute('\\\'?:');
+$t=q{Execute with ? placeholder works};
($retr) = $sth->fetchrow_array();
-ok( (defined($retr) && $retr eq '\\\'?:'), 'execute with ? placeholder');
+is( $retr, '\\\'?:', $t);
$sql = 'SELECT pname FROM dbd_pg_test WHERE pname = :1';
$sth = $dbh->prepare($sql);
$sth->bind_param(':1', '\\\'?:');
$sth->execute();
+$t=q{Execute with :1 placeholder works};
($retr) = $sth->fetchrow_array();
-ok( (defined($retr) && $retr eq '\\\'?:'), 'execute with :1 placeholder');
+is( $retr, '\\\'?:', $t);
$sql = q{SELECT pname FROM dbd_pg_test WHERE pname = $1 AND pname <> 'foo'};
$sth = $dbh->prepare($sql);
$sth->execute('\\\'?:');
+$t=q{Execute with $1 placeholder works};
($retr) = $sth->fetchrow_array();
-ok( (defined($retr) && $retr eq '\\\'?:'), 'execute with $1 placeholder');
+is( $retr, '\\\'?:', $t);
$sql = q{SELECT pname FROM dbd_pg_test WHERE pname = '?'};
+$t=q{Execute with quoted ? fails with a placeholder};
eval {
$sth = $dbh->prepare($sql);
$sth->execute('foo');
};
-isnt( $@, q{}, 'execute with quoted ?');
+like( $@, qr{when 0 are needed}, $t);
$sql = q{SELECT pname FROM dbd_pg_test WHERE pname = ':1'};
+$t=q{Execute with quoted :1 fails with a placeholder};
eval {
$sth = $dbh->prepare($sql);
$sth->execute('foo');
};
-isnt( $@, q{}, 'execute with quoted :1');
+like( $@, qr{when 0 are needed}, $t);
$sql = q{SELECT pname FROM dbd_pg_test WHERE pname = '\\\\' AND pname = '?'};
-$sth = $dbh->prepare($sql);
+$t=q{Execute with quoted ? fails with a placeholder};
eval {
-## XX ???
- local $dbh->{PrintError} = 0;
- local $sth->{PrintError} = 0;
+ $sth = $dbh->prepare($sql);
$sth->execute('foo');
};
-isnt( $@, q{}, 'execute with quoted ?');
+like( $@, qr{when 0 are needed}, $t);
+$t=q{Prepare with large number of parameters works};
## Test large number of placeholders
$sql = 'SELECT 1 FROM dbd_pg_test WHERE id IN (' . '?,' x 300 . '?)';
my @args = map { $_ } (1..301);
$sth = $dbh->prepare($sql);
my $count = $sth->execute(@args);
$sth->finish();
-cmp_ok( $count, '>=', 1, 'prepare with large number of parameters works');
+is( $count, 1, $t);
$sth->finish();
@@ -122,64 +130,68 @@
$dbh->do(q{SET NAMES 'UTF8'});
}
-## Test our parsing of backslashes
+$t=q{Prepare with backslashes inside quotes works};
$sth = $dbh->prepare(q{SELECT '\\'?'});
eval {
$sth->execute();
};
-is( $@, q{}, 'prepare with backslashes inside quotes works');
+is( $@, q{}, $t);
$sth->finish();
$dbh->commit();
-## Test do() with placeholders, both DML and non-DML
+$t=q{Calling do() with non-DML placeholder works};
eval {
$dbh->do(q{SET search_path TO ?}, undef, 'public');
};
-is( $@, q{}, 'do() called with non-DML placeholder works');
+is( $@, q{}, $t);
$dbh->commit();
+$t=q{Calling do() with DML placeholder works};
eval {
$dbh->do(q{SELECT ?::text}, undef, 'public');
};
-is( $@, q{}, 'do() called with non-DML placeholder works');
+is( $@, q{}, $t);
$dbh->commit();
-## Test a non-DML placeholder
+$t=q{Prepare/execute with non-DML placehlder works};
eval {
$sth = $dbh->prepare(q{SET search_path TO ?});
$sth->execute('public');
};
-is( $@, q{}, 'prepare/execute with non-DML placeholder works');
+is( $@, q{}, $t);
$dbh->commit();
-
-## Make sure we can allow geometric and other placeholders
+$t=q{Prepare/execute does not allow geometric operators};
eval {
$sth = $dbh->prepare(q{SELECT ?- lseg '(1,0),(1,1)'});
$sth->execute();
};
-like( $@, qr{unbound placeholder}, q{prepare/execute does not allows geometric
operators});
+like( $@, qr{unbound placeholder}, $t);
$dbh->commit();
+$t=q{Prepare/execute allows geometric operator ?- when dollaronly is set};
$dbh->{pg_placeholder_dollaronly} = 1;
eval {
$sth = $dbh->prepare(q{SELECT ?- lseg '(1,0),(1,1)'});
$sth->execute();
$sth->finish();
};
-is( $@, q{}, q{prepare/execute allows geometric operator ?- when dollaronly
set});
+is( $@, q{}, $t);
$dbh->commit();
+
+$t=q{Prepare/execute allows geometric operator ?# when dollaronly set};
eval {
$sth = $dbh->prepare(q{SELECT lseg'(1,0),(1,1)' ?# lseg '(2,3),(4,5)'});
$sth->execute();
$sth->finish();
};
-is( $@, q{}, q{prepare/execute allows geometric operator ?# when dollaronly
set});
+is( $@, q{}, $t);
-is( $dbh->{pg_placeholder_dollaronly}, 1, q{Value of placeholder_dollaronly
can be retrieved});
+$t=q{Value of placeholder_dollaronly can be retrieved};
+is( $dbh->{pg_placeholder_dollaronly}, 1, $t);
-$t=q{prepare/execute does not allow use of raw ? and :foo forms};
+$t=q{Prepare/execute does not allow use of raw ? and :foo forms};
$dbh->{pg_placeholder_dollaronly} = 0;
eval {
$sth = $dbh->prepare(q{SELECT uno ?: dos ? tres :foo bar $1});
@@ -188,6 +200,7 @@
};
like( $@, qr{mix placeholder}, $t);
+$t=q{Prepare/execute allows use of raw ? and :foo forms when dollaronly set};
$dbh->{pg_placeholder_dollaronly} = 1;
eval {
$sth = $dbh->prepare(q{SELECT uno ?: dos ? tres :foo bar $1},
{pg_placeholder_dollaronly => 1});
@@ -195,22 +208,23 @@
$sth->execute();
$sth->finish();
};
-like( $@, qr{unbound placeholder}, q{prepare/execute allows use of raw ? and
:foo forms when dollaronly set});
+like( $@, qr{unbound placeholder}, $t);
+$t=q{Prepare works with pg_placeholder_dollaronly};
$dbh->{pg_placeholder_dollaronly} = 0;
eval {
$sth = $dbh->prepare(q{SELECT uno ?: dos ? tres :foo bar $1},
{pg_placeholder_dollaronly => 1});
$sth->execute();
$sth->finish();
};
-like( $@, qr{unbound placeholder}, q{pg_placeholder_dollaronly can be called
as part of prepare()});
+like( $@, qr{unbound placeholder}, $t);
-$t=q{prepare works with identical named placeholders};
+$t=q{Prepare works with identical named placeholders};
eval {
$sth = $dbh->prepare(q{SELECT :row, :row, :row, :yourboat});
$sth->finish();
};
-is($@, q{}, $t);
+is( $@, q{}, $t);
$dbh->rollback();