]>
Commit | Line | Data |
---|---|---|
e43481af CP |
1 | #ifndef __PQSQL_DB_H |
2 | #define __PQSQL_DB_H | |
3 | ||
4 | #include <libpq-fe.h> | |
5 | ||
47d8702b | 6 | #define PQ_ERRORMSG_LENGTH 1024 |
67545367 | 7 | |
332870cd CP |
8 | #define QH_ALREADYFIRED 1 |
9 | ||
ee8cd7d0 CP |
10 | typedef struct PQResult { |
11 | PGresult *result; | |
12 | int row; | |
13 | int rows; | |
14 | } PQResult; | |
15 | ||
332870cd | 16 | typedef int PQModuleIdentifier; |
e43481af CP |
17 | typedef void (*PQQueryHandler)(PGconn *, void *); |
18 | ||
91ad51f6 | 19 | void pqloadtable(char *tablename, PQQueryHandler init, PQQueryHandler data, PQQueryHandler fini, void *tag); |
67545367 | 20 | |
bb4b25ee | 21 | void pqasyncqueryf(PQModuleIdentifier identifier, PQQueryHandler handler, void *tag, int flags, char *format, ...) __attribute__ ((format (printf, 5, 6))); |
332870cd | 22 | #define pqasyncqueryi(identifier, handler, tag, format, ...) pqasyncqueryf(identifier, handler, tag, 0, format , ##__VA_ARGS__) |
ee8cd7d0 CP |
23 | #define pqasyncquery(handler, tag, format, ...) pqasyncqueryf(DB_NULLIDENTIFIER, handler, tag, 0, format , ##__VA_ARGS__) |
24 | #define pqcreatequery(format, ...) pqasyncqueryf(DB_NULLIDENTIFIER, NULL, NULL, DB_CREATE, format , ##__VA_ARGS__) | |
25 | #define pqquery(format, ...) pqasyncqueryf(DB_NULLIDENTIFIER, NULL, NULL, 0, format , ##__VA_ARGS__) | |
67545367 | 26 | |
e43481af | 27 | int pqconnected(void); |
332870cd CP |
28 | |
29 | PQModuleIdentifier pqgetid(void); | |
30 | void pqfreeid(PQModuleIdentifier identifier); | |
e43481af | 31 | |
ee8cd7d0 CP |
32 | #define pqquerysuccessful(x) (x && (PQresultStatus(x->result) == PGRES_TUPLES_OK)) |
33 | ||
34 | PQResult *pqgetresult(PGconn *c); | |
35 | int pqfetchrow(PQResult *res); | |
36 | char *pqgetvalue(PQResult *res, int column); | |
37 | void pqclear(PQResult *res); | |
38 | ||
39 | #define pqcreateschema(schema) pqcreatequery("CREATE SCHEMA %s;", schema) | |
40 | ||
e43481af | 41 | #endif |