summaryrefslogtreecommitdiffstats
path: root/system/database/DB_active_rec.php
diff options
context:
space:
mode:
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 ";