Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1.  
  2.     /**
  3.      * Adds an adapter-specific LIMIT clause to the SELECT statement.
  4.      *
  5.      * @param string $sql
  6.      * @param integer $count
  7.      * @param integer $offset OPTIONAL
  8.      * @return string
  9.      * @throws Zend_Db_Adapter_Oracle_Exception
  10.      */
  11.     public function limit($sql, $count, $offset = 0)
  12.     {
  13.         $count = intval($count);
  14.         if ($count <= 0) {
  15.             /**
  16.              * @see Zend_Db_Adapter_Oracle_Exception
  17.              */
  18.             require_once 'Zend/Db/Adapter/Oracle/Exception.php';
  19.             throw new Zend_Db_Adapter_Oracle_Exception("LIMIT argument count=$count is not valid");
  20.         }
  21.  
  22.         $offset = intval($offset);
  23.         if ($offset < 0) {
  24.             /**
  25.              * @see Zend_Db_Adapter_Oracle_Exception
  26.              */
  27.             require_once 'Zend/Db/Adapter/Oracle/Exception.php';
  28.             throw new Zend_Db_Adapter_Oracle_Exception("LIMIT argument offset=$offset is not valid");
  29.         }
  30.  
  31.         /**
  32.          * Oracle does not implement the LIMIT clause as some RDBMS do.
  33.          * We have to simulate it with subqueries and ROWNUM.
  34.          * Unfortunately because we use the column wildcard "*",
  35.          * this puts an extra column into the query result set.
  36.          */
  37.         $limit_sql = "SELECT z2.*
  38.            FROM (
  39.                SELECT z1.*, ROWNUM AS \"zend_db_rownum\"
  40.                FROM (
  41.                    " . $sql . "
  42.                ) z1
  43.            ) z2
  44.            WHERE z2.\"zend_db_rownum\" BETWEEN " . ($offset+1) . " AND " . ($offset+$count);
  45.         return $limit_sql;
  46.     }