pg: Support binary bind params

This commit is contained in:
Yorhel 2025-02-08 10:35:43 +01:00
parent 166744dd51
commit 30b457d2b8
6 changed files with 226 additions and 78 deletions

View file

@ -66,10 +66,10 @@ subtest '$st prepare & exec', sub {
is $conn->exec('SELECT 1 FROM pg_prepared_statements'), 0;
ok !eval { $conn->q('SELECT 1', 1)->exec; 1 };
okerr ERROR => exec => qr/bind message supplies 1 parameters, but prepared statement/;
like $@, qr/Statement expects 0 bind parameters but 1 were given/;
ok !eval { $conn->q('SELECT $1')->exec; 1 };
okerr ERROR => exec => qr/bind message supplies 0 parameters, but prepared statement/;
like $@, qr/Statement expects 1 bind parameters but 0 were given/;
# prepare + describe won't let us detect empty queries, hmm...
is_deeply $conn->q('')->params, [];
@ -107,7 +107,9 @@ subtest '$st->rowl', sub {
is scalar $conn->q('SELECT')->rowl, 0;
is scalar $conn->q('SELECT 1, 2')->rowl, 2;
is_deeply [$conn->q('SELECT')->rowl], [];
is_deeply [$conn->q('SELECT 1, 2')->rowl], [1, 2];
is_deeply [$conn->q('SELECT 1, null')->rowl], [1, undef];
is_deeply [$conn->q('SELECT 1, $1', undef)->rowl], [1, undef];
is_deeply [$conn->q('SELECT 1, $1::int', undef)->text_params(0)->rowl], [1, undef];
};
subtest '$st->rowa', sub {
@ -120,6 +122,9 @@ subtest '$st->rowa', sub {
ok !eval { $conn->q('SELEXT')->rowa; 1; };
is_deeply $conn->q('SELECT')->rowa, [];
is_deeply $conn->q('SELECT 1, 2')->rowa, [1, 2];
is_deeply $conn->q('SELECT 1, null')->rowa, [1, undef];
is_deeply $conn->q('SELECT 1, $1', undef)->rowa, [1, undef];
is_deeply $conn->q('SELECT 1, $1::int', undef)->text_params(0)->rowa, [1, undef];
};
subtest '$st->rowh', sub {
@ -135,6 +140,8 @@ subtest '$st->rowh', sub {
ok !eval { $conn->q('SELEXT')->rowh; 1; };
is_deeply $conn->q('SELECT')->rowh, {};
is_deeply $conn->q('SELECT 1 as a, 2 as b')->rowh, {a => 1, b => 2};
is_deeply $conn->q('SELECT 1 as a, null as b')->rowh, {a => 1, b => undef};
is_deeply $conn->q('SELECT 1 as a, $1::int as b', undef)->rowh, {a => 1, b => undef};
};
subtest 'txn', sub {