hopefully fix getting query counts for < 7.0... slightly ineffecient as you need...
authorchriskl <chriskl>
Sun, 18 May 2003 12:48:11 +0000 (12:48 +0000)
committerchriskl <chriskl>
Sun, 18 May 2003 12:48:11 +0000 (12:48 +0000)
classes/database/Postgres.php
classes/database/Postgres71.php

index 616f6a188cc491f478d1cacbd25d0b7d33dccd0d..a7072f8c07ae2e8b37f2ea23ef81ff7ebcb1eaa6 100755 (executable)
@@ -4,7 +4,7 @@
  * A class that implements the DB interface for Postgres
  * Note: This class uses ADODB and returns RecordSets.
  *
- * $Id: Postgres.php,v 1.109 2003/05/18 11:53:28 chriskl Exp $
+ * $Id: Postgres.php,v 1.110 2003/05/18 12:48:11 chriskl Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -721,6 +721,24 @@ class Postgres extends BaseDB {
                return $rs;
        }
 
+       /**
+        * Finds the number of rows that would be returned by a
+        * query.
+        * @param $query The SQL query
+        * @param $count The count query
+        * @return The count of rows
+        * @return -1 error
+        */
+       function browseSQLCount($query, $count) {
+               // Count the number of rows
+               $rs = $this->selectSet($query);
+               if (!is_object($rs)) {
+                       return -1;
+               }
+               
+               return $rs->recordCount();      
+       }
+       
        /**
         * Returns a recordset of all columns in a query.  Supports paging.
         * @param $query The SQL SELECT query.
@@ -742,7 +760,7 @@ class Postgres extends BaseDB {
                if ($status != 0) return -1;
                
                // Count the number of rows
-               $total = $this->selectField($count, 'total');
+               $total = $this->browseSQLCount($query, $count);
                if ($total < 0) {
                        $this->rollbackTransaction();
                        return -2;
@@ -761,8 +779,6 @@ class Postgres extends BaseDB {
                $this->conn->setFetchMode(ADODB_FETCH_NUM);
 
                // Actually retrieve the rows, with offset and limit
-               // @@@@@@@@@@@@@@ THIS NEXT LINE ONLY WORKS IN POSTGRESQL 7.2+ @@@@@@@@@@@@@@@@@
-               //$sql = "SELECT * FROM ($query) LIMIT {$page_size} OFFSET " . ($page - 1) * $page_size);
                $rs = $this->selectSet("{$query} LIMIT {$page_size} OFFSET " . ($page - 1) * $page_size);
 
                $status = $this->endTransaction();
index 1e44c0ac29ba749c5567aca93d269b3ef8e537a0..8843e3d749760b5a75fc929fea29615e28676aa7 100644 (file)
@@ -4,7 +4,7 @@
  * A class that implements the DB interface for Postgres
  * Note: This class uses ADODB and returns RecordSets.
  *
- * $Id: Postgres71.php,v 1.33 2003/05/17 15:51:37 chriskl Exp $
+ * $Id: Postgres71.php,v 1.34 2003/05/18 12:48:11 chriskl Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -102,7 +102,19 @@ class Postgres71 extends Postgres {
        }
 
        // Table functions
-       
+
+       /**
+        * Finds the number of rows that would be returned by a
+        * query.
+        * @param $query The SQL query
+        * @param $count The count query
+        * @return The count of rows
+        * @return -1 error
+        */
+       function browseSQLCount($query, $count) {
+               return $this->selectField($count, 'total');
+       }
+               
        /**
         * Retrieve the attribute definition of a table
         * @param $table The name of the table