Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable automated DB deletion #99

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions database.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,17 @@ static int callback(void *NotUsed, int argc, char **argv, char **azColName){
return 0;
}

void dbclose(void)
{
sqlite3_close(db);
}

bool dbopen(void)
{
int rc = sqlite3_open_v2(FTLfiles.db, &db, SQLITE_OPEN_READWRITE, NULL);
if( rc ){
logg("Cannot open database: %s", sqlite3_errmsg(db));
sqlite3_close(db);
dbclose();
return false;
}

Expand Down Expand Up @@ -82,18 +87,13 @@ bool dbquery(const char *format, ...)

}

void dbclose(void)
{
sqlite3_close(db);
}

bool db_create(void)
{
bool ret;
int rc = sqlite3_open_v2(FTLfiles.db, &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
if( rc ){
logg("Can't create database: %s", sqlite3_errmsg(db));
sqlite3_close(db);
dbclose();
return false;
}
// Create Queries table in the database
Expand Down Expand Up @@ -128,7 +128,7 @@ void db_init(void)
int rc = sqlite3_open_v2(FTLfiles.db, &db, SQLITE_OPEN_READWRITE, NULL);
if( rc ){
logg("Cannot open database: %s", sqlite3_errmsg(db));
sqlite3_close(db);
dbclose();

logg("Creating new (empty) database");
if (!db_create())
Expand Down Expand Up @@ -161,7 +161,7 @@ int db_get_FTL_property(unsigned int ID)
rc = sqlite3_prepare(db, querystring, -1, &dbstmt, NULL);
if( rc ){
printf("Cannot read from database: %s", sqlite3_errmsg(db));
sqlite3_close(db);
dbclose();
return -1;
}
free(querystring);
Expand All @@ -170,7 +170,7 @@ int db_get_FTL_property(unsigned int ID)
sqlite3_step(dbstmt);
if( rc ){
printf("Cannot evaluate in database: %s", sqlite3_errmsg(db));
sqlite3_close(db);
dbclose();
return -1;
}

Expand Down
30 changes: 15 additions & 15 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,21 +111,21 @@ int main (int argc, char* argv[]) {
}
}

if(database)
{
// Disable any other DB accesses while doing this and wait one second
// so that currently running transactions can still finish
database = false;
sleepms(1000);

// Launch DB GC thread
pthread_t DBGCthread;
if(pthread_create( &DBGCthread, &attr, DB_GC_thread, NULL ) != 0)
{
logg("Unable to open DB GC thread. Exiting...");
killed = 1;
}
}
// if(database)
// {
// // Disable any other DB accesses while doing this and wait one second
// // so that currently running transactions can still finish
// database = false;
// sleepms(1000);

// // Launch DB GC thread
// pthread_t DBGCthread;
// if(pthread_create( &DBGCthread, &attr, DB_GC_thread, NULL ) != 0)
// {
// logg("Unable to open DB GC thread. Exiting...");
// killed = 1;
// }
// }

// Avoid immediate re-run of GC thread
while(((time(NULL) - GCdelay)%GCinterval) == 0)
Expand Down