remaining LIMIT to queryLimit() changes
authorMichael J. Rubinsky <mrubinsk@horde.org>
Wed, 28 Jul 2010 15:17:53 +0000 (11:17 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Wed, 28 Jul 2010 15:17:53 +0000 (11:17 -0400)
fima/lib/Driver/sql.php
folks/lib/Driver/sql.php
news/lib/Block/category.php
news/lib/Block/last.php
news/lib/Block/last_blogs.php
news/lib/Block/most_commented.php
news/lib/Block/most_read.php
skoli/lib/Driver/sql.php

index 7ebda33..9524b8a 100644 (file)
@@ -252,16 +252,15 @@ class Fima_Driver_sql extends Fima_Driver {
                 $limit[0] += ceil($this->_postingsCount / $limit[1]) + 1;
             }
             $limit[0] = ($limit[0] - 1) * $limit[1];
-
-            $query .= ' LIMIT ' . $limit[0];
-            if (isset($limit[1])) {
-                $query .= ', ' . $limit[1];
-            }
+            /* Log the query at a DEBUG log level. */
+            Horde::logMessage(sprintf('Fima_Driver_sql::retrievePostings() limitQuery: %s', $query), 'DEBUG');
+            $result = $this->_db->queryLimit($query, $limit[0], $limit[1], $values);
+        } else {
+            /* Log the query at a DEBUG log level. */
+            Horde::logMessage(sprintf('Fima_Driver_sql::retrievePostings(): %s', $query), 'DEBUG');
+            $result = $this->_db->query($query, $values);
         }
 
