pg: Add transaction & subtransaction support

Was expecting the implementation of this to get overly complicated and
brittle, but using a counter-based cookie and doing parts of it in Perl
made it pretty easy actually.  Pretty happy with how this turned out so
far.

TODO: documentation -.-
This commit is contained in:
Yorhel 2025-02-06 17:38:33 +01:00
parent 9d5905e3b4
commit 171afc0268
5 changed files with 276 additions and 10 deletions

View file

@ -13,6 +13,8 @@ typedef enum {
} ExecStatusType;
typedef enum { PQERRORS_TERSE, PQERRORS_DEFAULT, PQERRORS_VERBOSE, PQERRORS_SQLSTATE } PGVerbosity;
typedef enum { PQSHOW_CONTEXT_NEVER, PQSHOW_CONTEXT_ERRORS, PQSHOW_CONTEXT_ALWAYS } PGContextVisibility;
typedef enum { CONNECTION_OK, CONNECTION_BAD } ConnStatusType; /* There's more, but they're irrelevant to us */
typedef enum { PQTRANS_IDLE, PQTRANS_ACTIVE, PQTRANS_INTRANS, PQTRANS_INERROR, PQTRANS_UNKNOWN } PGTransactionStatusType;
#define PG_DIAG_SEVERITY 'S'
#define PG_DIAG_SEVERITY_NONLOCALIZED 'V'
@ -62,8 +64,9 @@ typedef enum { PQSHOW_CONTEXT_NEVER, PQSHOW_CONTEXT_ERRORS, PQSHOW_CONTEXT_ALWAY
X(PQresultStatus, ExecStatusType, const PGresult *) \
X(PQresultVerboseErrorMessage, char *, const PGresult *, PGVerbosity, PGContextVisibility) \
X(PQserverVersion, int, const PGconn *) \
X(PQstatus, int, const PGconn *) \
X(PQstatus, ConnStatusType, const PGconn *) \
X(PQtrace, void, PGconn *, FILE *) \
X(PQtransactionStatus, PGTransactionStatusType, const PGconn *) \
X(PQuntrace, void, PGconn *)
#define X(n, r, ...) static r (*n)(__VA_ARGS__);