summaryrefslogtreecommitdiffstats
path: root/system/database/DB_active_rec.php
diff options
context:
space:
mode:
authorDerek Allard <derek.allard@ellislab.com>2007-12-18 16:58:03 +0100
committerDerek Allard <derek.allard@ellislab.com>2007-12-18 16:58:03 +0100
commit694b5b8ee6a40b57c91be3c5448bc8f5540d32d8 (patch)
treee79f794d18e31113ef086d76772c49c81b6b3cf1 /system/database/DB_active_rec.php
parent04036f33f6af540ce371b1ebd1878018f0816ed8 (diff)
Added count_all_results() function to Active Record.
Diffstat (limited to 'system/database/DB_active_rec.php')
-rw-r--r--system/database/DB_active_rec.php41
1 files changed, 40 insertions, 1 deletions
diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php
index 6a991a2ed..cb134ea6a 100644
--- a/system/database/DB_active_rec.php
+++ b/system/database/DB_active_rec.php
@@ -540,6 +540,7 @@ class CI_DB_active_record extends CI_DB_driver {
* and runs the query
*
* @access public
+ * @param string the table
* @param string the limit clause
* @param string the offset clause
* @return object
@@ -566,6 +567,39 @@ class CI_DB_active_record extends CI_DB_driver {
// --------------------------------------------------------------------
/**
+ * "Count All Results" query
+ *
+ * Generates a platform-specific query string that counts all records
+ * returned by an Active Record query.
+ *
+ * @access public
+ * @param string
+ * @return string
+ */
+ function count_all_results($table = '')
+ {
+ if ($table != '')
+ {
+ $this->from($table);
+ }
+
+ $sql = $this->_compile_select($this->count_string);
+
+ $query = $this->query($sql);
+ $this->_reset_select();
+
+ if ($query->num_rows() == 0)
+ {
+ return '0';
+ }
+
+ $row = $query->row();
+ return $row->numrows;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Get_Where
*
* Allows the where clause, limit and offset to be added directly
@@ -806,12 +840,17 @@ class CI_DB_active_record extends CI_DB_driver {
* @access private
* @return string
*/
- function _compile_select()
+ function _compile_select($select_override = FALSE)
{
$sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT ';
$sql .= (count($this->ar_select) == 0) ? '*' : implode(', ', $this->ar_select);
+ if ($select_override !== FALSE)
+ {
+ $sql = $select_override;
+ }
+
if (count($this->ar_from) > 0)
{
$sql .= "\nFROM ";