Verify DB is actually closed (in tests it isn't!)

This commit is contained in:
Alexey Romanov
2014-10-12 17:21:34 +04:00
parent a8f15a4415
commit 92daa9db89
2 changed files with 12 additions and 4 deletions

View File

@@ -14,6 +14,7 @@ static int DEBUG = 0;
#endif #endif
#define TRACE(x) do { if (DEBUG) debug_printf x; } while (0) #define TRACE(x) do { if (DEBUG) debug_printf x; } while (0)
#define ERROR(x) debug_printf x;
#define EXTEND_DATASET(n, term_count, term_allocated, dataset) \ #define EXTEND_DATASET(n, term_count, term_allocated, dataset) \
term_count += n; \ term_count += n; \
@@ -156,6 +157,7 @@ static ErlDrvData start(ErlDrvPort port, char* cmd) {
static void stop(ErlDrvData handle) { static void stop(ErlDrvData handle) {
sqlite3_drv_t* driver_data = (sqlite3_drv_t*) handle; sqlite3_drv_t* driver_data = (sqlite3_drv_t*) handle;
unsigned int i; unsigned int i;
int close_result;
if (driver_data->prepared_stmts) { if (driver_data->prepared_stmts) {
for (i = 0; i < driver_data->prepared_count; i++) { for (i = 0; i < driver_data->prepared_count; i++) {
@@ -163,11 +165,17 @@ static void stop(ErlDrvData handle) {
} }
driver_free(driver_data->prepared_stmts); driver_free(driver_data->prepared_stmts);
} }
sqlite3_close(driver_data->db);
close_result = sqlite3_close(driver_data->db);
if (close_result != SQLITE_OK) {
//ERROR((driver_data->log,
// "ERROR: Failed to close DB, some resources aren't finalized!"));
fprintf(stderr, "ERROR: Failed to close DB, some resources aren't finalized!");
}
if (driver_data->log && (driver_data->log != stderr)) { if (driver_data->log && (driver_data->log != stderr)) {
fclose(driver_data->log); fclose(driver_data->log);
} }
driver_data->log = NULL;
driver_free(driver_data); driver_free(driver_data);
} }

View File

@@ -51,9 +51,9 @@ all_test_() ->
?FuncTest(unicode), ?FuncTest(unicode),
?FuncTest(acc_string_encoding), ?FuncTest(acc_string_encoding),
?FuncTest(large_offset), ?FuncTest(large_offset),
?FuncTest(issue23),
?FuncTest(issue13), ?FuncTest(issue13),
?FuncTest(enable_load_extension), ?FuncTest(enable_load_extension)]}.
?FuncTest(issue23)]}.
anonymous_test() -> anonymous_test() ->
{ok, Pid} = sqlite3:open(anonymous, []), {ok, Pid} = sqlite3:open(anonymous, []),