From ab168bd952042a9e2fbd43173b0805204cf57eef Mon Sep 17 00:00:00 2001 From: Yorhel Date: Thu, 24 Apr 2025 07:23:00 +0200 Subject: [PATCH] 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. --- FU.xs | 2 +- t/pgconnect.t | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/FU.xs b/FU.xs index ef8d60b..221740b 100644 --- a/FU.xs +++ b/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: diff --git a/t/pgconnect.t b/t/pgconnect.t index d2dfbf5..798734c 100644 --- a/t/pgconnect.t +++ b/t/pgconnect.t @@ -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 }