]> jfr.im git - irc/quakenet/newserv.git/blame - pqsql/pqsql.h
Merge chanserv-live into default.
[irc/quakenet/newserv.git] / pqsql / pqsql.h
CommitLineData
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
10typedef struct PQResult {
11 PGresult *result;
12 int row;
13 int rows;
14} PQResult;
15
332870cd 16typedef int PQModuleIdentifier;
e43481af
CP
17typedef void (*PQQueryHandler)(PGconn *, void *);
18
91ad51f6 19void pqloadtable(char *tablename, PQQueryHandler init, PQQueryHandler data, PQQueryHandler fini, void *tag);
67545367 20
bb4b25ee 21void 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 27int pqconnected(void);
332870cd
CP
28
29PQModuleIdentifier pqgetid(void);
30void pqfreeid(PQModuleIdentifier identifier);
e43481af 31
ee8cd7d0
CP
32#define pqquerysuccessful(x) (x && (PQresultStatus(x->result) == PGRES_TUPLES_OK))
33
34PQResult *pqgetresult(PGconn *c);
35int pqfetchrow(PQResult *res);
36char *pqgetvalue(PQResult *res, int column);
37void pqclear(PQResult *res);
38
39#define pqcreateschema(schema) pqcreatequery("CREATE SCHEMA %s;", schema)
40
e43481af 41#endif