Merge branch '2014.11-develop' into 2015.11
[tine20] / tine20 / Tinebase / Backend / Sql / Command / Pgsql.php
index 5e31e10..e8ce604 100755 (executable)
@@ -6,7 +6,7 @@
  * @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-2014 Metaways Infosystems GmbH (http://www.metaways.de)
+ * @copyright   Copyright (c) 2011-2015 Metaways Infosystems GmbH (http://www.metaways.de)
  */
 
 /**
 class Tinebase_Backend_Sql_Command_Pgsql implements Tinebase_Backend_Sql_Command_Interface
 {
     /**
-     * @var Zend_Db_Adapter_Abstract
+     * @var Tinebase_Backend_Sql_Adapter_Pdo_Pgsql
      */
     protected $_adapter;
     
     /**
-     * @param Zend_Db_Adapter_Abstract $adapter
+     * @param Tinebase_Backend_Sql_Adapter_Pdo_Pgsql $adapter
      */
-    public function __construct(Zend_Db_Adapter_Abstract $adapter)
+    public function __construct(Tinebase_Backend_Sql_Adapter_Pdo_Pgsql $adapter)
     {
         $this->_adapter = $adapter;
     }
@@ -188,10 +188,15 @@ class Tinebase_Backend_Sql_Command_Pgsql implements Tinebase_Backend_Sql_Command
             if (isset($session->dbcapabilities) && (isset($session->dbcapabilities['unaccent']) || array_key_exists('unaccent', $session->dbcapabilities))) {
                 $result = $session->dbcapabilities['unaccent'];
             } else {
-                $result = 0;
+                $result = $this->_adapter->hasUnaccentExtension();
+                
+                $capabilities['unaccent'] = $result;
+                
+                $session->dbcapabilities = $capabilities;
             }
+            
         } catch (Zend_Session_Exception $zse) {
-            $result = 0;
+            $result = $this->_adapter->hasUnaccentExtension();
         }
         
         return $result;
@@ -230,4 +235,31 @@ class Tinebase_Backend_Sql_Command_Pgsql implements Tinebase_Backend_Sql_Command
      {
 
      }
+
+    /**
+     * returns something similar to "(interval '$staticPart $timeUnit' * $dynamicPart)"
+     *
+     * @see http://www.postgresql.org/docs/9.1/static/functions-datetime.html
+     *
+     * @param string $timeUnit
+     * @param string $staticPart
+     * @param string $dynamicPart
+     * @return string
+     */
+    public function getDynamicInterval($timeUnit, $staticPart, $dynamicPart)
+    {
+        return '(' . $this->getInterval($timeUnit, $staticPart) .  ' * ' . $dynamicPart . ')';
+    }
+
+    /**
+     * returns something similar to "interval '$staticPart $timeUnit'"
+     *
+     * @param string $timeUnit
+     * @param string $staticPart
+     * @return string
+     */
+    public function getInterval($timeUnit, $staticPart)
+    {
+        return "INTERVAL '" . $staticPart . ' ' . $timeUnit . "'";
+    }
 }