#include <stdarg.h>
#include <string.h>
+#ifndef __USE_POSIX199309
#define __USE_POSIX199309
+#endif
+
#include <time.h>
#include "../core/config.h"
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;
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) {
struct sqlitetableloader {
SQLiteQueryHandler init, data, fini;
+ void *tag;
char tablename[];
};
/* 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);
}
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;
t->init = init;
t->data = data;
t->fini = fini;
+ t->tag = tag;
sqliteasyncqueryf(0, loadtablecount, t, 0, "SELECT COUNT(*) FROM %s", tablename);
}
}
}
+sqlite3 *sqlitegetconn(void) {
+ return conn;
+}