From db67f078e764301e8af953887b06d3c591d68a78 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 29 Jan 2006 07:47:21 +0000 Subject: [PATCH] The DB::transaction_rollback() now has name as optional, to just rollback the entire transaction --- db_mysql.php | 4 ++-- db_mysqli.php | 4 ++-- db_postgresql.php | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/db_mysql.php b/db_mysql.php index e12b013..47bb605 100644 --- a/db_mysql.php +++ b/db_mysql.php @@ -211,9 +211,9 @@ class DB_MySQL extends DB_Abstract * * @param string Named savepoint */ - function transaction_rollback($name) + function transaction_rollback($name = null) { - $this->query("ROLLBACK TO SAVEPOINT $name"); + $this->query("ROLLBACK" . ($name != null ? " TO SAVEPOINT $name" : "")); } // ################################################################### diff --git a/db_mysqli.php b/db_mysqli.php index fe1cb5a..c3e1dfb 100644 --- a/db_mysqli.php +++ b/db_mysqli.php @@ -131,9 +131,9 @@ class DB_MySQLi extends DB_Abstract * * @param string Named savepoint */ - function transaction_rollback($name) + function transaction_rollback($name = null) { - $this->query("ROLLBACK TO SAVEPOINT $name"); + $this->query("ROLLBACK" . ($name != null ? " TO SAVEPOINT $name" : "")); } // ################################################################### diff --git a/db_postgresql.php b/db_postgresql.php index a01b5f2..3c265ea 100644 --- a/db_postgresql.php +++ b/db_postgresql.php @@ -232,6 +232,54 @@ class DB_PostgreSQL extends DB_Abstract $temp = $this->query_first("SELECT last_value FROM {$table}_{$field}_seq"); return $temp['last_value']; } + + // ################################################################### + /** + * Starts a database transaction + * + * @access public + */ + function transaction_start() + { + $this->query("BEGIN"); + } + + // ################################################################### + /** + * 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 = null) + { + $this->query("ROLLBACK" . ($name != null ? " TO $name" : "")); + } + + // ################################################################### + /** + * Commits a database transaction + * + * @access public + */ + function transaction_commit() + { + $this->query("COMMIT"); + } } /*=====================================================================*\ -- 2.43.5