From fc49aa859470a1701ad0274a5f00727d66f8cfcc Mon Sep 17 00:00:00 2001 From: jengo Date: Mon, 2 Jul 2001 19:16:20 +0000 Subject: [PATCH] Changed around the limit_query() function to be easier for developers to use --- phpgwapi/inc/class.db_mysql.inc.php | 40 +++++++++++++++++++++-------- phpgwapi/inc/class.db_pgsql.inc.php | 40 +++++++++++++++++++++-------- 2 files changed, 58 insertions(+), 22 deletions(-) diff --git a/phpgwapi/inc/class.db_mysql.inc.php b/phpgwapi/inc/class.db_mysql.inc.php index 3701dc93d4..781a558139 100644 --- a/phpgwapi/inc/class.db_mysql.inc.php +++ b/phpgwapi/inc/class.db_mysql.inc.php @@ -116,6 +116,8 @@ class db { { global $phpgw_info; + echo 'Warning: limit() is no longer used, use limit_query()'; + if ($start == 0) { $s = "limit " . $phpgw_info["user"]["preferences"]["common"]["maxmatchs"]; } else { @@ -165,21 +167,37 @@ class db { return $this->Query_ID; } - // public: perform a query with limited result set - function limit_query($Query_String, $offset, $num_rows, $line = '', $file = '') - { - global $phpgw_info; + // public: perform a query with limited result set + function limit_query($Query_String, $_offset, $line = '', $file = '') + { + global $phpgw_info; - if ($this->Debug) - printf("Debug: limit_query = %s
offset=%d, num_rows=%d
\n", $Query_String, $offset, $num_rows); + if (is_array($_offset)) + { + list($offset,$num_rows) = $_offset; + } + else + { + $num_rows = $phpgw_info['user']['preferences']['common']['maxmatchs']; + $offset = $_offset; + } - if (!IsSet($num_rows) || $num_rows < 1) - $num_rows = $phpgw_info['user']['preferences']['common']['maxmatchs']; + if ($offset == 0) + { + $Query_String .= ' LIMIT ' . $num_rows; + } + else + { + $Query_String .= ' LIMIT ' . $offset . ',' . $num_rows; + } - $Query_String .= ' LIMIT ' . $offset . ',' . $num_rows; + if ($this->Debug) + { + printf("Debug: limit_query = %s
offset=%d, num_rows=%d
\n", $Query_String, $offset, $num_rows); + } - return $this->query($Query_String, $line, $file); - } + return $this->query($Query_String, $line, $file); + } /* public: walk result set */ function next_record() { diff --git a/phpgwapi/inc/class.db_pgsql.inc.php b/phpgwapi/inc/class.db_pgsql.inc.php index 6f347af9c6..e361baf0e6 100644 --- a/phpgwapi/inc/class.db_pgsql.inc.php +++ b/phpgwapi/inc/class.db_pgsql.inc.php @@ -69,6 +69,8 @@ class db { { global $phpgw_info; + echo 'Warning: limit() is no longer used, use limit_query()'; + if ($start == 0) { $s = "limit " . $phpgw_info["user"]["preferences"]["common"]["maxmatchs"]; } else { @@ -109,21 +111,37 @@ class db { return $this->Query_ID; } - // public: perform a query with limited result set - function limit_query($Query_String, $offset, $num_rows, $line = '', $file = '') - { - global $phpgw_info; + // public: perform a query with limited result set + function limit_query($Query_String, $_offset, $line = '', $file = '') + { + global $phpgw_info; - if ($this->Debug) - printf("Debug: limit_query = %s
offset=%d, num_rows=%d
\n", $Query_String, $offset, $num_rows); + if (is_array($_offset)) + { + list($offset,$num_rows) = $_offset; + } + else + { + $num_rows = $phpgw_info['user']['preferences']['common']['maxmatchs']; + $offset = $_offset; + } - if (!IsSet($num_rows) || $num_rows < 1) - $num_rows = $phpgw_info['user']['preferences']['common']['maxmatchs']; + if ($offset == 0) + { + $Query_String .= ' LIMIT ' . $num_rows; + } + else + { + $Query_String .= ' LIMIT ' . $num_rows . ',' . $offset; + } - $Query_String .= ' LIMIT ' . $offset . ',' . $num_rows; + if ($this->Debug) + { + printf("Debug: limit_query = %s
offset=%d, num_rows=%d
\n", $Query_String, $offset, $num_rows); + } - return $this->query($Query_String, $line, $file); - } + return $this->query($Query_String, $line, $file); + } // public: discard the query result function free() {