From 14c31893e5de6b469e2632664fe891d871810dfc Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Wed, 28 Jul 2010 11:17:53 -0400 Subject: [PATCH] remaining LIMIT to queryLimit() changes --- fima/lib/Driver/sql.php | 15 +++++++-------- folks/lib/Driver/sql.php | 16 ++++++++++------ news/lib/Block/category.php | 14 ++++++++------ news/lib/Block/last.php | 15 ++++++++------- news/lib/Block/last_blogs.php | 13 +++++++------ news/lib/Block/most_commented.php | 14 ++++++++------ news/lib/Block/most_read.php | 14 ++++++++------ skoli/lib/Driver/sql.php | 5 +++-- 8 files changed, 59 insertions(+), 47 deletions(-) diff --git a/fima/lib/Driver/sql.php b/fima/lib/Driver/sql.php index 7ebda335b..9524b8a44 100644 --- a/fima/lib/Driver/sql.php +++ b/fima/lib/Driver/sql.php @@ -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')) { diff --git a/folks/lib/Driver/sql.php b/folks/lib/Driver/sql.php index 151180293..6777d50ee 100644 --- a/folks/lib/Driver/sql.php +++ b/folks/lib/Driver/sql.php @@ -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]; } /** diff --git a/news/lib/Block/category.php b/news/lib/Block/category.php index b16c8f254..8b04ef6be 100755 --- a/news/lib/Block/category.php +++ b/news/lib/Block/category.php @@ -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']); diff --git a/news/lib/Block/last.php b/news/lib/Block/last.php index 32cec810b..30787d5be 100755 --- a/news/lib/Block/last.php +++ b/news/lib/Block/last.php @@ -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'); diff --git a/news/lib/Block/last_blogs.php b/news/lib/Block/last_blogs.php index 4521f7120..360e53cda 100755 --- a/news/lib/Block/last_blogs.php +++ b/news/lib/Block/last_blogs.php @@ -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; diff --git a/news/lib/Block/most_commented.php b/news/lib/Block/most_commented.php index 89779bc94..e683c95ec 100755 --- a/news/lib/Block/most_commented.php +++ b/news/lib/Block/most_commented.php @@ -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; diff --git a/news/lib/Block/most_read.php b/news/lib/Block/most_read.php index 163d9df42..a64508599 100755 --- a/news/lib/Block/most_read.php +++ b/news/lib/Block/most_read.php @@ -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; diff --git a/skoli/lib/Driver/sql.php b/skoli/lib/Driver/sql.php index fbb5f5307..aa6375cf0 100644 --- a/skoli/lib/Driver/sql.php +++ b/skoli/lib/Driver/sql.php @@ -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')) { -- 2.11.0