]> jfr.im git - irc/quakenet/newserv.git/commitdiff
Add a tag for loadtable.
authorChris Porter <redacted>
Mon, 15 Sep 2008 02:26:17 +0000 (03:26 +0100)
committerChris Porter <redacted>
Mon, 15 Sep 2008 02:26:17 +0000 (03:26 +0100)
dbapi/dbapi.h
pqsql/pqsql.c
pqsql/pqsql.h
sqlite/sqlite.c
sqlite/sqlite.h

index 2a93afb3beb2a3e238a76072bc6ae4c2bef10b81..b8e241c07ec9ff700380c862fd8f7fead6ebdf50 100644 (file)
@@ -29,7 +29,7 @@ typedef PQResult DBResult;
 #define dbattach(schema) pqcreateschema(schema)
 #define dbdetach(schema)
 #define dbescapestring(buf, src, len)  PQescapeString(buf, src, len)
-#define dbloadtable(tablename, init, data, fini) pqloadtable(tablename, init, data, fini);
+#define dbloadtable(tablename, init, data, fini) pqloadtable(tablename, init, data, fini, NULL);
 
 #define dbasyncqueryf(id, handler, tag, flags, format, ...) pqasyncqueryf(id, handler, tag, flags, format , ##__VA_ARGS__)
 #define dbquerysuccessful(x) pqquerysuccessful(x)
@@ -59,7 +59,7 @@ typedef SQLiteResult DBResult;
 #define dbattach(schema) sqliteattach(schema)
 #define dbdetach(schema) sqlitedetach(schema)
 #define dbescapestring(buf, src, len) sqliteescapestring(buf, (char *)(src), len)
-#define dbloadtable(tablename, init, data, fini) sqliteloadtable(tablename, init, data, fini);
+#define dbloadtable(tablename, init, data, fini) sqliteloadtable(tablename, init, data, fini, NULL);
 
 #define dbasyncqueryf(id, handler, tag, flags, format, ...) sqliteasyncqueryf(id, handler, tag, flags, format , ##__VA_ARGS__)
 #define dbquerysuccessful(x) sqlitequerysuccessful(x)
index 8a15d9e390e5d1ce02bfeec67fc5977ca66c9cdf..a43c04905ff95ae40be60a27397e4b05a1862a94 100644 (file)
@@ -51,6 +51,7 @@ typedef struct pqtableloaderinfo_s
 {
     sstring *tablename;
     PQQueryHandler init, data, fini;
+    void *tag;
 } pqtableloaderinfo_s;
 
 pqasyncquery_s *queryhead = NULL, *querytail = NULL;
@@ -275,7 +276,7 @@ void pqasyncqueryf(int identifier, PQQueryHandler handler, void *tag, int flags,
   }
 }
 
