Author: ts Date: Fri Jan 18 10:14:57 2008 New Revision: 7172 Log: - Made transactions in ezcPersistentSession->performQuery() optional. # A transaction when performing a SELECT query does not makes sense and in some # cases transactions are handled explicitly. With ezcPersistentFindIterator # they can also produce errors with SQLite when used with a SELECT statement.
Modified: trunk/PersistentObject/src/handlers/delete_handler.php trunk/PersistentObject/src/handlers/save_handler.php trunk/PersistentObject/src/persistent_session.php Modified: trunk/PersistentObject/src/handlers/delete_handler.php ============================================================================== --- trunk/PersistentObject/src/handlers/delete_handler.php [iso-8859-1] (original) +++ trunk/PersistentObject/src/handlers/delete_handler.php [iso-8859-1] Fri Jan 18 10:14:57 2008 @@ -189,7 +189,7 @@ ) ); } - $this->session->performQuery( $q ); + $this->session->performQuery( $q, true ); break; } @@ -215,7 +215,7 @@ */ public function deleteFromQuery( ezcQueryDelete $query ) { - $this->session->performQuery( $query ); + $this->session->performQuery( $query, true ); } /** Modified: trunk/PersistentObject/src/handlers/save_handler.php ============================================================================== --- trunk/PersistentObject/src/handlers/save_handler.php [iso-8859-1] (original) +++ trunk/PersistentObject/src/handlers/save_handler.php [iso-8859-1] Fri Jan 18 10:14:57 2008 @@ -235,7 +235,7 @@ */ public function updateFromQuery( ezcQueryUpdate $query ) { - $this->session->performQuery( $query ); + $this->session->performQuery( $query, true ); } /** @@ -418,7 +418,7 @@ ) ); - $this->session->performQuery( $q ); + $this->session->performQuery( $q, true ); } /** @@ -530,7 +530,7 @@ $insertColumns[] = $map->relationDestinationColumn; } } - $this->session->performQuery( $q ); + $this->session->performQuery( $q, true ); } } Modified: trunk/PersistentObject/src/persistent_session.php ============================================================================== --- trunk/PersistentObject/src/persistent_session.php [iso-8859-1] (original) +++ trunk/PersistentObject/src/persistent_session.php [iso-8859-1] Fri Jan 18 10:14:57 2008 @@ -617,31 +617,45 @@ * Performs the given query. * * Performs the $query, checks for errors and throws an exception in case. - * Returns the generated statement object on success. + * Returns the generated statement object on success. If the $transaction + * parameter is set to true, the query is excuted transaction save. * * @param ezcQuery $q + * @param bool $transaction * @return PDOStatement * * @access private */ - public function performQuery( ezcQuery $q ) - { - $this->database->beginTransaction(); + public function performQuery( ezcQuery $q, $transaction = false ) + { + if ( $transaction ) + { + $this->database->beginTransaction(); + } try { $stmt = $q->prepare(); $stmt->execute(); if ( ( $errCode = $stmt->errorCode() ) != 0 ) { - $this->database->rollback(); + if ( $transaction ) + { + $this->database->rollback(); + } throw new ezcPersistentQueryException( "The query returned error code $errCode.", $q ); } - $this->database->commit(); + if ( $transaction ) + { + $this->database->commit(); + } return $stmt; } catch ( PDOException $e ) { - $this->database->rollback(); + if ( $transaction ) + { + $this->database->rollback(); + } throw new ezcPersistentQueryException( $e->getMessage(), $q ); } } -- svn-components mailing list svn-components@lists.ez.no http://lists.ez.no/mailman/listinfo/svn-components