ZF-2319: Support transactions in the pdo_mssql driver in Zend Framework

Description

The PDO driver in PHP for MSSQL unfortunately does not support transactions. However, due to the way that Zend Framework is designed we can support it anyway.


Index: C:/Development/ibt/portal/trunk/lib/ZendFramework/library/Zend/Db/Adapter/Pdo/Mssql.php
===================================================================
--- C:/Development/ibt/portal/trunk/lib/ZendFramework/library/Zend/Db/Adapter/Pdo/Mssql.php (revision 112)
+++ C:/Development/ibt/portal/trunk/lib/ZendFramework/library/Zend/Db/Adapter/Pdo/Mssql.php (revision 113)
@@ -314,4 +314,41 @@
         return (int)$this->fetchOne($sql);
     }
 
+    /**
+     * Begin a transaction.
+     *
+     * It is necessary to override the abstract PDO transaction functions here, as
+     * the PDO driver for MSSQL does not support transactions.
+     */
+    protected function _beginTransaction()
+    {
+        $this->_connect();
+        $this->_connection->exec('BEGIN TRANSACTION');
+        return true;
+    }
+
+    /**
+     * Commit a transaction.
+     *
+     * It is necessary to override the abstract PDO transaction functions here, as
+     * the PDO driver for MSSQL does not support transactions.
+     */
+    protected function _commit()
+    {
+        $this->_connect();
+        $this->_connection->exec('COMMIT TRANSACTION');
+        return true;
+    }
+
+    /**
+     * Roll-back a transaction.
+     *
+     * It is necessary to override the abstract PDO transaction functions here, as
+     * the PDO driver for MSSQL does not support transactions.
+     */
+    protected function _rollBack() {
+        $this->_connect();
+        $this->_connection->exec('ROLLBACK TRANSACTION');
+        return true;
+    }
 }

Please consider this for future Zend - it's extremely important for those of us who use MSSQL!

Comments

Integrated in the incubator with some other improvements related to MSSQL in the testbed made by Simon