Pg: Don't return self on / cache() or text_*() methods
This is much too easy of a footgun: $db->cache->q(...); Enabled cache on the $db object, not just for the given query.
This commit is contained in:
parent
13271fa413
commit
ab168bd952
2 changed files with 7 additions and 3 deletions
2
FU.xs
2
FU.xs
|
|
@ -55,7 +55,6 @@
|
|||
if (!ix) ix = FUPG_CACHE;\
|
||||
if (items == 1 || SvTRUE(ST(1))) x->stflags |= ix; \
|
||||
else x->stflags &= ~ix; \
|
||||
XSRETURN(1); \
|
||||
} while(0)
|
||||
|
||||
MODULE = FU
|
||||
|
|
@ -343,6 +342,7 @@ void cache(fupg_st *x, ...)
|
|||
CODE:
|
||||
if (ix == 0 && x->prepared) fu_confess("Invalid attempt to change statement configuration after it has already been prepared or executed");
|
||||
FUPG_STFLAGS;
|
||||
XSRETURN(1);
|
||||
|
||||
void exec(fupg_st *st)
|
||||
CODE:
|
||||
|
|
|
|||
|
|
@ -17,7 +17,9 @@ okerr FATAL => connect => qr/missing "=" after "invalid"/;
|
|||
|
||||
ok FU::Pg::lib_version() > 100000;
|
||||
|
||||
my $conn = FU::Pg->connect($ENV{FU_TEST_DB})->text->cache(0);
|
||||
my $conn = FU::Pg->connect($ENV{FU_TEST_DB});
|
||||
$conn->text;
|
||||
$conn->cache(0);
|
||||
$conn->_debug_trace(0);
|
||||
|
||||
is ref $conn, 'FU::Pg::conn';
|
||||
|
|
@ -364,7 +366,9 @@ subtest 'txn', sub {
|
|||
}
|
||||
|
||||
subtest 'Prepared statement cache', sub {
|
||||
my $txn = $conn->cache_size(2)->txn->cache;
|
||||
$conn->cache_size(2);
|
||||
my $txn = $conn->txn;
|
||||
$txn->cache;
|
||||
my sub numexec($sql) {
|
||||
$txn->q('SELECT generic_plans + custom_plans FROM pg_prepared_statements WHERE statement = $1', $sql)->cache(0)->val
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue