Implement LIMIT/OFFSET correctly for pgsql.
authorJan Schneider <jan@horde.org>
Wed, 5 Jan 2011 15:28:55 +0000 (16:28 +0100)
committerJan Schneider <jan@horde.org>
Wed, 5 Jan 2011 15:58:13 +0000 (16:58 +0100)
framework/Db/lib/Horde/Db/Adapter/Base.php
framework/Db/lib/Horde/Db/Adapter/Pdo/Pgsql.php

index ce12ef9..2cffb21 100644 (file)
@@ -644,10 +644,10 @@ abstract class Horde_Db_Adapter_Base implements Horde_Db_Adapter
     }
 
     /**
-     * Appends +LIMIT+ and +OFFSET+ options to a SQL statement.
+     * Appends LIMIT and OFFSET options to a SQL statement.
      *
      * @param string $sql     SQL statement.
-     * @param array $options  TODO
+     * @param array $options  Hash with 'limit' and (optional) 'offset' values.
      *
      * @return string
      */
index 8d306f3..0fa2e4a 100644 (file)
@@ -172,6 +172,25 @@ class Horde_Db_Adapter_Pdo_Pgsql extends Horde_Db_Adapter_Pdo_Base
         }
     }
 
+    /**
+     * Appends LIMIT and OFFSET options to a SQL statement.
+     *
+     * @param string $sql     SQL statement.
+     * @param array $options  Hash with 'limit' and (optional) 'offset' values.
+     *
+     * @return string
+     */
+    public function addLimitOffset($sql, $options)
+    {
+        if (isset($options['limit']) && $limit = $options['limit']) {
+            $sql .= " LIMIT $limit";
+        }
+        if (isset($options['offset']) && $offset = $options['offset']) {
+            $sql .= " OFFSET $offset";
+        }
+        return $sql;
+    }
+
 
     /*##########################################################################
     # Protected