aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/db/mssql_odbc.php
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/includes/db/mssql_odbc.php')
-rw-r--r--phpBB/includes/db/mssql_odbc.php37
1 files changed, 15 insertions, 22 deletions
diff --git a/phpBB/includes/db/mssql_odbc.php b/phpBB/includes/db/mssql_odbc.php
index 54655c389a..09437a1780 100644
--- a/phpBB/includes/db/mssql_odbc.php
+++ b/phpBB/includes/db/mssql_odbc.php
@@ -168,33 +168,26 @@ class dbal_mssql_odbc extends dbal
{
$this->query_result = false;
- // if $total is set to 0 we do not want to limit the number of rows
- if ($total == 0)
+ // Since TOP is only returning a set number of rows we won't need it if total is set to 0 (return all rows)
+ if ($total)
{
- $total = -1;
- }
-
- $row_offset = ($total) ? $offset : 0;
- $num_rows = ($total) ? $total : $offset;
-
- if (strpos($query, 'SELECT DISTINCT') === 0)
- {
- $query = 'SELECT DISTINCT TOP ' . ($row_offset + $num_rows) . ' ' . substr($query, 15);
- }
- else
- {
- $query = 'SELECT TOP ' . ($row_offset + $num_rows) . ' ' . substr($query, 6);
+ // We need to grab the total number of rows + the offset number of rows to get the correct result
+ if (strpos($query, 'SELECT DISTINCT') === 0)
+ {
+ $query = 'SELECT DISTINCT TOP ' . ($total + $offset) . ' ' . substr($query, 15);
+ }
+ else
+ {
+ $query = 'SELECT TOP ' . ($total + $offset) . ' ' . substr($query, 6);
+ }
}
$result = $this->sql_query($query, $cache_ttl);
- // Seek by $row_offset rows
- if ($row_offset)
+ // Seek by $offset rows
+ if ($offset)
{
- for ($i = 0; $i < $row_offset; $i++)
- {
- $this->sql_fetchrow($result);
- }
+ $this->sql_rowseek($offset, $result);
}
return $result;
@@ -301,7 +294,7 @@ class dbal_mssql_odbc extends dbal
if (isset($cache->sql_rowset[$query_id]))
{
- return $cache->sql_rowseek($query_id, $rownum);
+ return $cache->sql_rowseek($rownum, $query_id);
}
$this->sql_freeresult($query_id);