Add transaction helpers to query class.

This commit is contained in:
Andrew McMillan 2010-03-03 14:29:47 +13:00
parent ecf57ce54e
commit e2ff9b575b
2 changed files with 38 additions and 0 deletions

View File

@ -95,6 +95,7 @@ class AwlDatabase extends AwlDBDialect {
else {
trigger_error("Cannot begin a transaction while a transaction is already active.", E_USER_ERROR);
}
return true;
}
@ -106,6 +107,7 @@ class AwlDatabase extends AwlDBDialect {
$this->db->commit();
$this->txnstate = 0;
}
return true;
}
@ -120,6 +122,7 @@ class AwlDatabase extends AwlDBDialect {
else {
trigger_error("Cannot rollback unless a transaction is already active.", E_USER_ERROR);
}
return true;
}

View File

@ -358,6 +358,41 @@ class AwlQuery
}
/**
* Wrap the parent DB class Begin() so we can $qry->Begin() sometime before we $qry->Exec()
*/
public function Begin() {
global $_awl_dbconn;
if ( !isset($this->connection) ) {
if ( !isset($_awl_dbconn) ) _awl_connect_configured_database();
$this->connection = $_awl_dbconn;
}
return $this->connection->Begin();
}
/**
* Wrap the parent DB class Commit() so we can $qry->Commit() sometime after we $qry->Exec()
*/
public function Commit() {
if ( !isset($this->connection) ) {
trigger_error("Cannot commit a transaction without an active statement.", E_USER_ERROR);
}
return $this->connection->Commit();
}
/**
* Wrap the parent DB class Rollback() so we can $qry->Rollback() sometime after we $qry->Exec()
*/
public function Rollback() {
if ( !isset($this->connection) ) {
trigger_error("Cannot rollback a transaction without an active statement.", E_USER_ERROR);
}
return $this->connection->Rollback();
}
/**
* Execute the query, logging any debugging.
*