Pg: Add escape_literal() and escape_identifier()

Didn't expect I'd ever need these, but they're useful for generating SQL
scripts.
This commit is contained in:
Yorhel 2025-04-07 13:45:24 +02:00
parent 3bf98e4d8f
commit b3281924d1
4 changed files with 41 additions and 0 deletions

View file

@ -353,6 +353,16 @@ subtest 'txn', sub {
is_deeply $st->val, [1,3], 'not deep copy';
}
{
# Exact format returned by escape_literal() can differ between Postgres versions and configurations.
my $x = q{"' \" \\};
is $conn->q('SELECT '.$conn->escape_literal($x))->val, $x;
# Format can also change, but unsure how to test this otherwise.
is $conn->escape_identifier('hel\l"o'), '"hel\l""o"';
}
subtest 'Prepared statement cache', sub {
my $txn = $conn->cache_size(2)->txn->cache;
my sub numexec($sql) {