]> jfr.im git - irc/quakenet/newserv.git/blob - pqsql/pqsql.h
BUILD: add require-all build mode
[irc/quakenet/newserv.git] / pqsql / pqsql.h
1 #ifndef __PQSQL_DB_H
2 #define __PQSQL_DB_H
3
4 #include <libpq-fe.h>
5
6 #define PQ_ERRORMSG_LENGTH 1024
7
8 #define QH_ALREADYFIRED 1
9
10 typedef struct PQResult {
11 PGresult *result;
12 int row;
13 int rows;
14 } PQResult;
15
16 typedef int PQModuleIdentifier;
17 typedef void (*PQQueryHandler)(PGconn *, void *);
18
19 void pqloadtable(char *tablename, PQQueryHandler init, PQQueryHandler data, PQQueryHandler fini, void *tag);
20
21 void pqasyncqueryf(PQModuleIdentifier identifier, PQQueryHandler handler, void *tag, int flags, char *format, ...) __attribute__ ((format (printf, 5, 6)));
22 #define pqasyncqueryi(identifier, handler, tag, format, ...) pqasyncqueryf(identifier, handler, tag, 0, format , ##__VA_ARGS__)
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__)
26
27 int pqconnected(void);
28
29 PQModuleIdentifier pqgetid(void);
30 void pqfreeid(PQModuleIdentifier identifier);
31
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
41 #endif