add: macro endpoints
add: basic macro support fix: database locking with lock-pointer fix: memory leaks
This commit is contained in:
parent
6a2b94ef1c
commit
9d2c48d645
30 changed files with 606 additions and 213 deletions
src
|
@ -8,7 +8,7 @@
|
|||
#include <sql/migration_1.h>
|
||||
|
||||
sqlite3 *global_database;
|
||||
static int in_transaction;
|
||||
static database_transaction_lock *transaction_lock;
|
||||
|
||||
void
|
||||
database_init()
|
||||
|
@ -24,7 +24,7 @@ database_init()
|
|||
database_migrate();
|
||||
|
||||
sqlite3_exec(global_database, "PRAGMA foreign_keys = ON", 0, 0, 0);
|
||||
in_transaction = 0;
|
||||
transaction_lock = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -91,33 +91,37 @@ database_migrate()
|
|||
return;
|
||||
}
|
||||
|
||||
int
|
||||
database_transaction_begin()
|
||||
void
|
||||
database_transaction_begin(database_transaction_lock *lock)
|
||||
{
|
||||
if(!in_transaction)
|
||||
if(transaction_lock == NULL)
|
||||
{
|
||||
LOGGER_DEBUG("beginning transaction\n");
|
||||
sqlite3_exec(global_database, "BEGIN TRANSACTION;", NULL, NULL, NULL);
|
||||
in_transaction = 1;
|
||||
return 1;
|
||||
transaction_lock = lock;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
database_transaction_commit()
|
||||
database_transaction_commit(database_transaction_lock *lock)
|
||||
{
|
||||
LOGGER_DEBUG("commiting transaction\n");
|
||||
sqlite3_exec(global_database, "COMMIT TRANSACTION;", NULL, NULL, NULL);
|
||||
in_transaction = 0;
|
||||
if(transaction_lock == lock)
|
||||
{
|
||||
LOGGER_DEBUG("commiting transaction\n");
|
||||
sqlite3_exec(global_database, "COMMIT TRANSACTION;", NULL, NULL, NULL);
|
||||
transaction_lock = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
database_transaction_rollback()
|
||||
database_transaction_rollback(database_transaction_lock *lock)
|
||||
{
|
||||
LOGGER_DEBUG("rolling back transaction\n");
|
||||
sqlite3_exec(global_database, "ROLLBACK TRANSACTION;", NULL, NULL, NULL);
|
||||
in_transaction = 0;
|
||||
if(transaction_lock == lock)
|
||||
{
|
||||
LOGGER_DEBUG("rolling back transaction\n");
|
||||
sqlite3_exec(global_database, "ROLLBACK TRANSACTION;", NULL, NULL, NULL);
|
||||
transaction_lock = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue