From: Michael J. Rubinsky Date: Thu, 4 Nov 2010 18:13:36 +0000 (-0400) Subject: Add a method for building an INTERVAL clause, and use it in kronolith migration X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=e7c53aba1e8889c05e85d680ea85d46b4fbd80b0;p=horde.git Add a method for building an INTERVAL clause, and use it in kronolith migration --- diff --git a/framework/SQL/SQL.php b/framework/SQL/SQL.php index a44486c75..d455aca24 100644 --- a/framework/SQL/SQL.php +++ b/framework/SQL/SQL.php @@ -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. * diff --git a/kronolith/migration/3_kronolith_upgrade_addallday.php b/kronolith/migration/3_kronolith_upgrade_addallday.php index 75ef3e45b..446c868d8 100644 --- a/kronolith/migration/3_kronolith_upgrade_addallday.php +++ b/kronolith/migration/3_kronolith_upgrade_addallday.php @@ -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'); } }