diff options
Diffstat (limited to 'install/5.005/DBD-Pg-1.22-fixvercmp/t/11quoting.t')
-rw-r--r-- | install/5.005/DBD-Pg-1.22-fixvercmp/t/11quoting.t | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/install/5.005/DBD-Pg-1.22-fixvercmp/t/11quoting.t b/install/5.005/DBD-Pg-1.22-fixvercmp/t/11quoting.t new file mode 100644 index 000000000..afec9632a --- /dev/null +++ b/install/5.005/DBD-Pg-1.22-fixvercmp/t/11quoting.t @@ -0,0 +1,50 @@ +use strict; +use DBI; +use Test::More; + +if (defined $ENV{DBI_DSN}) { + plan tests => 8; +} else { + plan skip_all => 'cannot test without DB info'; +} + +my $dbh = DBI->connect($ENV{DBI_DSN}, $ENV{DBI_USER}, $ENV{DBI_PASS}, + {RaiseError => 1, AutoCommit => 0} + ); +ok(defined $dbh, + 'connect with transaction' + ); + +my %tests = ( + one=>["'", "'\\" . sprintf("%03o", ord("'")) . "'"], + two=>["''", "'" . ("\\" . sprintf("%03o", ord("'")))x2 . "'"], + three=>["\\", "'\\" . sprintf("%03o", ord("\\")) . "'"], + four=>["\\'", sprintf("'\\%03o\\%03o'", ord("\\"), ord("'"))], + five=>["\\'?:", sprintf("'\\%03o\\%03o?:'", ord("\\"), ord("'"))], + ); + +foreach my $test (keys %tests) { + my ($unq, $quo, $ref); + + $unq = $tests{$test}->[0]; + $ref = $tests{$test}->[1]; + $quo = $dbh->quote($unq); + + ok($quo eq $ref, + "$test: $unq -> expected $quo got $ref" + ); +} + +# Make sure that SQL_BINARY doesn't work. +# eval { $dbh->quote('foo', { TYPE => DBI::SQL_BINARY })}; +eval { + local $dbh->{PrintError} = 0; + $dbh->quote('foo', DBI::SQL_BINARY); +}; +ok($@ && $@ =~ /Use of SQL_BINARY invalid in quote/, + 'SQL_BINARY' +); + +ok($dbh->disconnect(), + 'disconnect' + ); |