Pg: Set appropriate quote_identifier for $conn->Q()
This commit is contained in:
parent
81a3d3c608
commit
2083ab2a6f
3 changed files with 27 additions and 2 deletions
12
FU.xs
12
FU.xs
|
|
@ -217,6 +217,12 @@ void query_trace(fupg_conn *c, SV *cb)
|
|||
SvGETMAGIC(cb);
|
||||
c->trace = SvOK(cb) ? SvREFCNT_inc(cb) : NULL;
|
||||
|
||||
void conn(fupg_conn *c)
|
||||
CODE:
|
||||
ST(0) = sv_newmortal();
|
||||
sv_setrv_inc(ST(0), c->self);
|
||||
sv_bless(ST(0), gv_stashpv("FU::Pg::conn", 0));
|
||||
|
||||
void status(fupg_conn *c)
|
||||
CODE:
|
||||
ST(0) = sv_2mortal(newSVpv(fupg_conn_status(c), 0));
|
||||
|
|
@ -317,6 +323,12 @@ void cache(fupg_txn *x, ...)
|
|||
CODE:
|
||||
FUPG_STFLAGS;
|
||||
|
||||
void conn(fupg_txn *t)
|
||||
CODE:
|
||||
ST(0) = sv_newmortal();
|
||||
sv_setrv_inc(ST(0), t->conn->self);
|
||||
sv_bless(ST(0), gv_stashpv("FU::Pg::conn", 0));
|
||||
|
||||
void status(fupg_txn *t)
|
||||
CODE:
|
||||
ST(0) = sv_2mortal(newSVpv(fupg_txn_status(t), 0));
|
||||
|
|
|
|||
9
FU/Pg.pm
9
FU/Pg.pm
|
|
@ -10,7 +10,11 @@ package FU::Pg::conn {
|
|||
sub Q {
|
||||
require FU::SQL;
|
||||
my $s = shift;
|
||||
my($sql, $params) = FU::SQL::SQL(@_)->compile(placeholder_style => 'pg', in_style => 'pg');
|
||||
my($sql, $params) = FU::SQL::SQL(@_)->compile(
|
||||
placeholder_style => 'pg',
|
||||
in_style => 'pg',
|
||||
quote_identifier => sub { $s->conn->escape_identifier(@_) },
|
||||
);
|
||||
$s->q($sql, @$params);
|
||||
}
|
||||
|
||||
|
|
@ -208,7 +212,8 @@ used.
|
|||
=item $conn->Q(@args)
|
||||
|
||||
Same as C<< $conn->q() >> but uses L<FU::SQL> to construct the query and bind
|
||||
parameters.
|
||||
parameters. Uses the 'pg' C<in_style> and C<< $conn->escape_identifier() >> for
|
||||
identifier quoting.
|
||||
|
||||
=back
|
||||
|
||||
|
|
|
|||
|
|
@ -127,6 +127,14 @@ subtest 'custom types', sub {
|
|||
};
|
||||
|
||||
|
||||
subtest 'identifier quoting', sub {
|
||||
my $txn = $conn->txn;
|
||||
$txn->exec('CREATE TEMPORARY TABLE fupg_test_tbl ("desc" int, ok int, "hello world" int)');
|
||||
ok $txn->Q('INSERT INTO fupg_test_tbl', VALUES {desc => 5, ok => 10, 'hello world', 15})->exec;
|
||||
is $txn->Q('SELECT', IDENT 'hello world', 'FROM fupg_test_tbl')->val, 15;
|
||||
};
|
||||
|
||||
|
||||
subtest 'vndbid', sub {
|
||||
plan skip_all => 'type not loaded in the database' if !$conn->q("SELECT 1 FROM pg_type WHERE typname = 'vndbtag'")->val;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue