File Coverage

c/libpq.h
Criterion Covered Total %
statement 3 5 60.0
branch 1 88 1.1
condition n/a
subroutine n/a
pod n/a
total 4 93 4.3


line stmt bran cond sub pod time code
1             /* libpq is not being linked directly and there's no build-time dependency on it.
2             * This means we need to manually copy over some definitions from libpq-fe.h
3             */
4              
5             typedef struct PGconn PGconn;
6             typedef struct PGresult PGresult;
7             typedef unsigned int Oid;
8              
9             typedef enum {
10             PGRES_EMPTY_QUERY = 0, PGRES_COMMAND_OK, PGRES_TUPLES_OK, PGRES_COPY_OUT, PGRES_COPY_IN,
11             PGRES_BAD_RESPONSE, PGRES_NONFATAL_ERROR, PGRES_FATAL_ERROR, PGRES_COPY_BOTH,
12             PGRES_SINGLE_TUPLE, PGRES_PIPELINE_SYNC, PGRES_PIPELINE_ABORTED, PGRES_TUPLES_CHUNK
13             } ExecStatusType;
14             typedef enum { PQERRORS_TERSE, PQERRORS_DEFAULT, PQERRORS_VERBOSE, PQERRORS_SQLSTATE } PGVerbosity;
15             typedef enum { PQSHOW_CONTEXT_NEVER, PQSHOW_CONTEXT_ERRORS, PQSHOW_CONTEXT_ALWAYS } PGContextVisibility;
16             typedef enum { CONNECTION_OK, CONNECTION_BAD } ConnStatusType; /* There's more, but they're irrelevant to us */
17             typedef enum { PQTRANS_IDLE, PQTRANS_ACTIVE, PQTRANS_INTRANS, PQTRANS_INERROR, PQTRANS_UNKNOWN } PGTransactionStatusType;
18              
19             #define PG_DIAG_SEVERITY 'S'
20             #define PG_DIAG_SEVERITY_NONLOCALIZED 'V'
21             #define PG_DIAG_SQLSTATE 'C'
22             #define PG_DIAG_MESSAGE_PRIMARY 'M'
23             #define PG_DIAG_MESSAGE_DETAIL 'D'
24             #define PG_DIAG_MESSAGE_HINT 'H'
25             #define PG_DIAG_STATEMENT_POSITION 'P'
26             #define PG_DIAG_INTERNAL_POSITION 'p'
27             #define PG_DIAG_INTERNAL_QUERY 'q'
28             #define PG_DIAG_CONTEXT 'W'
29             #define PG_DIAG_SCHEMA_NAME 's'
30             #define PG_DIAG_TABLE_NAME 't'
31             #define PG_DIAG_COLUMN_NAME 'c'
32             #define PG_DIAG_DATATYPE_NAME 'd'
33             #define PG_DIAG_CONSTRAINT_NAME 'n'
34             #define PG_DIAG_SOURCE_FILE 'F'
35             #define PG_DIAG_SOURCE_LINE 'L'
36             #define PG_DIAG_SOURCE_FUNCTION 'R'
37              
38             #define PG_FUNCS \
39             X(PQbinaryTuples, int, const PGresult *) \
40             X(PQclear, void, PGresult *) \
41             X(PQclosePrepared, PGresult *, PGconn *, const char *) \
42             X(PQcmdTuples, char *, PGresult *) \
43             X(PQconnectdb, PGconn *, const char *) \
44             X(PQenterPipelineMode, int, PGconn *) \
45             X(PQerrorMessage, char *, const PGconn *) \
46             X(PQescapeIdentifier, char *, PGconn *, const char *, size_t) \
47             X(PQescapeLiteral, char *, PGconn *, const char *, size_t) \
48             X(PQexec, PGresult *, PGconn *, const char *) \
49             X(PQexecParams, PGresult *, PGconn *, const char *, int, const Oid *, const char * const *, const int *, const int *, int) \
50             X(PQexecPrepared, PGresult *, PGconn *, const char *, int, const char * const *, const int *, const int *, int) \
51             X(PQexitPipelineMode, int, PGconn *conn) \
52             X(PQfinish, void, PGconn *) \
53             X(PQfmod, int, const PGresult *, int) \
54             X(PQfname, char *, const PGresult *, int) \
55             X(PQfreemem, void, void *) \
56             X(PQftype, Oid, const PGresult *, int) \
57             X(PQgetCopyData, int, PGconn *, char **, int) \
58             X(PQgetResult, PGresult *, PGconn *) \
59             X(PQgetisnull, int, const PGresult *, int, int) \
60             X(PQgetlength, int, const PGresult *, int, int) \
61             X(PQgetvalue, char *, const PGresult *, int, int) \
62             X(PQlibVersion, int, void) \
63             X(PQnfields, int, const PGresult *) \
64             X(PQnparams, int, const PGresult *) \
65             X(PQntuples, int, const PGresult *) \
66             X(PQparamtype, Oid, const PGresult *, int) \
67             X(PQpipelineSync, int, PGconn *) \
68             X(PQputCopyData, int, PGconn *, const char *, int) \
69             X(PQputCopyEnd, int, PGconn *, const char *) \
70             X(PQresStatus, char *, ExecStatusType) \
71             X(PQresultErrorField, char *, const PGresult *, int) \
72             X(PQresultErrorMessage, char *, const PGresult *) \
73             X(PQresultStatus, ExecStatusType, const PGresult *) \
74             X(PQresultVerboseErrorMessage, char *, const PGresult *, PGVerbosity, PGContextVisibility) \
75             X(PQsendDescribePrepared, int, PGconn *, const char *) \
76             X(PQsendPrepare, int, PGconn *, const char *, const char *, int, const Oid *) \
77             X(PQserverVersion, int, const PGconn *) \
78             X(PQstatus, ConnStatusType, const PGconn *) \
79             X(PQtrace, void, PGconn *, FILE *) \
80             X(PQtransactionStatus, PGTransactionStatusType, const PGconn *) \
81             X(PQuntrace, void, PGconn *)
82              
83             #define X(n, r, ...) static r (*n)(__VA_ARGS__);
84             PG_FUNCS
85             #undef X
86              
87 4           static void fupg_load() {
88 4           void *handle = dlopen("libpq.so", RTLD_LAZY);
89 4 50         if (!handle) croak("Unable to load libpq: %s", dlerror());
90             #define X(n, ...) if (!(n = dlsym(handle, #n))) croak("Unable to load libpq: %s", dlerror());
91 0 0         PG_FUNCS
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
92             #undef X
93 0           }
94              
95             #undef PG_FUNCS