aboutsummaryrefslogtreecommitdiffstats
path: root/src/libhydra/plugins/attr_sql/sql_attribute.c
diff options
context:
space:
mode:
authorTobias Brunner <tobias@strongswan.org>2013-10-11 15:29:30 +0200
committerTobias Brunner <tobias@strongswan.org>2013-10-11 15:29:30 +0200
commit6d7710a7441dbb3fb839f8c0d04e4c89fc595e3d (patch)
tree5a10d4f4fcbb3af8250ccc6cf16d32da6085a473 /src/libhydra/plugins/attr_sql/sql_attribute.c
parentec91f15e3ba3e622c3bc206c0eeac7c35bfd8ce8 (diff)
parentbd085dd978b2dc7891c0d8486dd883e76e15e9a3 (diff)
downloadstrongswan-6d7710a7441dbb3fb839f8c0d04e4c89fc595e3d.tar.bz2
strongswan-6d7710a7441dbb3fb839f8c0d04e4c89fc595e3d.tar.xz
Merge branch 'database-transactions'
This adds support for transactions to the database_t interface and the two current implementations. The pool utility is also moved to its own directory in src/.
Diffstat (limited to 'src/libhydra/plugins/attr_sql/sql_attribute.c')
-rw-r--r--src/libhydra/plugins/attr_sql/sql_attribute.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/src/libhydra/plugins/attr_sql/sql_attribute.c b/src/libhydra/plugins/attr_sql/sql_attribute.c
index e91e1ed15..0a06c419f 100644
--- a/src/libhydra/plugins/attr_sql/sql_attribute.c
+++ b/src/libhydra/plugins/attr_sql/sql_attribute.c
@@ -51,15 +51,16 @@ static u_int get_identity(private_sql_attribute_t *this, identification_t *id)
enumerator_t *e;
u_int row;
+ this->db->transaction(this->db, TRUE);
/* look for peer identity in the identities table */
e = this->db->query(this->db,
"SELECT id FROM identities WHERE type = ? AND data = ?",
DB_INT, id->get_type(id), DB_BLOB, id->get_encoding(id),
DB_UINT);
-
if (e && e->enumerate(e, &row))
{
e->destroy(e);
+ this->db->commit(this->db);
return row;
}
DESTROY_IF(e);
@@ -68,8 +69,10 @@ static u_int get_identity(private_sql_attribute_t *this, identification_t *id)
"INSERT INTO identities (type, data) VALUES (?, ?)",
DB_INT, id->get_type(id), DB_BLOB, id->get_encoding(id)) == 1)
{
+ this->db->commit(this->db);
return row;
}
+ this->db->rollback(this->db);
return 0;
}
@@ -346,8 +349,6 @@ METHOD(attribute_provider_t, create_attribute_enumerator, enumerator_t*,
u_int count;
char *name;
- this->db->execute(this->db, NULL, "BEGIN EXCLUSIVE TRANSACTION");
-
/* in a first step check for attributes that match name and id */
if (id)
{
@@ -418,8 +419,6 @@ METHOD(attribute_provider_t, create_attribute_enumerator, enumerator_t*,
pool_enumerator->destroy(pool_enumerator);
}
- this->db->execute(this->db, NULL, "END TRANSACTION");
-
/* lastly try to find global attributes */
if (!attr_enumerator)
{
@@ -474,4 +473,3 @@ sql_attribute_t *sql_attribute_create(database_t *db)
DB_UINT, now);
return &this->public;
}
-