Pg: Add escape_literal() and escape_identifier()

Didn't expect I'd ever need these, but they're useful for generating SQL
scripts.
This commit is contained in:
Yorhel 2025-04-07 13:45:24 +02:00
parent 3bf98e4d8f
commit b3281924d1
4 changed files with 41 additions and 0 deletions

18
FU.xs
View file

@ -216,6 +216,24 @@ void status(fupg_conn *c)
CODE:
ST(0) = sv_2mortal(newSVpv(fupg_conn_status(c), 0));
void escape_literal(fupg_conn *c, SV *v)
CODE:
STRLEN len;
const char *str = SvPVutf8(v, len);
char *r = PQescapeLiteral(c->conn, str, len);
if (!r) fupg_conn_croak(c, "escapeLiteral");
ST(0) = newSVpvn_flags(r, strlen(r), SVf_UTF8|SVs_TEMP);
PQfreemem(r);
void escape_identifier(fupg_conn *c, SV *v)
CODE:
STRLEN len;
const char *str = SvPVutf8(v, len);
char *r = PQescapeIdentifier(c->conn, str, len);
if (!r) fupg_conn_croak(c, "escapeIdentifier");
ST(0) = newSVpvn_flags(r, strlen(r), SVf_UTF8|SVs_TEMP);
PQfreemem(r);
void cache(fupg_conn *x, ...)
ALIAS:
FU::Pg::conn::text_params = FUPG_TEXT_PARAMS