From 4ebd7ca0799bff76ea8cbd00860714fc47b42779 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 29 Jan 2006 06:24:22 +0000 Subject: [PATCH] Adding transaction stuff to everything but PGSQL (need to look it up) --- db.php | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ db_mysql.php | 48 +++++++++++++++++++++++++++++++++++++++++++++ db_mysqli.php | 48 +++++++++++++++++++++++++++++++++++++++++++++ dev/changes.txt | 1 + 4 files changed, 149 insertions(+) diff --git a/db.php b/db.php index b7ee77c..050c3f9 100644 --- a/db.php +++ b/db.php @@ -358,6 +358,58 @@ class DB_Abstract return call_user_func($this->commands['affected_rows'], $result); } + // ################################################################### + /** + * Sends the command to start a transaction. This command should never + * be reached as it's always overridden + * + * @access public + */ + function transaction_start() + { + trigger_error('DB_Abstract::transaction_start() needs to be overridden when subclassed', E_USER_ERROR); + } + + // ################################################################### + /** + * Sends the command to set this as a savepoint. This command should never + * be reached as it's always overridden + * + * @access public + * + * @param string Named savepoint + */ + function transaction_savepoint($name) + { + trigger_error('DB_Abstract::transaction_savepoint() needs to be overridden when subclassed', E_USER_ERROR); + } + + // ################################################################### + /** + * Sends the command to rollback to a given savepoint. This command + * should never be reached as it's always overridden + * + * @access public + * + * @param string Named savepoint + */ + function transaction_rollback($name) + { + trigger_error('DB_Abstract::transaction_rollback() needs to be overridden when subclassed', E_USER_ERROR); + } + + // ################################################################### + /** + * Sends the command to commit the entire transaction. This command + * should never be reached as it's always overridden + * + * @access public + */ + function transaction_commit($name) + { + trigger_error('DB_Abstract::transaction_commit() needs to be overridden when subclassed', E_USER_ERROR); + } + // ################################################################### /** * Constructs a table of query information output that is used in some diff --git a/db_mysql.php b/db_mysql.php index 64d1d61..e12b013 100644 --- a/db_mysql.php +++ b/db_mysql.php @@ -178,6 +178,54 @@ class DB_MySQL extends DB_Abstract return mysql_escape_string($string); } } + + // ################################################################### + /** + * Starts a database transaction + * + * @access public + */ + function transaction_start() + { + $this->query("BEGIN WORK"); + } + + // ################################################################### + /** + * Saves current transaction steps as a savepoint + * + * @access public + * + * @param string Named savepoint + */ + function transaction_savepoint($name) + { + $this->query("SAVEPOINT $name"); + } + + // ################################################################### + /** + * Reverts a transaction back to a given savepoint + * + * @access public + * + * @param string Named savepoint + */ + function transaction_rollback($name) + { + $this->query("ROLLBACK TO SAVEPOINT $name"); + } + + // ################################################################### + /** + * Commits a database transaction + * + * @access public + */ + function transaction_commit() + { + $this->query("COMMIT"); + } } /*=====================================================================*\ diff --git a/db_mysqli.php b/db_mysqli.php index a58e5b0..fe1cb5a 100644 --- a/db_mysqli.php +++ b/db_mysqli.php @@ -98,6 +98,54 @@ class DB_MySQLi extends DB_Abstract { return mysqli_connect($server, $user, $password, $database); } + + // ################################################################### + /** + * Starts a database transaction + * + * @access public + */ + function transaction_start() + { + $this->query("START TRANSACTION"); + } + + // ################################################################### + /** + * Saves current transaction steps as a savepoint + * + * @access public + * + * @param string Named savepoint + */ + function transaction_savepoint($name) + { + $this->query("SAVEPOINT $name"); + } + + // ################################################################### + /** + * Reverts a transaction back to a given savepoint + * + * @access public + * + * @param string Named savepoint + */ + function transaction_rollback($name) + { + $this->query("ROLLBACK TO SAVEPOINT $name"); + } + + // ################################################################### + /** + * Commits a database transaction + * + * @access public + */ + function transaction_commit() + { + $this->query("COMMIT"); + } } /*=====================================================================*\ diff --git a/dev/changes.txt b/dev/changes.txt index 73143cb..a4368e0 100644 --- a/dev/changes.txt +++ b/dev/changes.txt @@ -31,3 +31,4 @@ CHANGELOG FOR 2.0 - Optimized the rand() function [functions.php] - Objects no longer use $_isso as a call back, but rather $this->registry (in objects) or $GLOBALS['isso:callback'] (in global scope) - Added explain_error_reporting() so you can get an overview of all the constants and if they're enabled [kernel.php] +- Added transaction capabilities to database layers \ No newline at end of file -- 2.22.5