database: Add support for serializable transactions

This commit is contained in:
Tobias Brunner
2013-10-11 15:29:10 +02:00
parent e745f5f69f
commit b283a6e9ef
4 changed files with 27 additions and 9 deletions
@@ -652,7 +652,7 @@ METHOD(database_t, execute, int,
}
METHOD(database_t, transaction, bool,
private_mysql_database_t *this)
private_mysql_database_t *this, bool serializable)
{
transaction_t *trans = NULL;
conn_t *conn;
@@ -669,6 +669,17 @@ METHOD(database_t, transaction, bool,
}
/* these statements are not supported in prepared statements that are used
* by the execute() method */
if (serializable)
{
if (mysql_query(conn->mysql,
"SET TRANSACTION ISOLATION LEVEL SERIALIZABLE") != 0)
{
DBG1(DBG_LIB, "starting transaction failed: %s",
mysql_error(conn->mysql));
conn_release(this, conn);
return FALSE;
}
}
if (mysql_query(conn->mysql, "START TRANSACTION") != 0)
{
DBG1(DBG_LIB, "starting transaction failed: %s",
@@ -305,9 +305,11 @@ METHOD(database_t, execute, int,
}
METHOD(database_t, transaction, bool,
private_sqlite_database_t *this)
private_sqlite_database_t *this, bool serializable)
{
transaction_t *trans;
char *cmd = serializable ? "BEGIN EXCLUSIVE TRANSACTION"
: "BEGIN TRANSACTION";
trans = this->transaction->get(this->transaction);
if (trans)
@@ -315,7 +317,7 @@ METHOD(database_t, transaction, bool,
ref_get(&trans->refs);
return TRUE;
}
if (execute(this, NULL, "BEGIN EXCLUSIVE TRANSACTION") == -1)
if (execute(this, NULL, cmd) == -1)
{
return FALSE;
}