]> jfr.im git - irc/quakenet/newserv.git/blobdiff - sqlite/sqlite.c
CHANSERV: reduce reason to 15 chars
[irc/quakenet/newserv.git] / sqlite / sqlite.c
index 6871594be02423dcce5e63dbbcc7ba8ca7ac89de..7b97264244132dd651ef54dc5189666623d80e78 100644 (file)
@@ -7,7 +7,10 @@
 #include <stdarg.h>
 #include <string.h>
 
+#ifndef __USE_POSIX199309
 #define __USE_POSIX199309
+#endif
+
 #include <time.h>
 
 #include "../core/config.h"
@@ -193,11 +196,11 @@ static void popqueue(void) {
 
 void sqliteasyncqueryf(int identifier, SQLiteQueryHandler handler, void *tag, int flags, char *format, ...) {
   char querybuf[8192];
-  va_list va;
   int len;
   int rc;
   sqlite3_stmt *s;
-  
+  va_list va;
+
   if(!sqliteconnected())
     return;
 
@@ -232,16 +235,18 @@ int sqliteconnected(void) {
   return dbconnected;
 }
 
-void sqliteescapestring(char *buf, char *src, unsigned int len) {
+size_t sqliteescapestring(char *buf, char *src, unsigned int len) {
   unsigned int i;
-  char *p;
+  char *p, *d;
 
-  for(p=src,i=0;i<len;i++,p++) {
+  for(p=src,d=buf,i=0;i<len;i++,p++) {
     if(*p == '\'')
-      *buf++ = *p;
-    *buf++ = *p;
+      *d++ = *p;
+    *d++ = *p;
   }
-  *buf = '\0';
+  *d = '\0';
+
+  return d - buf;
 }
 
 SQLiteResult *sqlitegetresult(SQLiteConn *r) {
@@ -305,6 +310,7 @@ int sqlitequerysuccessful(SQLiteResult *r) {
 
 struct sqlitetableloader {
   SQLiteQueryHandler init, data, fini;
+  void *tag;
   char tablename[];
 };
 
@@ -318,12 +324,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)(NULL, t->tag);
 
-  (t->data)(c, NULL);
+  (t->data)(c, t->tag);
 
   if(t->fini)
-    (t->fini)(c, NULL);
+    (t->fini)(NULL, t->tag);
 
   nsfree(POOL_SQLITE, t);
 }
@@ -352,7 +358,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 +372,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);
 }
@@ -445,3 +452,6 @@ static void dbstatus(int hooknum, void *arg) {
   }
 }
 
+sqlite3 *sqlitegetconn(void) {
+  return conn;
+}