]> jfr.im git - irc/quakenet/newserv.git/blame_incremental - pqsql/pqsql.h
CHANSERV: better batcher error handling for expired accounts/accounts with no email.
[irc/quakenet/newserv.git] / pqsql / pqsql.h
... / ...
CommitLineData
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
10typedef struct PQResult {
11 PGresult *result;
12 int row;
13 int rows;
14} PQResult;
15
16typedef int PQModuleIdentifier;
17typedef void (*PQQueryHandler)(PGconn *, void *);
18
19void pqloadtable(char *tablename, PQQueryHandler init, PQQueryHandler data, PQQueryHandler fini, void *tag);
20
21void 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
27int pqconnected(void);
28
29PQModuleIdentifier pqgetid(void);
30void pqfreeid(PQModuleIdentifier identifier);
31
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
41#endif