From e52d23848a1b116d32fbad9dd384e0755553b829 Mon Sep 17 00:00:00 2001 From: Patrick Webster Date: Tue, 8 May 2012 18:44:43 -0500 Subject: [ticket/10858] Fix MSSQL Native's row seeking behavior The result_mssqlnative class remains in case someone wants to use it PHPBB3-10858 --- phpBB/includes/db/mssqlnative.php | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'phpBB/includes/db') diff --git a/phpBB/includes/db/mssqlnative.php b/phpBB/includes/db/mssqlnative.php index 7fbc374e77..6391664a3e 100644 --- a/phpBB/includes/db/mssqlnative.php +++ b/phpBB/includes/db/mssqlnative.php @@ -447,14 +447,39 @@ class dbal_mssqlnative extends dbal { global $cache; + if ($query_id === false) + { + $query_id = $this->query_result; + } + if (isset($cache->sql_rowset[$query_id])) { return $cache->sql_rowseek($rownum, $query_id); } - $seek = new result_mssqlnative($query_id); - $row = $seek->seek($rownum); - return ($row = $seek->fetch()) ? $row : false; + if ($query_id === false) + { + return false; + } + + $this->sql_freeresult($query_id); + $query_id = $this->sql_query($this->last_query_text); + + if ($query_id === false) + { + return false; + } + + // We do not fetch the row for rownum == 0 because then the next resultset would be the second row + for ($i = 0; $i < $rownum; $i++) + { + if (!$this->sql_fetchrow($query_id)) + { + return false; + } + } + + return true; } /** -- cgit v1.2.1 From 09d49fb7b2be51a29f5a03c0a1a3816d7e55a466 Mon Sep 17 00:00:00 2001 From: Patrick Webster Date: Tue, 8 May 2012 19:41:22 -0500 Subject: [ticket/10858] Move generic row seeking to DBAL Removed from: firebird, mssql_odbc, and mssqlnative PHPBB3-10858 --- phpBB/includes/db/dbal.php | 43 +++++++++++++++++++++++++++++++++++++++ phpBB/includes/db/firebird.php | 43 --------------------------------------- phpBB/includes/db/mssql_odbc.php | 43 --------------------------------------- phpBB/includes/db/mssqlnative.php | 43 --------------------------------------- 4 files changed, 43 insertions(+), 129 deletions(-) (limited to 'phpBB/includes/db') diff --git a/phpBB/includes/db/dbal.php b/phpBB/includes/db/dbal.php index 5d456c2ff0..358df50402 100644 --- a/phpBB/includes/db/dbal.php +++ b/phpBB/includes/db/dbal.php @@ -194,6 +194,49 @@ class dbal return false; } + /** + * Seek to given row number + * rownum is zero-based + */ + function sql_rowseek($rownum, &$query_id) + { + global $cache; + + if ($query_id === false) + { + $query_id = $this->query_result; + } + + if (isset($cache->sql_rowset[$query_id])) + { + return $cache->sql_rowseek($rownum, $query_id); + } + + if ($query_id === false) + { + return false; + } + + $this->sql_freeresult($query_id); + $query_id = $this->sql_query($this->last_query_text); + + if ($query_id === false) + { + return false; + } + + // We do not fetch the row for rownum == 0 because then the next resultset would be the second row + for ($i = 0; $i < $rownum; $i++) + { + if (!$this->sql_fetchrow($query_id)) + { + return false; + } + } + + return true; + } + /** * Fetch field * if rownum is false, the current row is used, else it is pointing to the row (zero-based) diff --git a/phpBB/includes/db/firebird.php b/phpBB/includes/db/firebird.php index 7e3f15ed1d..7072c58ac0 100644 --- a/phpBB/includes/db/firebird.php +++ b/phpBB/includes/db/firebird.php @@ -359,49 +359,6 @@ class dbal_firebird extends dbal return (sizeof($row)) ? $row : false; } - /** - * Seek to given row number - * rownum is zero-based - */ - function sql_rowseek($rownum, &$query_id) - { - global $cache; - - if ($query_id === false) - { - $query_id = $this->query_result; - } - - if (isset($cache->sql_rowset[$query_id])) - { - return $cache->sql_rowseek($rownum, $query_id); - } - - if ($query_id === false) - { - return; - } - - $this->sql_freeresult($query_id); - $query_id = $this->sql_query($this->last_query_text); - - if ($query_id === false) - { - return false; - } - - // We do not fetch the row for rownum == 0 because then the next resultset would be the second row - for ($i = 0; $i < $rownum; $i++) - { - if (!$this->sql_fetchrow($query_id)) - { - return false; - } - } - - return true; - } - /** * Get last inserted id after insert statement */ diff --git a/phpBB/includes/db/mssql_odbc.php b/phpBB/includes/db/mssql_odbc.php index 75a080b1b7..34f7a87337 100644 --- a/phpBB/includes/db/mssql_odbc.php +++ b/phpBB/includes/db/mssql_odbc.php @@ -255,49 +255,6 @@ class dbal_mssql_odbc extends dbal return ($query_id !== false) ? @odbc_fetch_array($query_id) : false; } - /** - * Seek to given row number - * rownum is zero-based - */ - function sql_rowseek($rownum, &$query_id) - { - global $cache; - - if ($query_id === false) - { - $query_id = $this->query_result; - } - - if (isset($cache->sql_rowset[$query_id])) - { - return $cache->sql_rowseek($rownum, $query_id); - } - - if ($query_id === false) - { - return false; - } - - $this->sql_freeresult($query_id); - $query_id = $this->sql_query($this->last_query_text); - - if ($query_id === false) - { - return false; - } - - // We do not fetch the row for rownum == 0 because then the next resultset would be the second row - for ($i = 0; $i < $rownum; $i++) - { - if (!$this->sql_fetchrow($query_id)) - { - return false; - } - } - - return true; - } - /** * Get last inserted id after insert statement */ diff --git a/phpBB/includes/db/mssqlnative.php b/phpBB/includes/db/mssqlnative.php index 6391664a3e..92ac9b1fb9 100644 --- a/phpBB/includes/db/mssqlnative.php +++ b/phpBB/includes/db/mssqlnative.php @@ -439,49 +439,6 @@ class dbal_mssqlnative extends dbal return $row; } - /** - * Seek to given row number - * rownum is zero-based - */ - function sql_rowseek($rownum, &$query_id) - { - global $cache; - - if ($query_id === false) - { - $query_id = $this->query_result; - } - - if (isset($cache->sql_rowset[$query_id])) - { - return $cache->sql_rowseek($rownum, $query_id); - } - - if ($query_id === false) - { - return false; - } - - $this->sql_freeresult($query_id); - $query_id = $this->sql_query($this->last_query_text); - - if ($query_id === false) - { - return false; - } - - // We do not fetch the row for rownum == 0 because then the next resultset would be the second row - for ($i = 0; $i < $rownum; $i++) - { - if (!$this->sql_fetchrow($query_id)) - { - return false; - } - } - - return true; - } - /** * Get last inserted id after insert statement */ -- cgit v1.2.1