This commit is contained in:
Max Lapshin
2009-10-14 09:23:53 +04:00
parent de53ecd1c0
commit d9bf2afaac
3 changed files with 17 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
GCC=gcc
LDFLAGS=-shared -lsqlite3 -bundle -flat_namespace -undefined suppress -fPIC -lerl_interface -L/usr/local/lib/erlang/lib/erl_interface-3.6.1/lib -lei
LDFLAGS=-shared -L/usr/local/lib -lsqlite3 -bundle -flat_namespace -undefined suppress -fPIC -lerl_interface -L/usr/local/lib/erlang/lib/erl_interface-3.6.1/lib -lei
SRCS=sqlite3_drv.c sqlite3_drv.h
OUTPUT=sqlite3_drv.so
CFLAGS=-o ../ebin/${OUTPUT} -I/usr/local/lib/erlang/usr/include/ -I/usr/local/lib/erlang/lib/erl_interface-3.6.1/include/ -arch i386 -arch x86_64

View File

@@ -93,7 +93,6 @@ static int sql_exec(sqlite3_drv_t *drv, char *command, int command_size) {
char *rest = NULL;
sqlite3_stmt *statement;
fprintf(stderr, "Exec: %.*s\n", command_size, command);
result = sqlite3_prepare_v2(drv->db, command, command_size, &statement, (const char **)&rest);
if(result != SQLITE_OK) {
return return_error(drv, sqlite3_errmsg(drv->db));
@@ -103,9 +102,13 @@ static int sql_exec(sqlite3_drv_t *drv, char *command, int command_size) {
async_command->driver_data = drv;
async_command->statement = statement;
// fprintf(stderr, "Driver async: %p\n", async_command->statement);
fprintf(stderr, "Driver async: %d %p\n", SQLITE_VERSION_NUMBER, async_command->statement);
result = driver_async(drv->port, &drv->key, sql_exec_async, async_command, sql_free_async);
if (1) {
sql_exec_async(async_command);
} else {
drv->async_handle = driver_async(drv->port, &drv->key, sql_exec_async, async_command, sql_free_async);
}
return 0;
}
@@ -115,6 +118,8 @@ static void sql_free_async(void *_async_command)
async_sqlite3_command *async_command = (async_sqlite3_command *)_async_command;
free(async_command->dataset);
async_command->driver_data->async_handle = 0;
if (async_command->floats) {
free(async_command->floats);
}
@@ -179,6 +184,7 @@ static void sql_exec_async(void *_async_command) {
}
fprintf(stderr, "Exec: %s\n", sqlite3_sql(statement));
while (column_count > 0 && (next_row = sqlite3_step(statement)) == SQLITE_ROW) {
for (i = 0; i < column_count; i++) {

View File

@@ -5,6 +5,12 @@
#include <sqlite3.h>
#include <erl_interface.h>
#if SQLITE_VERSION_NUMBER < 3006001
#error "SQLite3 of version 3.6.1 minumum required"
#endif
// Path to file where data will be stored.
// It will be created if it doesn't exist
#define DB_PATH "./store.db"
@@ -22,6 +28,7 @@ typedef struct sqlite3_drv_t {
ErlDrvPort port;
unsigned int key;
struct sqlite3 *db;
long async_handle;
} sqlite3_drv_t;
typedef struct async_sqlite3_command {