#include "../dbapi2/dbapi2.h"
#include "../lib/stringbuf.h"
+#include "../lib/version.h"
+
+#include <string.h>
static DBAPI2_HANDLE *dbapi2_adapter_new(const DBAPIConn *);
static void dbapi2_adapter_close(DBAPIConn *);
static char *dbapi2_adapter_tablename(const DBAPIConn *, const char *);
+static void dbapi2_adapter_call(const DBAPIConn *, DBAPIQueryCallback, DBAPIUserData, const char *, const char *);
+
static DBAPIProvider adapterprovider = {
.new = dbapi2_adapter_new,
.close = dbapi2_adapter_close,
.quotestring = dbapi2_adapter_quotestring,
.tablename = dbapi2_adapter_tablename,
+
+ .call = dbapi2_adapter_call,
};
struct DBAPI2AdapterQueryCallback {
if(!c)
return NULL;
- if(!r)
+ if(!r) {
r = calloc(1, sizeof(DBAPIResult));
+ } else {
+ memset(r, 0, sizeof(DBAPIResult));
+ }
r->clear = dbapi2_adapter_result_clear;
r->handle = dbgetresult(c);
+ r->affected = dbnumaffected(c, r->handle);
+
if(!dbquerysuccessful(r->handle))
return r;
static void dbapi2_adapter_loadtablewrapper_init(DBConn *c, void *data) {
struct DBAPI2AdapterLoadTableCallback *a = data;
- DBAPIResult r;
- a->init(wrapresult(&r, c), a->data);
+ a->init(NULL, a->data);
}
static void dbapi2_adapter_loadtablewrapper_data(DBConn *c, void *data) {
static void dbapi2_adapter_loadtablewrapper_fini(DBConn *c, void *data) {
struct DBAPI2AdapterLoadTableCallback *a = data;
- DBAPIResult r;
if(a->fini)
- a->fini(wrapresult(&r, c), a->data);
+ a->fini(NULL, a->data);
free(a);
}
return buf;
}
#endif
+
+static void dbapi2_adapter_call(const DBAPIConn *db, DBAPIQueryCallback cb, DBAPIUserData data, const char *function, const char *query) {
+ struct DBAPI2AdapterQueryCallback *a;
+ char buf[512];
+
+ if(cb) {
+ a = malloc(sizeof(struct DBAPI2AdapterQueryCallback));
+
+ a->db = db;
+ a->data = data;
+ a->callback = cb;
+ } else {
+ a = NULL;
+ }
+
+ snprintf(buf, sizeof(buf), "%s", db->tablename(db, function));
+ dbcall((int)(long)db->handle, cb?dbapi2_adapter_querywrapper:NULL, a, buf, query);
+}
+