Log into correct temp directory
This commit is contained in:
@@ -94,40 +94,54 @@ static ErlDrvData start(ErlDrvPort port, char* cmd) {
|
|||||||
sqlite3_drv_t* retval = (sqlite3_drv_t*) driver_alloc(sizeof(sqlite3_drv_t));
|
sqlite3_drv_t* retval = (sqlite3_drv_t*) driver_alloc(sizeof(sqlite3_drv_t));
|
||||||
struct sqlite3 *db = NULL;
|
struct sqlite3 *db = NULL;
|
||||||
int status = 0;
|
int status = 0;
|
||||||
char *db_name;
|
char *db_name = strstr(cmd, " ");
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
retval->log = fopen(LOG_PATH, "a+");
|
#ifdef _MSC_VER
|
||||||
|
const char *log_file = _tempnam(NULL, "erlang-sqlite3-log-");
|
||||||
|
retval->log =
|
||||||
|
fopen_s(log_file, "a");
|
||||||
|
#else
|
||||||
|
const char *log_file = tempnam(NULL, "erlang-sqlite3-log-");
|
||||||
|
retval->log =
|
||||||
|
fopen(log_file, "ax");
|
||||||
|
#endif
|
||||||
if (!retval->log) {
|
if (!retval->log) {
|
||||||
fprintf(stderr, "Error creating log file: %s\n", LOG_PATH);
|
fprintf(stderr, "Error creating log file: %s\n", log_file);
|
||||||
// if we can't open the log file we shouldn't hide the data or the problem
|
// if we can't open the log file we shouldn't hide the data or the problem
|
||||||
retval->log = stderr; // noisy
|
retval->log = stderr; // noisy
|
||||||
}
|
}
|
||||||
|
free(log_file);
|
||||||
fprintf(retval->log,
|
|
||||||
"--- Start erlang-sqlite3 driver\nCommand line: [%s]\n", cmd);
|
|
||||||
#else
|
#else
|
||||||
retval->log = NULL;
|
retval->log = NULL;
|
||||||
#endif
|
#endif
|
||||||
db_name = strstr(cmd, " ");
|
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
#pragma warning(disable: 4306)
|
||||||
|
#endif
|
||||||
if (!db_name) {
|
if (!db_name) {
|
||||||
TRACE((retval->log,
|
driver_free(retval);
|
||||||
"ERROR: DB name should be passed at command line\n"));
|
return ERL_DRV_ERROR_BADARG;
|
||||||
db_name = DB_PATH;
|
|
||||||
} else {
|
} else {
|
||||||
++db_name; // move to first character after ' '
|
++db_name; // move to first character after ' '
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create and open the database
|
// Create and open the database
|
||||||
sqlite3_open(db_name, &db);
|
status = sqlite3_open(db_name, &db);
|
||||||
status = sqlite3_errcode(db);
|
|
||||||
|
|
||||||
if (status != SQLITE_OK) {
|
if (status != SQLITE_OK) {
|
||||||
TRACE((retval->log, "ERROR: Unable to open file: %s because %s\n\n",
|
TRACE((retval->log, "ERROR: Unable to open file: %s because %s\n\n",
|
||||||
db_name, sqlite3_errmsg(db)));
|
db_name, sqlite3_errmsg(db)));
|
||||||
|
// We don't do this because there's no way to pass the error to Erlang
|
||||||
|
// sqlite3_close(db);
|
||||||
|
// driver_free(retval);
|
||||||
|
// return ERL_DRV_ERROR_GENERAL;
|
||||||
} else {
|
} else {
|
||||||
TRACE((retval->log, "Opened file %s\n", db_name));
|
TRACE((retval->log, "Opened file %s\n", db_name));
|
||||||
}
|
}
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
#pragma warning(default: 4306)
|
||||||
|
#endif
|
||||||
|
|
||||||
// Set the state for the driver
|
// Set the state for the driver
|
||||||
retval->port = port;
|
retval->port = port;
|
||||||
|
|||||||
@@ -25,11 +25,6 @@
|
|||||||
#pragma warning(disable: 4820)
|
#pragma warning(disable: 4820)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Path to file where data will be stored.
|
|
||||||
// It will be created if it doesn't exist
|
|
||||||
#define DB_PATH "./store.db"
|
|
||||||
#define LOG_PATH "/tmp/erlang-sqlite3-drv.log"
|
|
||||||
|
|
||||||
// Binary commands between Erlang VM and Driver
|
// Binary commands between Erlang VM and Driver
|
||||||
#define CMD_SQL_EXEC 2
|
#define CMD_SQL_EXEC 2
|
||||||
// #define CMD_DEL 3
|
// #define CMD_DEL 3
|
||||||
|
|||||||
Reference in New Issue
Block a user