From d9bf2afaac4dd242b1847067e6aa5bd6fef7ce26 Mon Sep 17 00:00:00 2001 From: Max Lapshin Date: Wed, 14 Oct 2009 09:23:53 +0400 Subject: [PATCH] fixes --- priv/Makefile | 2 +- priv/sqlite3_drv.c | 12 +++++++++--- priv/sqlite3_drv.h | 7 +++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/priv/Makefile b/priv/Makefile index 899da77..cb4ae50 100644 --- a/priv/Makefile +++ b/priv/Makefile @@ -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 diff --git a/priv/sqlite3_drv.c b/priv/sqlite3_drv.c index 441d30d..a9fa53d 100644 --- a/priv/sqlite3_drv.c +++ b/priv/sqlite3_drv.c @@ -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++) { diff --git a/priv/sqlite3_drv.h b/priv/sqlite3_drv.h index 62e44e3..5ad1b7e 100644 --- a/priv/sqlite3_drv.h +++ b/priv/sqlite3_drv.h @@ -5,6 +5,12 @@ #include #include +#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 {