openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit beda5d016713368fc5e6e38a1c15cebf67170787
parent 1d6c8cfbfb8bc648496073b28da3cfcde69288a7
Author: dankert <devnull@localhost>
Date:   Tue,  6 Oct 2009 22:32:37 +0200

Die Datenbank-Abstraktionsschicht ist nun transaktionsfähig.

Diffstat:
db/db.class.php | 39++++++++++++++++++++++++++++++++++++++-
db/mysql.class.php | 28++++++++++++++++++++++++++++
db/postgresql.class.php | 38+++++++++++++++++++++++++++++++++-----
objectClasses/Project.class.php | 26++++++++++++++++----------
4 files changed, 115 insertions(+), 16 deletions(-)

diff --git a/db/db.class.php b/db/db.class.php @@ -201,7 +201,11 @@ class DB die('Database Error (not prepared):<pre style="color:red">'.$this->error.'</pre>'); } } - + + if ( @$this->conf['autocommit']) + if ( method_exists($this->client,'commit') ) + $this->client->commit(); + return new DB_result( $this->client,$result ); } @@ -367,6 +371,39 @@ class DB return $results; } + + + /** + * Startet eine Transaktion. + */ + function start() + { + if ( @$this->conf['transaction']) + if ( method_exists($this->client,'start') ) + $this->client->start(); + } + + + /** + * Beendet eine Transaktion. + */ + function commit() + { + if ( @$this->conf['transaction']) + if ( method_exists($this->client,'commit') ) + $this->client->commit(); + } + + /** + * Beendet eine Transaktion. + */ + function rollback() + { + if ( @$this->conf['transaction']) + if ( method_exists($this->client,'rollback') ) + $this->client->rollback(); + } + } diff --git a/db/mysql.class.php b/db/mysql.class.php @@ -134,6 +134,34 @@ class DB_mysql { return mysql_num_rows($result); } + + + /** + * Startet eine Transaktion. + */ + function start() + { + mysql_query('BEGIN', $this->connection); + } + + + /** + * Beendet eine Transaktion. + */ + function commit() + { + mysql_query('COMMIT', $this->connection); + } + + + /** + * Bricht eine Transaktion ab. + */ + function rollback() + { + mysql_query('ROLLBACK', $this->connection); + } + } ?> \ No newline at end of file diff --git a/db/postgresql.class.php b/db/postgresql.class.php @@ -79,20 +79,48 @@ class DB_postgresql - /** - * Verbindung schlie�en. - * - * @return unknown + /** + * Verbindung schlie�en. + * + * @return unknown */ function disconnect() { - $ret = pg_close( $this->connection ); + $ret = pg_query( $this->connection ); $this->connection = null; return $ret; } + /** + * Startet eine Transaktion. + */ + function start() + { + @pg_exec( $this->connection,"BEGIN WORK" ); + } + + + /** + * Beendet eine Transaktion. + */ + function commit() + { + @pg_exec( $this->connection,"COMMIT" ); + } + + + /** + * Bricht eine Transaktion ab. + */ + function rollback() + { + @pg_exec( $this->connection,"ROLLBACK" ); + } + + + function query($query) { //Html::debug($query,'query()'); diff --git a/objectClasses/Project.class.php b/objectClasses/Project.class.php @@ -268,16 +268,20 @@ class Project function save() { $db = db_connection(); - - $sql = new Sql( 'UPDATE {t_project}'. - ' SET name = {name},'. - ' target_dir = {target_dir},'. - ' ftp_url = {ftp_url}, '. - ' ftp_passive = {ftp_passive}, '. - ' cut_index = {cut_index}, '. - ' content_negotiation = {content_negotiation}, '. - ' cmd_after_publish = {cmd_after_publish} '. - 'WHERE id= {projectid} ' ); + $db->start(); + + $sql = new Sql( <<<SQL + UPDATE {t_project} + SET name = {name}, + target_dir = {target_dir}, + ftp_url = {ftp_url}, + ftp_passive = {ftp_passive}, + cut_index = {cut_index}, + content_negotiation = {content_negotiation}, + cmd_after_publish = {cmd_after_publish} + WHERE id= {projectid} +SQL +); $sql->setString('name' ,$this->name ); $sql->setString('target_dir' ,$this->target_dir ); @@ -289,6 +293,8 @@ class Project $sql->setInt ('projectid' ,$this->projectid ); $db->query( $sql ); + $db->commit(); + $db->rollback; $rootFolder = new Folder( $this->getRootObjectId() ); $rootFolder->load();