2019-07-25 14:50:02 -04:00
|
|
|
/***********************************************************************************************************************************
|
|
|
|
PostgreSQL Client
|
|
|
|
|
|
|
|
Connect to a PostgreSQL database and run queries. This is not intended to be a general purpose client but is suitable for
|
|
|
|
pgBackRest's limited needs. In particular, data type support is limited to text, int, and bool types so it may be necessary to add
|
|
|
|
casts to queries to output one of these types.
|
|
|
|
***********************************************************************************************************************************/
|
|
|
|
#ifndef POSTGRES_QUERY_H
|
|
|
|
#define POSTGRES_QUERY_H
|
|
|
|
|
2019-08-01 15:38:27 -04:00
|
|
|
#include "common/type/string.h"
|
|
|
|
#include "common/type/variantList.h"
|
|
|
|
#include "common/time.h"
|
|
|
|
|
2019-07-25 14:50:02 -04:00
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Object type
|
|
|
|
***********************************************************************************************************************************/
|
|
|
|
#define PG_CLIENT_TYPE PgClient
|
|
|
|
#define PG_CLIENT_PREFIX pgClient
|
|
|
|
|
|
|
|
typedef struct PgClient PgClient;
|
|
|
|
|
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Constructor
|
|
|
|
***********************************************************************************************************************************/
|
|
|
|
PgClient *pgClientNew(
|
|
|
|
const String *host, const unsigned int port, const String *database, const String *user, const TimeMSec queryTimeout);
|
|
|
|
|
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Functions
|
|
|
|
***********************************************************************************************************************************/
|
2020-04-03 18:01:28 -04:00
|
|
|
// Open connection to PostgreSQL
|
2019-07-25 14:50:02 -04:00
|
|
|
PgClient *pgClientOpen(PgClient *this);
|
2019-08-01 15:38:27 -04:00
|
|
|
|
2020-04-03 18:01:28 -04:00
|
|
|
// Move to a new parent mem context
|
2019-08-01 15:38:27 -04:00
|
|
|
PgClient *pgClientMove(PgClient *this, MemContext *parentNew);
|
2020-04-03 18:01:28 -04:00
|
|
|
|
|
|
|
// Execute a query and return results
|
|
|
|
VariantList *pgClientQuery(PgClient *this, const String *query);
|
|
|
|
|
|
|
|
// Close connection to PostgreSQL
|
|
|
|
void pgClientClose(PgClient *this);
|
2019-07-25 14:50:02 -04:00
|
|
|
|
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Destructor
|
|
|
|
***********************************************************************************************************************************/
|
|
|
|
void pgClientFree(PgClient *this);
|
|
|
|
|
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Macros for function logging
|
|
|
|
***********************************************************************************************************************************/
|
|
|
|
String *pgClientToLog(const PgClient *this);
|
|
|
|
|
|
|
|
#define FUNCTION_LOG_PG_CLIENT_TYPE \
|
|
|
|
PgClient *
|
|
|
|
#define FUNCTION_LOG_PG_CLIENT_FORMAT(value, buffer, bufferSize) \
|
|
|
|
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, pgClientToLog, buffer, bufferSize)
|
|
|
|
|
|
|
|
#endif
|