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};
|
||||
|
|
|
|||
|
|
@ -18,6 +18,13 @@ is query_encode
|
|||
{ "\xfe" => [ 1, undef, 3, builtin::false, builtin::true ] },
|
||||
"%c3%be=1&%c3%be=3&%c3%be";
|
||||
|
||||
is_deeply
|
||||
query_decode('a=&a=&b=&c==x&d=x='),
|
||||
{ a => ['', ''], b => '', c => '=x', d => 'x=' };
|
||||
|
||||
is query_encode { a => ['', ''], b => '', c => '=x', d => 'x=' }, 'a=&a=&b=&c=%3dx&d=x%3d';
|
||||
|
||||
|
||||
sub FUTILTEST::TO_QUERY { '&'.($_[0][0] + 1) }
|
||||
|
||||
is query_encode
|
||||
|
|
|
|||
8
t/sql.t
8
t/sql.t
|
|
@ -62,11 +62,11 @@ t VALUES([1, $x, 'NOW()', RAW 'NOW()']), 'VALUES ( ? , ? , ? , NOW() )', [1, $x,
|
|||
t VALUES(P {}), 'VALUES ( ? )', [{}];
|
||||
t VALUES(P []), 'VALUES ( ? )', [[]];
|
||||
|
||||
t IN([1,2,'a',undef,$x]), 'IN(?,?,?,?,?)', [1,2,'a',undef,$x];
|
||||
t IN([1,2,'a',undef,$x]), '= ANY(?)', [[1,2,'a',undef,$x]], in_style => 'pg';
|
||||
t IN([]), '= ANY($1)', [[]], in_style => 'pg', placeholder_style => 'pg';
|
||||
t IN [1,2,'a',undef,$x], 'IN(?,?,?,?,?)', [1,2,'a',undef,$x];
|
||||
t IN [1,2,'a',undef,$x], '= ANY(?)', [[1,2,'a',undef,$x]], in_style => 'pg';
|
||||
t IN [], '= ANY($1)', [[]], in_style => 'pg', placeholder_style => 'pg';
|
||||
|
||||
t WHERE({ id => IN([1,2]) }), 'WHERE ( id IN(?,?) )', [1,2];
|
||||
t WHERE({ id => IN [1,2] }), 'WHERE ( id IN(?,?) )', [1,2];
|
||||
|
||||
sub somefunc { 'not actually const' }
|
||||
t SQL(somefunc), '?', [somefunc];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue