diff options
Diffstat (limited to 'phpBB/includes/db')
-rw-r--r-- | phpBB/includes/db/dbal.php | 18 | ||||
-rw-r--r-- | phpBB/includes/db/firebird.php | 15 | ||||
-rw-r--r-- | phpBB/includes/db/mssql.php | 43 | ||||
-rw-r--r-- | phpBB/includes/db/mssql_odbc.php | 43 | ||||
-rw-r--r-- | phpBB/includes/db/mysql.php | 27 | ||||
-rw-r--r-- | phpBB/includes/db/mysqli.php | 27 | ||||
-rw-r--r-- | phpBB/includes/db/oracle.php | 15 | ||||
-rw-r--r-- | phpBB/includes/db/postgres.php | 25 | ||||
-rw-r--r-- | phpBB/includes/db/sqlite.php | 25 |
9 files changed, 100 insertions, 138 deletions
diff --git a/phpBB/includes/db/dbal.php b/phpBB/includes/db/dbal.php index 1f48909d43..df6e453329 100644 --- a/phpBB/includes/db/dbal.php +++ b/phpBB/includes/db/dbal.php @@ -115,6 +115,24 @@ class dbal } /** + * Build LIMIT query + * Doing some validation here. + */ + function sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0) + { + if (empty($query)) + { + return false; + } + + // Never use a negative total or offset + $total = ($total < 0) ? 0 : $total; + $offset = ($offset < 0) ? 0 : $offset; + + return $this->_sql_query_limit($query, $total, $offset, $cache_ttl); + } + + /** * Fetch all rows */ function sql_fetchrowset($query_id = false) diff --git a/phpBB/includes/db/firebird.php b/phpBB/includes/db/firebird.php index 60fa366b7f..709145c4cf 100644 --- a/phpBB/includes/db/firebird.php +++ b/phpBB/includes/db/firebird.php @@ -158,20 +158,13 @@ class dbal_firebird extends dbal /** * Build LIMIT query */ - function sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0) + function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0) { - if ($query != '') - { - $this->query_result = false; + $this->query_result = false; - $query = 'SELECT FIRST ' . $total . ((!empty($offset)) ? ' SKIP ' . $offset : '') . substr($query, 6); + $query = 'SELECT FIRST ' . $total . ((!empty($offset)) ? ' SKIP ' . $offset : '') . substr($query, 6); - return $this->sql_query($query, $cache_ttl); - } - else - { - return false; - } + return $this->sql_query($query, $cache_ttl); } /** diff --git a/phpBB/includes/db/mssql.php b/phpBB/includes/db/mssql.php index c9946c2b5c..b28ea01acb 100644 --- a/phpBB/includes/db/mssql.php +++ b/phpBB/includes/db/mssql.php @@ -159,40 +159,33 @@ class dbal_mssql extends dbal /** * Build LIMIT query */ - function sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0) + function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0) { - if ($query != '') - { - $this->query_result = false; + $this->query_result = false; - // 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) + // 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) + { + // 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) { - // 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); - } + $query = 'SELECT DISTINCT TOP ' . ($total + $offset) . ' ' . substr($query, 15); } - - $result = $this->sql_query($query, $cache_ttl); - - // Seek by $offset rows - if ($offset) + else { - $this->sql_rowseek($offset, $result); + $query = 'SELECT TOP ' . ($total + $offset) . ' ' . substr($query, 6); } - - return $result; } - else + + $result = $this->sql_query($query, $cache_ttl); + + // Seek by $offset rows + if ($offset) { - return false; + $this->sql_rowseek($offset, $result); } + + return $result; } /** diff --git a/phpBB/includes/db/mssql_odbc.php b/phpBB/includes/db/mssql_odbc.php index 2cb3bf0f2d..0b8f1e2a95 100644 --- a/phpBB/includes/db/mssql_odbc.php +++ b/phpBB/includes/db/mssql_odbc.php @@ -156,40 +156,33 @@ class dbal_mssql_odbc extends dbal /** * Build LIMIT query */ - function sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0) + function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0) { - if ($query != '') - { - $this->query_result = false; + $this->query_result = false; - // 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) + // 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) + { + // 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) { - // 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); - } + $query = 'SELECT DISTINCT TOP ' . ($total + $offset) . ' ' . substr($query, 15); } - - $result = $this->sql_query($query, $cache_ttl); - - // Seek by $offset rows - if ($offset) + else { - $this->sql_rowseek($offset, $result); + $query = 'SELECT TOP ' . ($total + $offset) . ' ' . substr($query, 6); } - - return $result; } - else + + $result = $this->sql_query($query, $cache_ttl); + + // Seek by $offset rows + if ($offset) { - return false; + $this->sql_rowseek($offset, $result); } + + return $result; } /** diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php index 89a6e21d70..b750618ae6 100644 --- a/phpBB/includes/db/mysql.php +++ b/phpBB/includes/db/mysql.php @@ -163,27 +163,20 @@ class dbal_mysql extends dbal /** * Build LIMIT query */ - function sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0) + function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0) { - if ($query != '') - { - $this->query_result = false; - - // if $total is set to 0 we do not want to limit the number of rows - if ($total == 0) - { - // Having a value of -1 was always a bug - $total = '18446744073709551615'; - } - - $query .= "\n LIMIT " . ((!empty($offset)) ? $offset . ', ' . $total : $total); + $this->query_result = false; - return $this->sql_query($query, $cache_ttl); - } - else + // if $total is set to 0 we do not want to limit the number of rows + if ($total == 0) { - return false; + // Having a value of -1 was always a bug + $total = '18446744073709551615'; } + + $query .= "\n LIMIT " . ((!empty($offset)) ? $offset . ', ' . $total : $total); + + return $this->sql_query($query, $cache_ttl); } /** diff --git a/phpBB/includes/db/mysqli.php b/phpBB/includes/db/mysqli.php index 86700744fb..da6faa3983 100644 --- a/phpBB/includes/db/mysqli.php +++ b/phpBB/includes/db/mysqli.php @@ -142,27 +142,20 @@ class dbal_mysqli extends dbal /** * Build LIMIT query */ - function sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0) + function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0) { - if ($query != '') - { - $this->query_result = false; - - // if $total is set to 0 we do not want to limit the number of rows - if ($total == 0) - { - // MySQL 4.1+ no longer supports -1 in limit queries - $total = '18446744073709551615'; - } - - $query .= "\n LIMIT " . ((!empty($offset)) ? $offset . ', ' . $total : $total); + $this->query_result = false; - return $this->sql_query($query, $cache_ttl); - } - else + // if $total is set to 0 we do not want to limit the number of rows + if ($total == 0) { - return false; + // MySQL 4.1+ no longer supports -1 in limit queries + $total = '18446744073709551615'; } + + $query .= "\n LIMIT " . ((!empty($offset)) ? $offset . ', ' . $total : $total); + + return $this->sql_query($query, $cache_ttl); } /** diff --git a/phpBB/includes/db/oracle.php b/phpBB/includes/db/oracle.php index 8f65c667a7..dcb972d119 100644 --- a/phpBB/includes/db/oracle.php +++ b/phpBB/includes/db/oracle.php @@ -213,20 +213,13 @@ class dbal_oracle extends dbal /** * Build LIMIT query */ - function sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0) + function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0) { - if ($query != '') - { - $this->query_result = false; + $this->query_result = false; - $query = 'SELECT * FROM (SELECT /*+ FIRST_ROWS */ rownum AS xrownum, a.* FROM (' . $query . ') a WHERE rownum <= ' . ($offset + $total) . ') WHERE xrownum >= ' . $offset; + $query = 'SELECT * FROM (SELECT /*+ FIRST_ROWS */ rownum AS xrownum, a.* FROM (' . $query . ') a WHERE rownum <= ' . ($offset + $total) . ') WHERE xrownum >= ' . $offset; - return $this->sql_query($query, $cache_ttl); - } - else - { - return false; - } + return $this->sql_query($query, $cache_ttl); } /** diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php index c06786a795..c0a8d930e1 100644 --- a/phpBB/includes/db/postgres.php +++ b/phpBB/includes/db/postgres.php @@ -192,26 +192,19 @@ class dbal_postgres extends dbal /** * Build LIMIT query */ - function sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0) + function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0) { - if ($query != '') - { - $this->query_result = false; - - // if $total is set to 0 we do not want to limit the number of rows - if ($total == 0) - { - $total = -1; - } + $this->query_result = false; - $query .= "\n LIMIT $total OFFSET $offset"; - - return $this->sql_query($query, $cache_ttl); - } - else + // if $total is set to 0 we do not want to limit the number of rows + if ($total == 0) { - return false; + $total = -1; } + + $query .= "\n LIMIT $total OFFSET $offset"; + + return $this->sql_query($query, $cache_ttl); } /** diff --git a/phpBB/includes/db/sqlite.php b/phpBB/includes/db/sqlite.php index 708376881c..9f44bd6b35 100644 --- a/phpBB/includes/db/sqlite.php +++ b/phpBB/includes/db/sqlite.php @@ -141,26 +141,19 @@ class dbal_sqlite extends dbal /** * Build LIMIT query */ - function sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0) + function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0) { - if ($query != '') - { - $this->query_result = false; - - // if $total is set to 0 we do not want to limit the number of rows - if ($total == 0) - { - $total = -1; - } - - $query .= "\n LIMIT " . ((!empty($offset)) ? $offset . ', ' . $total : $total); + $this->query_result = false; - return $this->sql_query($query, $cache_ttl); - } - else + // if $total is set to 0 we do not want to limit the number of rows + if ($total == 0) { - return false; + $total = -1; } + + $query .= "\n LIMIT " . ((!empty($offset)) ? $offset . ', ' . $total : $total); + + return $this->sql_query($query, $cache_ttl); } /** |