Add a method for building an INTERVAL clause, and use it in kronolith migration
authorMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 4 Nov 2010 18:13:36 +0000 (14:13 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 4 Nov 2010 18:14:30 +0000 (14:14 -0400)
framework/SQL/SQL.php
kronolith/migration/3_kronolith_upgrade_addallday.php

index a44486c..d455aca 100644 (file)
@@ -176,6 +176,34 @@ class Horde_SQL {
     }
 
     /**
+     * Build appropriate INTERVAL clause for the database in use
+     *
+     * @param mixed $dbh
+     * @param string $interval
+     * @param string $precision
+     *
+     * @return string
+     */
+    public function buildIntervalClause($dbh, $interval, $precision)
+    {
+        $type = $dbh instanceof Horde_Db_Adapter ? Horde_String::lower($dbh->adapterName()) : $dbh->phptype;
+        var_dump($type);
+        switch ($type) {
+        case 'pgsql':
+        case 'pdo_postgresql':
+            $clause = 'INTERVAL \'' . $interval . ' ' . $precision . '\'';
+            break;
+        case 'oci8':
+            $clause = 'INTERVAL ' . $interval . '(' . $precision . ')';
+            break;
+        default:
+            $clause = 'INTERVAL ' . $interval . ' ' . $precision;
+        }
+
+        return $clause;
+    }
+
+    /**
      * Escapes all characters in a string that are placeholders for the
      * prepare/execute methods of the DB package.
      *
index 75ef3e4..446c868 100644 (file)
@@ -21,7 +21,7 @@ class KronolithUpgradeAddAllDay extends Horde_Db_Migration_Base
         $cols = $t->getColumns();
         if (!in_array('event_allday', array_keys($cols))) {
             $this->addColumn('kronolith_events', 'event_allday', 'integer', array('default' => 0));
-            $this->_connection->execute('UPDATE kronolith_events SET event_allday = 1 WHERE event_start + INTERVAL 1 DAY = event_end');
+            $this->_connection->execute('UPDATE kronolith_events SET event_allday = 1 WHERE event_start + ' . Horde_SQL::buildIntervalClause($this->_connection, '1 DAY') . ' = event_end');
         }
     }