-        /* Log the query at a DEBUG log level. */
-        Horde::logMessage(sprintf('Fima_Driver_sql::retrievePostings(): %s', $query), 'DEBUG');
-
         /* Execute the query. */
         $result = $this->_db->query($query, $values);
         if (isset($result) && !is_a($result, 'PEAR_Error')) {
index 1511802..6777d50 100644 (file)
@@ -77,9 +77,11 @@ class Folks_Driver_sql extends Folks_Driver {
     {
         $sql = 'SELECT user_uid FROM ' . $this->_params['online']
             . ' WHERE user_uid <> "" AND user_uid <> "0" '
-            . ' ORDER BY time_last_click DESC LIMIT 0, ' . (int)$limit;
+            . ' ORDER BY time_last_click DESC';
 
-        return $this->_db->getCol($sql);
+        $result = $this->_db->limitQuery($sql, 0, $limit);
+        $value = $result->fetchRow(DB_FETCHMODE_ORDERED);
+        return $value[0];
     }
 
     /**
@@ -94,13 +96,15 @@ class Folks_Driver_sql extends Folks_Driver {
     {
         if ($online) {
             $sql = 'SELECT u.user_uid FROM ' . $this->_params['table'] . ' u, .' . $this->_params['online'] . ' o '
-                . ' WHERE u.user_picture = 1 AND o.user_uid = u.user_uid ORDER BY RAND() LIMIT 0, ' . (int)$limit;
+                . ' WHERE u.user_picture = 1 AND o.user_uid = u.user_uid ORDER BY RAND()';
         } else {
             $sql = 'SELECT user_uid FROM ' . $this->_params['table']
-                . ' WHERE user_picture = 1 ORDER BY RAND() LIMIT 0, ' . (int)$limit;
-        }
+                . ' WHERE user_picture = 1 ORDER BY RAND()';
+        
+        $result = $this->_db->limitQuery($sql, 0, $limit);
+        $value = $result->fetchRow(DB_FETCHMODE_ORDERED);
 
-        return $this->_db->getCol($sql);
+        return $value[0];
     }
 
     /**
index b16c8f2..8b04ef6 100755 (executable)
@@ -45,15 +45,17 @@ class Horde_Block_News_category extends Horde_Block {
                  'n.status = ? AND n.publish <= NOW() ' .
                  'AND (n.category1 = ? OR n.category2 = ?) ' .
                  'AND nl.lang = ? AND n.id = nl.id ' .
-                 'ORDER BY n.publish DESC ' .
-                 'LIMIT 0, ' . $this->_params['limit'];
+                 'ORDER BY n.publish DESC';
 
         $params = array(News::CONFIRMED, $this->_params['category'], $this->_params['category'], $GLOBALS['registry']->preferredLang());
-        $rows = $GLOBALS['news']->db->getAll($query, $params, DB_FETCHMODE_ASSOC);
-        if ($rows instanceof PEAR_Error) {
-            return $rows->getDebugInfo();
+        $res = $GLOBALS['news']->db->limitQuery($query, 0, $this->_params['limit'], $params);
+        if ($res instanceof PEAR_Error) {
+            return $res->getDebugInfo();
+        }
+        $rows = array();
+        while ($res->fetchInto($row, DB_FETCHMODE_ASSOC)) {
+            $rows[$row['id']] = $row;
         }
-
         $view = new News_View();
         $view->news = $rows;
         $view->moreurl = Horde_Util::addParameter(Horde::applicationUrl('browse.php'), 'category', $this->_params['category']);
index 32cec81..30787d5 100755 (executable)
@@ -44,14 +44,15 @@ class Horde_Block_News_last extends Horde_Block {
             $params[] = (int)$this->_params['category'];
         }
 
-        $query .= 'ORDER BY n.publish DESC ' .
-                 'LIMIT 0, ' . $this->_params['limit'];
-
-        $rows = $GLOBALS['news']->db->getAll($query, $params, DB_FETCHMODE_ASSOC);
-        if ($rows instanceof PEAR_Error) {
-            return $rows->getDebugInfo();
+        $query .= 'ORDER BY n.publish DESC';
+        $res = $GLOBALS['news']->db->queryLimit($query, 0, $this->_params['limit'], $params);
+        if ($res instanceof PEAR_Error) {
+            return $res->getDebugInfo();
+        }
+        $rows = array();
+        while ($res->fetchInto($row, DB_FETCHMODE_ASSOC)) {
+            $rows[$row['id']] = $row;
         }
-
         $view = new News_View();
         $view->news = $rows;
         $view->moreurl = Horde::applicationUrl('browse.php');
index 4521f71..360e53c 100755 (executable)
@@ -30,15 +30,16 @@ class Horde_Block_News_last_blogs extends Horde_Block {
                  'FROM ' . $GLOBALS['news']->prefix . ' AS n, ' . $GLOBALS['news']->prefix . '_body AS nl WHERE ' .
                  'n.status = ? AND n.publish <= NOW() AND n.trackbacks > ? ' .
                  'AND nl.lang = ? AND n.id = nl.id ' .
-                 'ORDER BY n.publish DESC ' .
-                 'LIMIT 0, ' . $this->_params['limit'];
+                 'ORDER BY n.publish DESC';
 
         $params = array(News::CONFIRMED, 0, $GLOBALS['registry']->preferredLang());
-        $rows = $GLOBALS['news']->db->getAll($query, $params, DB_FETCHMODE_ASSOC);
-        if ($rows instanceof PEAR_Error) {
-            return $rows->getDebugInfo();
+        $res = $GLOBALS['news']->db->limitQuery($query, 0, $this->_params['limit'], $params);
+        if ($res instanceof PEAR_Error) {
+            return $res->getDebugInfo();
+        }
+        while ($res->fetchInto($row, DB_FETCHMODE_ASSOC)) {
+            $rows[$row['id']] = $row;
         }
-
         $view = new News_View();
         $view->news = $rows;
 
index 89779bc..e683c95 100755 (executable)
@@ -35,16 +35,18 @@ class Horde_Block_News_most_commented extends Horde_Block {
                  'FROM ' . $GLOBALS['news']->prefix . ' AS n, ' . $GLOBALS['news']->prefix . '_body AS nl WHERE ' .
                  'n.status = ? AND n.publish <= NOW()  AND n.publish > ?' .
                  'AND nl.lang = ? AND n.id = nl.id ' .
-                 'ORDER BY n.comments DESC ' .
-                 'LIMIT 0, ' . $this->_params['limit'];
+                 'ORDER BY n.comments DESC ';
 
         $younger = $_SERVER['REQUEST_TIME'] - $this->_params['days'] * 86400;
         $params = array(News::CONFIRMED, date('Y-m-d', $younger), $GLOBALS['registry']->preferredLang());
-        $rows = $GLOBALS['news']->db->getAll($query, $params, DB_FETCHMODE_ASSOC);
-        if ($rows instanceof PEAR_Error) {
-            return $rows->getDebugInfo();
+        $res = $GLOBALS['news']->db->limitQuery($query, 0, $this->_params['limit'], $params);
+        if ($res instanceof PEAR_Error) {
+            return $res->getDebugInfo();
+        }
+        $rows = array();
+        while ($res->fetchInto($row, DB_FETCHMODE_ASSOC)) {
+            $rows[$row['id']] = $row;
         }
-
         $view = new News_View();
         $view->news = $rows;
 
index 163d9df..a645085 100755 (executable)
@@ -35,16 +35,18 @@ class Horde_Block_News_most_read extends Horde_Block {
                  'FROM ' . $GLOBALS['news']->prefix . ' AS n, ' . $GLOBALS['news']->prefix . '_body AS nl WHERE ' .
                  'n.status = ? AND n.publish <= NOW() AND n.publish > ?' .
                  'AND nl.lang = ? AND n.id = nl.id ' .
-                 'ORDER BY n.view_count DESC ' .
-                 'LIMIT 0, ' . $this->_params['limit'];
+                 'ORDER BY n.view_count DESC';
 
         $younger = $_SERVER['REQUEST_TIME'] - $this->_params['days'] * 86400;
         $params = array(News::CONFIRMED, date('Y-m-d', $younger), $GLOBALS['registry']->preferredLang());
-        $rows = $GLOBALS['news']->db->getAll($query, $params, DB_FETCHMODE_ASSOC);
-        if ($rows instanceof PEAR_Error) {
-            return $rows->getDebugInfo();
+        $res = $GLOBALS['news']->db->queryLimit($query, 0, $this->_params['limit'], $params);
+        if ($res instanceof PEAR_Error) {
+            return $res->getDebugInfo();
+        }
+        $rows = array();
+        while ($res->fetchInto($row, DB_FETCHMODE_ASSOC)) {
+            $rows[$row['id']] = $row;
         }
-
         $view = new News_View();
         $view->news = $rows;
 
index fbb5f53..aa6375c 100644 (file)
@@ -382,14 +382,15 @@ class Skoli_Driver_sql extends Skoli_Driver {
     function lastEntry($studentid)
     {
         $query = 'SELECT object_time FROM ' . $this->_params['objects_table'] .
-                 ' WHERE class_id = ? AND student_id = ? ORDER BY object_time DESC LIMIT 1';
+                 ' WHERE class_id = ? AND student_id = ? ORDER BY object_time DESC';
         $values = array($this->_class, $studentid);
 
         /* Log the query at a DEBUG log level. */
         Horde::logMessage(sprintf('Skoli_Driver_sql::lastEntry(): %s', $query), 'DEBUG');
 
         /* Attempt the select query. */
-        $lastentry = $this->_db->getRow($query, $values, DB_FETCHMODE_ORDERED);
+        $lastentry = $this->_db->limitQuery($query, 0, 1);
+        $lastentry = $lastentry->fetchRow(DB_FETCHMODE_ORDERED);
 
         /* Return an error immediately if the query failed. */
         if (is_a($lastentry, 'PEAR_Error')) {