fixes
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
GCC=gcc
|
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
|
SRCS=sqlite3_drv.c sqlite3_drv.h
|
||||||
OUTPUT=sqlite3_drv.so
|
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
|
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
|
||||||
|
|||||||
@@ -93,7 +93,6 @@ static int sql_exec(sqlite3_drv_t *drv, char *command, int command_size) {
|
|||||||
char *rest = NULL;
|
char *rest = NULL;
|
||||||
sqlite3_stmt *statement;
|
sqlite3_stmt *statement;
|
||||||
|
|
||||||
fprintf(stderr, "Exec: %.*s\n", command_size, command);
|
|
||||||
result = sqlite3_prepare_v2(drv->db, command, command_size, &statement, (const char **)&rest);
|
result = sqlite3_prepare_v2(drv->db, command, command_size, &statement, (const char **)&rest);
|
||||||
if(result != SQLITE_OK) {
|
if(result != SQLITE_OK) {
|
||||||
return return_error(drv, sqlite3_errmsg(drv->db));
|
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->driver_data = drv;
|
||||||
async_command->statement = statement;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,6 +118,8 @@ static void sql_free_async(void *_async_command)
|
|||||||
async_sqlite3_command *async_command = (async_sqlite3_command *)_async_command;
|
async_sqlite3_command *async_command = (async_sqlite3_command *)_async_command;
|
||||||
free(async_command->dataset);
|
free(async_command->dataset);
|
||||||
|
|
||||||
|
async_command->driver_data->async_handle = 0;
|
||||||
|
|
||||||
if (async_command->floats) {
|
if (async_command->floats) {
|
||||||
free(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) {
|
while (column_count > 0 && (next_row = sqlite3_step(statement)) == SQLITE_ROW) {
|
||||||
|
|
||||||
for (i = 0; i < column_count; i++) {
|
for (i = 0; i < column_count; i++) {
|
||||||
|
|||||||
@@ -5,6 +5,12 @@
|
|||||||
#include <sqlite3.h>
|
#include <sqlite3.h>
|
||||||
#include <erl_interface.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.
|
// Path to file where data will be stored.
|
||||||
// It will be created if it doesn't exist
|
// It will be created if it doesn't exist
|
||||||
#define DB_PATH "./store.db"
|
#define DB_PATH "./store.db"
|
||||||
@@ -22,6 +28,7 @@ typedef struct sqlite3_drv_t {
|
|||||||
ErlDrvPort port;
|
ErlDrvPort port;
|
||||||
unsigned int key;
|
unsigned int key;
|
||||||
struct sqlite3 *db;
|
struct sqlite3 *db;
|
||||||
|
long async_handle;
|
||||||
} sqlite3_drv_t;
|
} sqlite3_drv_t;
|
||||||
|
|
||||||
typedef struct async_sqlite3_command {
|
typedef struct async_sqlite3_command {
|
||||||
|
|||||||
Reference in New Issue
Block a user