-void pqloadtable(char *tablename, PQQueryHandler init, PQQueryHandler data, PQQueryHandler fini)
+void pqloadtable(char *tablename, PQQueryHandler init, PQQueryHandler data, PQQueryHandler fini, void *tag)
 {
   pqtableloaderinfo_s *tli;
 
@@ -284,6 +285,7 @@ void pqloadtable(char *tablename, PQQueryHandler init, PQQueryHandler data, PQQu
   tli->init=init;
   tli->data=data;
   tli->fini=fini;
+  tli->tag=tag;
   pqasyncquery(pqstartloadtable, tli, "SELECT COUNT(*) FROM %s", tli->tablename->content);
 }
 
@@ -311,16 +313,16 @@ void pqstartloadtable(PGconn *dbconn, void *arg)
 
   Error("pqsql", ERR_INFO, "Found %lu entries in table %s, scheduling load.", count, tli->tablename->content);
 
-  pqasyncquery(tli->init, NULL, "BEGIN");
+  pqasyncquery(tli->init, tli->tag, "BEGIN");
   pqasyncquery(NULL, NULL, "DECLARE table%lx%lx CURSOR FOR SELECT * FROM %s", tablecrc, count, tli->tablename->content);
 
   for (i=0;(count - i) > 1000; i+=1000)
-    pqasyncquery(tli->data, NULL, "FETCH 1000 FROM table%lx%lx", tablecrc, count);
+    pqasyncquery(tli->data, tli->tag, "FETCH 1000 FROM table%lx%lx", tablecrc, count);
 
-  pqasyncquery(tli->data, NULL, "FETCH ALL FROM table%lx%lx", tablecrc, count);
+  pqasyncquery(tli->data, tli->tag, "FETCH ALL FROM table%lx%lx", tablecrc, count);
 
   pqasyncquery(NULL, NULL, "CLOSE table%lx%lx", tablecrc, count);
-  pqasyncquery(tli->fini, NULL, "COMMIT");
+  pqasyncquery(tli->fini, tli->tag, "COMMIT");
 
   freesstring(tli->tablename);
   nsfree(POOL_PQSQL, tli);
index 3be0ffddd7c80664b78abded21b2f17d346ceb09..6f885e2eec1d27cd06e74aa1c3213e8f2a7dec1b 100644 (file)
@@ -16,7 +16,7 @@ typedef struct PQResult {
 typedef int PQModuleIdentifier;
 typedef void (*PQQueryHandler)(PGconn *, void *);
 
-void pqloadtable(char *tablename, PQQueryHandler init, PQQueryHandler data, PQQueryHandler fini);
+void pqloadtable(char *tablename, PQQueryHandler init, PQQueryHandler data, PQQueryHandler fini, void *tag);
 
 void pqasyncqueryf(PQModuleIdentifier identifier, PQQueryHandler handler, void *tag, int flags, char *format, ...) __attribute__ ((format (printf, 5, 6)));
 #define pqasyncqueryi(identifier, handler, tag, format, ...) pqasyncqueryf(identifier, handler, tag, 0, format , ##__VA_ARGS__)
index 6871594be02423dcce5e63dbbcc7ba8ca7ac89de..0349788a59cd938b436e2e9a2aeb6775130c4354 100644 (file)
@@ -48,6 +48,9 @@ static int inited;
 static void sqlitequeueprocessor(void *arg);
 static void dbstatus(int hooknum, void *arg);
 
+void registersqliteprovider(void);
+void deregistersqliteprovider(void);
+
 void _init(void) {
   sstring *dbfile;
   int rc;
@@ -88,6 +91,8 @@ void _init(void) {
 
   sqliteasyncqueryf(0, NULL, NULL, 0, "PRAGMA synchronous=" SYNC_MODE ";");
   registerhook(HOOK_CORE_STATSREQUEST, dbstatus);
+
+/*  registersqliteprovider();*/
 }
 
 void _fini(void) {
@@ -109,6 +114,8 @@ void _fini(void) {
 
     sqlite3_close(conn);
 
+/*    deregistersqliteprovider();*/
+
     dbconnected = 0;
   }
 
@@ -191,9 +198,8 @@ static void popqueue(void) {
   return;
 }
 
-void sqliteasyncqueryf(int identifier, SQLiteQueryHandler handler, void *tag, int flags, char *format, ...) {
+void sqliteasyncqueryfv(int identifier, SQLiteQueryHandler handler, void *tag, int flags, char *format, va_list va) {
   char querybuf[8192];
-  va_list va;
   int len;
   int rc;
   sqlite3_stmt *s;
@@ -201,9 +207,7 @@ void sqliteasyncqueryf(int identifier, SQLiteQueryHandler handler, void *tag, in
   if(!sqliteconnected())
     return;
 
-  va_start(va, format);
   len = vsnprintf(querybuf, sizeof(querybuf), format, va);
-  va_end(va);
 
   rc = sqlite3_prepare(conn, querybuf, -1, &s, NULL);
   if(rc != SQLITE_OK) {
@@ -228,6 +232,14 @@ void sqliteasyncqueryf(int identifier, SQLiteQueryHandler handler, void *tag, in
   processstatement(rc, s, handler, tag, querybuf);
 }
 
+void sqliteasyncqueryf(int identifier, SQLiteQueryHandler handler, void *tag, int flags, char *format, ...) {
+  va_list va;
+
+  va_start(va, format);
+  sqliteasyncqueryfv(identifier, handler, tag, flags, format, va);
+  va_end(va);
+}
+
 int sqliteconnected(void) {
   return dbconnected;
 }
@@ -305,6 +317,7 @@ int sqlitequerysuccessful(SQLiteResult *r) {
 
 struct sqlitetableloader {
   SQLiteQueryHandler init, data, fini;
+  void *tag;
   char tablename[];
 };
 
@@ -318,12 +331,12 @@ static void loadtablerows(SQLiteConn *c, void *tag) {
 
   /* the handlers do all the checking and cleanup */
   if(t->init)
-    (t->init)(c, NULL);
+    (t->init)(c, t->tag);
 
-  (t->data)(c, NULL);
+  (t->data)(c, t->tag);
 
   if(t->fini)
-    (t->fini)(c, NULL);
+    (t->fini)(c, t->tag);
 
   nsfree(POOL_SQLITE, t);
 }
@@ -352,7 +365,7 @@ static void loadtablecount(SQLiteConn *c, void *tag) {
   sqliteasyncqueryf(0, loadtablerows, t, 0, "SELECT * FROM %s", t->tablename);
 }
 
-void sqliteloadtable(char *tablename, SQLiteQueryHandler init, SQLiteQueryHandler data, SQLiteQueryHandler fini) {
+void sqliteloadtable(char *tablename, SQLiteQueryHandler init, SQLiteQueryHandler data, SQLiteQueryHandler fini, void *tag) {
   struct sqlitetableloader *t;
   int len;
 
@@ -366,6 +379,7 @@ void sqliteloadtable(char *tablename, SQLiteQueryHandler init, SQLiteQueryHandle
   t->init = init;
   t->data = data;
   t->fini = fini;
+  t->tag = tag;
 
   sqliteasyncqueryf(0, loadtablecount, t, 0, "SELECT COUNT(*) FROM %s", tablename);
 }
index fe1943a7b6f788898327a43d6dbc9a30a4e6817c..47e9d23f89d35f092365aff8dd6f00bd5bc0a753 100644 (file)
@@ -13,6 +13,7 @@ typedef int SQLiteModuleIdentifier;
 typedef void (*SQLiteQueryHandler)(SQLiteConn *, void *);
 
 void sqliteasyncqueryf(SQLiteModuleIdentifier identifier, SQLiteQueryHandler handler, void *tag, int flags, char *format, ...) __attribute__ ((format (printf, 5, 6)));
+void sqliteasyncqueryfv(int identifier, SQLiteQueryHandler handler, void *tag, int flags, char *format, va_list ap);
 
 int sqliteconnected(void);
 
@@ -31,6 +32,6 @@ int sqlitequerysuccessful(SQLiteResult *);
 
 void sqliteattach(char *schema);
 void sqlitedetach(char *schema);
-void sqliteloadtable(char *tablename, SQLiteQueryHandler init, SQLiteQueryHandler data, SQLiteQueryHandler fini);
+void sqliteloadtable(char *tablename, SQLiteQueryHandler init, SQLiteQueryHandler data, SQLiteQueryHandler fini, void *tag);
 
 #endif