DBD-PgAsync
view release on metacpan or search on metacpan
t/12placeholders.t view on Meta::CPAN
like ($@, qr{relation ".*" does not exist}, $t);
}
$dbh->rollback();
SKIP: {
skip 'Cannot adjust standard_conforming_strings for testing on this version of Postgres', 4 if $pgversion < 80200;
$t='Backslash quoting inside single quotes is parsed correctly with standard_conforming_strings off';
$dbh->do(q{SET standard_conforming_strings = 'off'});
eval {
local $dbh->{Warn} = '';
$sth = $dbh->prepare(q{SELECT '\', ?});
$sth->execute();
$sth->finish();
};
like ($@, qr{unterminated quoted string}, $t);
$dbh->rollback();
$t=q{Backslash quoting inside E'' is parsed correctly with standard_conforming_strings = 'off'};
eval {
$sth = $dbh->prepare(q{SELECT E'\'?'});
$sth->execute();
$sth->finish;
};
is ($@, q{}, $t);
$dbh->rollback();
$t='Backslash quoting inside single quotes is parsed correctly with standard_conforming_strings on';
eval {
$dbh->do(q{SET standard_conforming_strings = 'on'});
$sth = $dbh->prepare(q{SELECT '\', ?::int});
$sth->execute(1);
$sth->finish();
};
is ($@, q{}, $t);
$t=q{Backslash quoting inside E'' is parsed correctly with standard_conforming_strings = 'on'};
eval {
$sth = $dbh->prepare(q{SELECT E'\'?'});
$sth->execute();
$sth->finish;
};
is ($@, q{}, $t);
}
$t='Valid integer works when quoting with SQL_INTEGER';
my $val;
$val = $dbh->quote('123', SQL_INTEGER);
is ($val, 123, $t);
$t='Invalid integer fails to pass through when quoting with SQL_INTEGER';
$val = -1;
eval {
$val = $dbh->quote('123abc', SQL_INTEGER);
};
like ($@, qr{Invalid integer}, $t);
is ($val, -1, $t);
my $prefix = 'Valid float value works when quoting with SQL_FLOAT';
for my $float ('123','0.00','0.234','23.31562', '1.23e04','6.54e+02','4e-3','NaN','Infinity','-infinity') {
$t = "$prefix (value=$float)";
$val = -1;
eval { $val = $dbh->quote($float, SQL_FLOAT); };
is ($@, q{}, $t);
is ($val, $float, $t);
next unless $float =~ /\w/;
my $lcfloat = lc $float;
$t = "$prefix (value=$lcfloat)";
$val = -1;
eval { $val = $dbh->quote($lcfloat, SQL_FLOAT); };
is ($@, q{}, $t);
is ($val, $lcfloat, $t);
my $ucfloat = uc $float;
$t = "$prefix (value=$ucfloat)";
$val = -1;
eval { $val = $dbh->quote($ucfloat, SQL_FLOAT); };
is ($@, q{}, $t);
is ($val, $ucfloat, $t);
}
$prefix = 'Invalid float value fails when quoting with SQL_FLOAT';
for my $float ('3abc','123abc','','NaNum','-infinitee') {
$t = "$prefix (value=$float)";
$val = -1;
eval { $val = $dbh->quote($float, SQL_FLOAT); };
like ($@, qr{Invalid float}, $t);
is ($val, -1, $t);
}
$dbh->rollback();
## Test placeholders plus binding
$t='Bound placeholders enforce data types when not using server side prepares';
$dbh->trace(0);
$dbh->{pg_server_prepare} = 0;
$sth = $dbh->prepare('SELECT (1+?+?)::integer');
$sth->bind_param(1, 1, SQL_INTEGER);
eval {
$sth->execute('10foo',20);
};
like ($@, qr{Invalid integer}, 'Invalid integer test 2');
## Test quoting of the "name" type
$prefix = q{The 'name' data type does correct quoting};
for my $word (qw/User user USER trigger Trigger user-user/) {
$t = qq{$prefix for the word "$word"};
my $got = $dbh->quote($word, { pg_type => PG_NAME });
$expected = qq{"$word"};
is ($got, $expected, $t);
}
for my $word (qw/auser userz/) {
$t = qq{$prefix for the word "$word"};
my $got = $dbh->quote($word, { pg_type => PG_NAME });
$expected = qq{$word};
is ($got, $expected, $t);
}
## Test quoting of booleans
my %booltest = ( ## no critic (Lax::ProhibitLeadingZeros::ExceptChmod, ValuesAndExpressions::ProhibitLeadingZeros, ValuesAndExpressions::ProhibitDuplicateHashKeys)
undef => 'NULL',
't' => 'TRUE',
'T' => 'TRUE',
'true' => 'TRUE',
'TRUE' => 'TRUE',
1 => 'TRUE',
'01' => 'TRUE',
'1' => 'TRUE',
'0E0' => 'TRUE',
'0e0' => 'TRUE',
'0 but true' => 'TRUE',
'0 BUT TRUE' => 'TRUE',
'real true' => 'TRUE',
'f' => 'FALSE',
'F' => 'FALSE',
0 => 'FALSE',
00 => 'FALSE',
'0' => 'FALSE',
'false' => 'FALSE',
'FALSE' => 'FALSE',
( run in 1.304 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )