Add fu->redirect, change $st->row behavior on 0 results, minor fixes
And with this, I have a working rewrite of the manned.org backend into FU. \o/ The $st->row methods are very useful even for queries that may not return anything, so their old behavior was unhelpful. Interestingly enough, the error-on-multiple-rows did catch an actual bug in Manned.org, so I'm keeping that behavior.
This commit is contained in:
parent
fbbaa23842
commit
06e2f950fe
9 changed files with 62 additions and 34 deletions
|
|
@ -117,9 +117,6 @@ subtest '$st->val', sub {
|
|||
};
|
||||
|
||||
subtest '$st->rowl', sub {
|
||||
ok !eval { $conn->q('SELECT 1 WHERE false')->rowl; 1 };
|
||||
like $@, qr/on query returning zero rows/;
|
||||
|
||||
ok !eval { $conn->q('SELECT 1 UNION SELECT 2')->rowl; 1 };
|
||||
like $@, qr/on query returning more than one row/;
|
||||
|
||||
|
|
@ -130,34 +127,31 @@ subtest '$st->rowl', sub {
|
|||
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];
|
||||
is_deeply [$conn->q('SELECT 1 WHERE false')->rowl], [];
|
||||
};
|
||||
|
||||
subtest '$st->rowa', sub {
|
||||
ok !eval { $conn->q('SELECT 1 WHERE false')->rowa; 1 };
|
||||
like $@, qr/on query returning zero rows/;
|
||||
|
||||
ok !eval { $conn->q('SELECT 1 UNION SELECT 2')->rowa; 1 };
|
||||
like $@, qr/on query returning more than one row/;
|
||||
|
||||
ok !eval { $conn->q('SELEXT')->rowa; 1; };
|
||||
is $conn->q('SELECT 1 WHERE false')->rowa, undef;
|
||||
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 {
|
||||
ok !eval { $conn->q('SELECT 1 WHERE false')->rowh; 1 };
|
||||
like $@, qr/on query returning zero rows/;
|
||||
|
||||
ok !eval { $conn->q('SELECT 1 UNION SELECT 2')->rowh; 1 };
|
||||
like $@, qr/on query returning more than one row/;
|
||||
|
||||
ok !eval { $conn->q('SELECT 1 as a, 2 as a')->rowh; 1 };
|
||||
like $@, qr/Query returns multiple columns with the same name/;
|
||||
|
||||
ok !eval { $conn->q('SELEXT')->rowh; 1; };
|
||||
is $conn->q('SELECT 1 WHERE false')->rowh, undef;
|
||||
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};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue