classes to handle commands which are special for any database server
authorFlávio Gomes da Silva Lisboa <flaviogomesdasilva@yahoo.com.br>
Sun, 24 Jul 2011 21:02:36 +0000 (23:02 +0200)
committerLars Kneschke <l.kneschke@metaways.de>
Sun, 24 Jul 2011 21:02:36 +0000 (23:02 +0200)
tine20/Tinebase/Backend/Sql/Command.php [new file with mode: 0755]
tine20/Tinebase/Backend/Sql/Command/Interface.php [new file with mode: 0755]
tine20/Tinebase/Backend/Sql/Command/Mysql.php [new file with mode: 0755]
tine20/Tinebase/Backend/Sql/Command/Oracle.php [new file with mode: 0755]
tine20/Tinebase/Backend/Sql/Command/Pgsql.php [new file with mode: 0755]

diff --git a/tine20/Tinebase/Backend/Sql/Command.php b/tine20/Tinebase/Backend/Sql/Command.php
new file mode 100755 (executable)
index 0000000..114d26b
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+/**
+ * Tine 2.0
+ *
+ * @package     Tinebase
+ * @subpackage  Backend
+ * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
+ * @author      Flávio Gomes da Silva Lisboa <flavio.lisboa@serpro.gov.br>
+ * @copyright   Copyright (c) 2011-2011 Metaways Infosystems GmbH (http://www.metaways.de)
+ */
+
+/**
+ * encapsulates SQL commands that are different for each dialect
+ *
+ * @package     Tinebase
+ * @subpackage  Backend
+ */
+class Tinebase_Backend_Sql_Command implements Tinebase_Backend_Sql_Command_Interface
+{      
+       
+       private static function _getClassName($adapter)
+       {
+               $completeClassName = explode('_',get_class($adapter));
+               $className = $completeClassName[count($completeClassName)-1];
+               $className = str_replace('Oci','Oracle',$className);
+               return $className;              
+       }
+       
+       /**
+        * 
+        * @param $adapter Zend_Db_Adapter_Abstract
+        * @param $on boolean
+        */
+       public static function setAutocommit($adapter, $on)
+       {
+               $className = self::_getClassName($adapter);
+               $className = __CLASS__ . '_' . $className;
+               $command = new $className();
+
+               $command->setAutocommit($adapter,$on);          
+       }
+}
diff --git a/tine20/Tinebase/Backend/Sql/Command/Interface.php b/tine20/Tinebase/Backend/Sql/Command/Interface.php
new file mode 100755 (executable)
index 0000000..ee8410f
--- /dev/null
@@ -0,0 +1,26 @@
+<?php
+/**
+ * Tine 2.0
+ *
+ * @package     Tinebase
+ * @subpackage  Backend
+ * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
+ * @author      Flávio Gomes da Silva Lisboa <flavio.lisboa@serpro.gov.br>
+ * @copyright   Copyright (c) 2011-2011 Metaways Infosystems GmbH (http://www.metaways.de)
+ */
+
+/**
+ * encapsulates SQL commands that are different for each dialect
+ *
+ * @package     Tinebase
+ * @subpackage  Backend
+ */
+interface Tinebase_Backend_Sql_Command_Interface
+{      
+       /**
+        * 
+        * @param $adapter Zend_Db_Adapter_Abstract
+        * @param $on boolean
+        */
+       public static function setAutocommit($adapter,$on);
+}
diff --git a/tine20/Tinebase/Backend/Sql/Command/Mysql.php b/tine20/Tinebase/Backend/Sql/Command/Mysql.php
new file mode 100755 (executable)
index 0000000..c1991f2
--- /dev/null
@@ -0,0 +1,37 @@
+<?php
+/**
+ * Tine 2.0
+ *
+ * @package     Tinebase
+ * @subpackage  Backend
+ * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
+ * @author      Flávio Gomes da Silva Lisboa <flavio.lisboa@serpro.gov.br>
+ * @copyright   Copyright (c) 2011-2011 Metaways Infosystems GmbH (http://www.metaways.de)
+ */
+
+/**
+ * encapsulates SQL commands of Mysql database
+ *
+ * @package     Tinebase
+ * @subpackage  Backend
+ */
+class Tinebase_Backend_Sql_Command_Mysql implements Tinebase_Backend_Sql_Command_Interface
+{      
+       /**
+        * 
+        * @param $adapter Zend_Db_Adapter_Abstract
+        * @param $on boolean
+        */
+       public static function setAutocommit($adapter,$on)
+       {
+               // SET AUTOCOMMIT=0 is not supported for PostgreSQL
+               if ($on)
+               {
+                       $adapter->query('SET AUTOCOMMIT=1;');
+               }                               
+               else
+               {
+                       $adapter->query('SET AUTOCOMMIT=0;');
+               }
+       }
+}
diff --git a/tine20/Tinebase/Backend/Sql/Command/Oracle.php b/tine20/Tinebase/Backend/Sql/Command/Oracle.php
new file mode 100755 (executable)
index 0000000..c121723
--- /dev/null
@@ -0,0 +1,37 @@
+<?php
+/**
+ * Tine 2.0
+ *
+ * @package     Tinebase
+ * @subpackage  Backend
+ * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
+ * @author      Flávio Gomes da Silva Lisboa <flavio.lisboa@serpro.gov.br>
+ * @copyright   Copyright (c) 2011-2011 Metaways Infosystems GmbH (http://www.metaways.de)
+ */
+
+/**
+ * encapsulates SQL commands of Oracle database
+ *
+ * @package     Tinebase
+ * @subpackage  Backend
+ */
+class Tinebase_Backend_Sql_Command_Oracle implements Tinebase_Backend_Sql_Command_Interface
+{
+       /**
+        *
+        * @param $adapter Zend_Db_Adapter_Abstract
+        * @param $on boolean
+        */
+       public static function setAutocommit($adapter,$on)
+       {
+               // SET AUTOCOMMIT=0 is not supported for PostgreSQL
+               if ($on)
+               {
+                       $adapter->query('SET AUTOCOMMIT=1;');
+               }
+               else
+               {
+                       $adapter->query('SET AUTOCOMMIT=0;');
+               }
+       }
+}
diff --git a/tine20/Tinebase/Backend/Sql/Command/Pgsql.php b/tine20/Tinebase/Backend/Sql/Command/Pgsql.php
new file mode 100755 (executable)
index 0000000..fe1ea2e
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+/**
+ * Tine 2.0
+ *
+ * @package     Tinebase
+ * @subpackage  Backend
+ * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
+ * @author      Flávio Gomes da Silva Lisboa <flavio.lisboa@serpro.gov.br>
+ * @copyright   Copyright (c) 2011-2011 Metaways Infosystems GmbH (http://www.metaways.de)
+ */
+
+/**
+ * encapsulates SQL commands of PostgreSQL database
+ *
+ * @package     Tinebase
+ * @subpackage  Backend
+ */
+class Tinebase_Backend_Sql_Command_Pgsql implements Tinebase_Backend_Sql_Command_Interface
+{      
+       /**
+        * 
+        * @param $adapter Zend_Db_Adapter_Abstract
+        * @param $on boolean
+        */
+       public static function setAutocommit($adapter,$on)
+       {
+               // SET AUTOCOMMIT=0 is not supported for PostgreSQL
+               if ($on)
+               {
+                       $adapter->query('SET AUTOCOMMIT=1;');
+               }                               
+       }
+}