1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-01 00:25:06 +02:00
Files
pgbackrest/libc/xs/postgres/client.xs
David Steele ec173f12fb Add MEM_CONTEXT_PRIOR() block and update current call sites.
This macro block encapsulates the common pattern of switching to the prior (formerly called old) mem context to return results from a function.

Also rename MEM_CONTEXT_OLD() to memContextPrior().  This violates our convention of macros being in all caps but memContextPrior() will become a function very soon so this will reduce churn.
2020-01-17 13:29:49 -07:00

92 lines
2.4 KiB
Plaintext

# ----------------------------------------------------------------------------------------------------------------------------------
# PostgreSQL Query Client
# ----------------------------------------------------------------------------------------------------------------------------------
MODULE = pgBackRest::LibC PACKAGE = pgBackRest::LibC::PgClient
####################################################################################################################################
pgBackRest::LibC::PgClient
new(class, host, port, database, queryTimeout)
PREINIT:
MEM_CONTEXT_XS_TEMP_BEGIN()
{
INPUT:
const String *class = STR_NEW_SV($arg);
const String *host = STR_NEW_SV($arg);
U32 port
const String *database = STR_NEW_SV($arg);
UV queryTimeout
CODE:
CHECK(strEqZ(class, PACKAGE_NAME_LIBC "::PgClient"));
MEM_CONTEXT_PRIOR_BEGIN()
{
RETVAL = pgClientNew(host, port, database, NULL, queryTimeout);
}
MEM_CONTEXT_PRIOR_END();
OUTPUT:
RETVAL
CLEANUP:
}
MEM_CONTEXT_XS_TEMP_END();
####################################################################################################################################
void
open(self)
PREINIT:
MEM_CONTEXT_XS_TEMP_BEGIN()
{
INPUT:
pgBackRest::LibC::PgClient self
CODE:
pgClientOpen(self);
CLEANUP:
}
MEM_CONTEXT_XS_TEMP_END();
####################################################################################################################################
const char *
query(self, query)
PREINIT:
MEM_CONTEXT_XS_TEMP_BEGIN()
{
INPUT:
pgBackRest::LibC::PgClient self
const String *query = STR_NEW_SV($arg);
CODE:
VariantList *result = pgClientQuery(self, query);
RETVAL = result ? strPtr(jsonFromVar(varNewVarLst(result))) : NULL;
OUTPUT:
RETVAL
CLEANUP:
}
MEM_CONTEXT_XS_TEMP_END();
####################################################################################################################################
void
close(self)
PREINIT:
MEM_CONTEXT_XS_TEMP_BEGIN()
{
INPUT:
pgBackRest::LibC::PgClient self
CODE:
pgClientClose(self);
CLEANUP:
}
MEM_CONTEXT_XS_TEMP_END();
####################################################################################################################################
void
DESTROY(self)
PREINIT:
MEM_CONTEXT_XS_TEMP_BEGIN()
{
INPUT:
pgBackRest::LibC::PgClient self
CODE:
pgClientFree(self);
CLEANUP:
}
MEM_CONTEXT_XS_TEMP_END();