pg: Module rename + more docs

This commit is contained in:
Yorhel 2025-02-11 10:54:01 +01:00
parent ccc2f1dbf0
commit 33fe0d98a8
7 changed files with 186 additions and 101 deletions

View file

@ -37,7 +37,7 @@ static SV *fupg_conn_errsv(PGconn *conn, const char *action) {
hv_stores(hv, "action", newSVpv(action, 0));
hv_stores(hv, "severity", newSVpvs("FATAL")); /* Connection-related errors are always fatal */
hv_stores(hv, "message", newSVpv(PQerrorMessage(conn), 0));
return fu_croak_hv(hv, "FU::PG::error", "FATAL: %s", PQerrorMessage(conn));
return fu_croak_hv(hv, "FU::Pg::error", "FATAL: %s", PQerrorMessage(conn));
}
__attribute__((noreturn))
@ -89,8 +89,8 @@ static void fupg_result_croak(PGresult *r, const char *action, const char *query
PQclear(r);
croak_sv(verbose
? fu_croak_hv(hv, "FU::PG::error", "%s", SvPV_nolen(*hv_fetchs(hv, "verbose_message", 0)))
: fu_croak_hv(hv, "FU::PG::error", "%s: %s",
? fu_croak_hv(hv, "FU::Pg::error", "%s", SvPV_nolen(*hv_fetchs(hv, "verbose_message", 0)))
: fu_croak_hv(hv, "FU::Pg::error", "%s: %s",
SvPV_nolen(*hv_fetchs(hv, "severity", 0)),
SvPV_nolen(*hv_fetchs(hv, "message", 0))
)
@ -121,6 +121,7 @@ static void fupg_exec_ok(pTHX_ fupg_conn *c, const char *sql) {
/* Connection & transaction handling */
static SV *fupg_connect(pTHX_ const char *str) {
if (!PQconnectdb) fupg_load();
PGconn *conn = PQconnectdb(str);
if (PQstatus(conn) != CONNECTION_OK) {
SV *sv = fupg_conn_errsv(conn, "connect");
@ -135,7 +136,7 @@ static SV *fupg_connect(pTHX_ const char *str) {
c->ntypes = 0;
c->types = NULL;
fustr_init(&c->buf, NULL, SIZE_MAX);
return fu_selfobj(c, "FU::PG::conn");
return fu_selfobj(c, "FU::Pg::conn");
}
static const char *fupg_conn_status(fupg_conn *c) {
@ -169,7 +170,7 @@ static SV *fupg_conn_txn(pTHX_ fupg_conn *c) {
t->stflags = c->stflags;
strcpy(t->rollback_cmd, "ROLLBACK");
SvREFCNT_inc(c->self);
return fu_selfobj(t, "FU::PG::txn");
return fu_selfobj(t, "FU::Pg::txn");
}
static SV *fupg_txn_txn(pTHX_ fupg_txn *t) {
@ -185,7 +186,7 @@ static SV *fupg_txn_txn(pTHX_ fupg_txn *t) {
n->stflags = t->stflags;
snprintf(n->rollback_cmd, sizeof(n->rollback_cmd), "ROLLBACK TO SAVEPOINT fupg_%"UVuf, cookie);
SvREFCNT_inc(t->self);
return fu_selfobj(n, "FU::PG::txn");
return fu_selfobj(n, "FU::Pg::txn");
}
static const char *fupg_txn_status(fupg_txn *t) {

View file

@ -56,7 +56,7 @@ static SV *fupg_q(pTHX_ fupg_conn *c, int stflags, const char *query, I32 ax, I3
}
}
return fu_selfobj(st, "FU::PG::st");
return fu_selfobj(st, "FU::Pg::st");
}
static void fupg_st_destroy(fupg_st *st) {
@ -124,15 +124,12 @@ static void fupg_st_prepare(pTHX_ fupg_st *st) {
PQclear(sync);
}
static SV *fupg_st_params(pTHX_ fupg_st *st) {
static SV *fupg_st_param_types(pTHX_ fupg_st *st) {
fupg_st_prepare(aTHX_ st);
int i, nparams = PQnparams(st->describe);
AV *av = newAV_alloc_x(nparams);
for (i=0; i<nparams; i++) {
HV *hv = newHV();
hv_stores(hv, "oid", newSViv(PQparamtype(st->describe, i)));
av_push_simple(av, newRV_noinc((SV *)hv));
}
for (i=0; i<nparams; i++)
av_push_simple(av, newSViv(PQparamtype(st->describe, i)));
return sv_2mortal(newRV_noinc((SV *)av));
}
@ -256,10 +253,8 @@ static void fupg_st_check_dupcols(pTHX_ fupg_st *st, int start) {
for (i=start; i<nfields; i++) {
const char *key = PQfname(r, i);
int len = -strlen(key);
if (hv_exists(hv, key, len)) {
SvREFCNT_dec((SV *)hv);
if (hv_exists(hv, key, len))
fu_confess("Query returns multiple columns with the same name ('%s')", key);
}
hv_store(hv, key, len, &PL_sv_yes, 0);
}
}
@ -359,7 +354,7 @@ static SV *fupg_st_allh(pTHX_ fupg_st *st) {
static SV *fupg_st_flat(pTHX_ fupg_st *st) {
fupg_st_execute(aTHX_ st);
int i, j, nrows = PQntuples(st->result);
AV *av = newAV_alloc_x(nrows);
AV *av = newAV_alloc_x(nrows * st->nfields);
SV *sv = sv_2mortal(newRV_noinc((SV *)av));
for (i=0; i<nrows; i++) {
for (j=0; j<st->nfields; j++)