]>
Commit | Line | Data |
---|---|---|
1 | #ifndef __DBAPI_H | |
2 | #define __DBAPI_H | |
3 | ||
4 | #ifndef DBAPI2_ADAPTER | |
5 | #include "../config.h" | |
6 | #endif | |
7 | ||
8 | #define DB_NULLIDENTIFIER 0 | |
9 | #define DB_CREATE 1 | |
10 | #define DB_CALL 2 | |
11 | ||
12 | #ifdef DBAPI_OVERRIDE | |
13 | #undef USE_DBAPI_PGSQL | |
14 | #undef USE_DBAPI_SQLITE | |
15 | #endif | |
16 | ||
17 | #ifndef BUILDING_DBAPI | |
18 | ||
19 | #if defined(USE_DBAPI_PGSQL) || defined(DBAPI_OVERRIDE_PGSQL) | |
20 | ||
21 | #include "../pqsql/pqsql.h" | |
22 | ||
23 | typedef PQModuleIdentifier DBModuleIdentifier; | |
24 | typedef PGconn DBConn; | |
25 | typedef PQQueryHandler DBQueryHandler; | |
26 | typedef PQResult DBResult; | |
27 | ||
28 | #define dbconnected() pqconnected() | |
29 | #define dbgetid() pqgetid() | |
30 | #define dbfreeid(x) pqfreeid(x) | |
31 | ||
32 | #define dbattach(schema) pqcreateschema(schema) | |
33 | #define dbdetach(schema) | |
34 | #define dbescapestring(buf, src, len) PQescapeString(buf, src, len) | |
35 | #define dbloadtable(tablename, init, data, fini) pqloadtable(tablename, init, data, fini, NULL); | |
36 | #define dbloadtable_tag(tablename, init, data, fini, tag) pqloadtable(tablename, init, data, fini, tag); | |
37 | ||
38 | #define dbasyncqueryf(id, handler, tag, flags, format, ...) pqasyncqueryf(id, handler, tag, flags, format , ##__VA_ARGS__) | |
39 | #define dbquerysuccessful(x) pqquerysuccessful(x) | |
40 | #define dbgetresult(conn) pqgetresult(conn) | |
41 | #define dbnumfields(x) PQnfields(x->result) | |
42 | ||
43 | #define dbfetchrow(result) pqfetchrow(result) | |
44 | #define dbgetvalue(result, column) pqgetvalue(result, column) | |
45 | ||
46 | #define dbclear(result) pqclear(result) | |
47 | #define dbcall(id, handler, tag, function, ...) pqasyncqueryf(id, handler, tag, (handler) == NULL ? DB_CALL : 0, "SELECT %s(%s)", function , ##__VA_ARGS__) | |
48 | ||
49 | #endif /* DBAPI_PGSQL */ | |
50 | ||
51 | #if defined(USE_DBAPI_SQLITE) || defined(DBAPI_OVERRIDE_SQLITE) | |
52 | ||
53 | #include "../sqlite/sqlite.h" | |
54 | ||
55 | typedef SQLiteModuleIdentifier DBModuleIdentifier; | |
56 | typedef SQLiteConn DBConn; | |
57 | typedef SQLiteQueryHandler DBQueryHandler; | |
58 | typedef SQLiteResult DBResult; | |
59 | ||
60 | #define dbconnected() sqliteconnected() | |
61 | #define dbgetid() sqlitegetid() | |
62 | #define dbfreeid(x) sqlitefreeid(x) | |
63 | ||
64 | #define dbattach(schema) sqliteattach((schema)) | |
65 | #define dbdetach(schema) sqlitedetach((schema)) | |
66 | #define dbescapestring(buf, src, len) sqliteescapestring(buf, (char *)(src), len) | |
67 | #define dbloadtable(tablename, init, data, fini) sqliteloadtable(tablename, init, data, fini, NULL); | |
68 | #define dbloadtable_tag(tablename, init, data, fini, tag) sqliteloadtable(tablename, init, data, fini, tag); | |
69 | ||
70 | #define dbasyncqueryf(id, handler, tag, flags, format, ...) sqliteasyncqueryf(id, handler, tag, flags, format , ##__VA_ARGS__) | |
71 | #define dbquerysuccessful(x) sqlitequerysuccessful(x) | |
72 | #define dbgetresult(conn) sqlitegetresult(conn) | |
73 | #define dbnumfields(x) sqlite3_column_count(x->r) | |
74 | ||
75 | #define dbfetchrow(result) sqlitefetchrow(result) | |
76 | #define dbgetvalue(result, column) sqlitegetvalue(result, column) | |
77 | ||
78 | #define dbclear(result) sqliteclear(result) | |
79 | ||
80 | #define dbcall(...) abort() /* HA */ | |
81 | ||
82 | #endif /* DBAPI_SQLITE */ | |
83 | ||
84 | #endif /* BUILDING_DBAPI */ | |
85 | ||
86 | #define dbasyncqueryi(identifier, handler, tag, format, ...) dbasyncqueryf(identifier, handler, tag, 0, format , ##__VA_ARGS__) | |
87 | #define dbasyncquery(handler, tag, format, ...) dbasyncqueryf(DB_NULLIDENTIFIER, handler, tag, 0, format , ##__VA_ARGS__) | |
88 | #define dbcreatequery(format, ...) dbasyncqueryf(DB_NULLIDENTIFIER, NULL, NULL, DB_CREATE, format , ##__VA_ARGS__) | |
89 | #define dbquery(format, ...) dbasyncqueryf(DB_NULLIDENTIFIER, NULL, NULL, 0, format , ##__VA_ARGS__) | |
90 | ||
91 | #endif /* __DBAPI_H */ |