]> 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 47d334735be0a2df47176ffdaa52afc41841d673..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"
@@ -48,9 +51,6 @@ 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;
@@ -91,8 +91,6 @@ void _init(void) {
 
   sqliteasyncqueryf(0, NULL, NULL, 0, "PRAGMA synchronous=" SYNC_MODE ";");
   registerhook(HOOK_CORE_STATSREQUEST, dbstatus);
-
-  registersqliteprovider();
 }
 
 void _fini(void) {
@@ -114,8 +112,6 @@ void _fini(void) {
 
     sqlite3_close(conn);
 
-    deregistersqliteprovider();
-
     dbconnected = 0;
   }
 
@@ -198,16 +194,19 @@ static void popqueue(void) {
   return;
 }
 
-void sqliteasyncqueryfv(int identifier, SQLiteQueryHandler handler, void *tag, int flags, char *format, va_list va) {
+void sqliteasyncqueryf(int identifier, SQLiteQueryHandler handler, void *tag, int flags, char *format, ...) {
   char querybuf[8192];
   int len;
   int rc;
   sqlite3_stmt *s;
-  
+  va_list va;
+
   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) {
@@ -232,30 +231,22 @@ void sqliteasyncqueryfv(int identifier, SQLiteQueryHandler handler, void *tag, i
   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;
 }
 
 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 buf - p;
+  return d - buf;
 }
 
 SQLiteResult *sqlitegetresult(SQLiteConn *r) {
@@ -333,12 +324,12 @@ static void loadtablerows(SQLiteConn *c, void *tag) {
 
   /* the handlers do all the checking and cleanup */
   if(t->init)
-    (t->init)(c, t->tag);
+    (t->init)(NULL, t->tag);
 
   (t->data)(c, t->tag);
 
   if(t->fini)
-    (t->fini)(c, t->tag);
+    (t->fini)(NULL, t->tag);
 
   nsfree(POOL_SQLITE, t);
 }
@@ -461,3 +452,6 @@ static void dbstatus(int hooknum, void *arg) {
   }
 }
 
+sqlite3 *sqlitegetconn(void) {
+  return conn;
+}