summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--system/database/DB_active_rec.php85
-rw-r--r--user_guide/changelog.html2
-rw-r--r--user_guide/database/active_record.html41
3 files changed, 107 insertions, 21 deletions
diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php
index c3279e8c3..473685874 100644
--- a/system/database/DB_active_rec.php
+++ b/system/database/DB_active_rec.php
@@ -248,21 +248,99 @@ class CI_DB_active_record extends CI_DB_driver {
/**
* Where_in
*
- * Generates a WHERE field IN ('item', 'item') SQL query
+ * Generates a WHERE field IN ('item', 'item') SQL query joined with
+ * AND if appropriate
*
* @access public
* @param string The field to search
* @param array The values searched on
+
+ * @return object
+ */
+ function where_in($key = NULL, $values = NULL)
+ {
+ return $this->_where_in($key, $values);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Where_in_or
+ *
+ * Generates a WHERE field IN ('item', 'item') SQL query joined with
+ * OR if appropriate
+ *
+ * @access public
+ * @param string The field to search
+ * @param array The values searched on
+
+ * @return object
+ */
+ function where_in_or($key = NULL, $values = NULL)
+ {
+ return $this->_where_in($key, $values, FALSE, 'or');
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Where_not_in
+ *
+ * Generates a WHERE field NOT IN ('item', 'item') SQL query joined
+ * with AND if appropriate
+ *
+ * @access public
+ * @param string The field to search
+ * @param array The values searched on
+
+ * @return object
+ */
+ function where_not_in($key = NULL, $values = NULL)
+ {
+ return $this->_where_in($key, $values, TRUE);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Where_not_in_or
+ *
+ * Generates a WHERE field NOT IN ('item', 'item') SQL query joined
+ * with OR if appropriate
+ *
+ * @access public
+ * @param string The field to search
+ * @param array The values searched on
+
+ * @return object
+ */
+ function where_not_in_or($key = NULL, $values = NULL)
+ {
+ return $this->_where_in($key, $values, FALSE, 'or');
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Where_in
+ *
+ * Called by where_in, where_in_or, where_not_in, where_not_in_or
+ *
+ * @access public
+ * @param string The field to search
+ * @param array The values searched on
+ * @param boolean If the statement whould be IN or NOT IN
* @param string
* @return object
*/
- function where_in($key = NULL, $values = NULL, $type = 'and')
+ function _where_in($key = NULL, $values = NULL, $not = FALSE, $type = 'and')
{
if ($key === NULL || !is_array($values))
{
return;
}
+ $not = ($not) ? ' NOT ' : '';
$type = (strtolower($type) == 'or') ? ' OR ' : ' AND ';
foreach ($values as $value)
@@ -272,7 +350,7 @@ class CI_DB_active_record extends CI_DB_driver {
$prefix = (count($this->ar_where) == 0) ? '' : $type;
- $this->ar_where[] = $prefix.$key. " IN (" . implode(", ", $this->ar_wherein) . ") ";
+ $this->ar_where[] = $prefix.$key.$not . " IN (" . implode(", ", $this->ar_wherein) . ") ";
return $this;
}
@@ -1005,6 +1083,7 @@ class CI_DB_active_record extends CI_DB_driver {
$this->ar_offset = FALSE;
$this->ar_order = FALSE;
$this->ar_orderby = array();
+ $this->ar_wherein = array();
}
// --------------------------------------------------------------------
diff --git a/user_guide/changelog.html b/user_guide/changelog.html
index 8853969c4..55edb75d1 100644
--- a/user_guide/changelog.html
+++ b/user_guide/changelog.html
@@ -68,7 +68,7 @@ Change Log
<li>Javascript Calendar plugin now uses the months and days from the calendar language file, instead of hard-coded values, internationalizing it.</li>
<li>Removed &quot;rand()&quot; as a listed option from orderby in the <a href="./database/active_record.html">Active Record</a>, as it was MySQL only.</li>
<li>Added 'random' as an <kbd>order_by()</kbd> option in <a href="./database/active_record.html">Active Record</a>.</li>
- <li>Added <kbd>where_in()</kbd> to <a href="./database/active_record.html">Active Record</a>.</li>
+ <li>Added <kbd>where_in()</kbd>, <kbd>where_in_or()</kbd>, <kbd>where_not_in()</kbd>, and <kbd>where_not_in_or()</kbd> to <a href="./database/active_record.html">Active Record</a>.</li>
<li>Added titles to all user manual pages.</li>
<li>Added a check for NULL fields in the MySQL database backup utility.</li>
<li>Documented the <kbd>timezones()</kbd> function in the <a href="./helpers/date_helper.html">Date Helper</a>.</li>
diff --git a/user_guide/database/active_record.html b/user_guide/database/active_record.html
index 0146941ba..cf8ad469f 100644
--- a/user_guide/database/active_record.html
+++ b/user_guide/database/active_record.html
@@ -268,26 +268,33 @@ $this->db->or_where('id >', $id);
<h2>$this->db->where_in();</h2>
-<p>This function is used to write WHERE clauses that contain the IN keyword.</p>
+<p>Generates a WHERE field IN ('item', 'item') SQL query joined with AND if appropriate</p>
+<p><code>
+ $names = array('Frank', 'Todd', 'James');<br />
+ $this->db->where_in('username', $names);<br />
+ // Produces: AND WHERE username IN ('Frank', 'Todd', 'James')</code></p>
+
+<h2>$this->db->where_in_or();</h2>
+<p>Generates a WHERE field IN ('item', 'item') SQL query joined with OR if appropriate</p>
+<p><code>
+ $names = array('Frank', 'Todd', 'James');<br />
+ $this->db->where_in_or('username', $names);<br />
+ // Produces: OR WHERE username IN ('Frank', 'Todd', 'James')</code></p>
+
+<h2>$this->db->where_not_in();</h2>
+<p>Generates a WHERE field NOT IN ('item', 'item') SQL query joined with AND if appropriate</p>
+<p><code>
+ $names = array('Frank', 'Todd', 'James');<br />
+ $this->db->where_not_in('username', $names);<br />
+ // Produces: AND WHERE username NOT IN ('Frank', 'Todd', 'James')</code></p>
+<h2>$this->db->where_not_in_or();</h2>
+<p>Generates a WHERE field NOT IN ('item', 'item') SQL query joined with OR if appropriate</p>
<p><code>
- $names = array('frank', 'Todd', 'James');<br />
+ $names = array('Frank', 'Todd', 'James');<br />
$this->db->where_in('username', $names);<br />
- // Produces: AND WHERE username IN ('frank', 'Todd', 'James')</code></p>
-<p>An optional third parameter can be used to specify if the WHERE statement should be separated with &quot;OR&quot; or &quot;AND&quot; in the event of multiple WHERE calls. The default is &quot;AND&quot;. They are called with 'and', 'or'.</p>
-<p><code>$names = array('frank', 'Todd', 'James');<br />
- <br />
- $this-&gt;db-&gt;where('usergroup', '5')<br />
-$this-&gt;db-&gt;where_in('username', $names);<br />
-// Produces: WHERE usergroup = '5' AND WHERE username IN ('frank', 'Todd', 'James')<br />
-<br />
-$this-&gt;db-&gt;where('usergroup', '5')<br />
-$this-&gt;db-&gt;where_in('username', $names, 'and');<br />
-// Produces: WHERE usergroup = '5' AND WHERE username IN ('frank', 'Todd', 'James')<br />
-<br />
-$this-&gt;db-&gt;where('usergroup', '5')<br />
-$this-&gt;db-&gt;where_in('username', $names, 'or');<br />
-// Produces: WHERE usergroup = '5' OR WHERE username IN ('frank', 'Todd', 'James')</code></p>
+ // Produces: OR WHERE username NOT IN ('Frank', 'Todd', 'James')</code></p>
+
<h2>$this->db->like();</h2>
<p>This function enables you to generate <strong>LIKE</strong> clauses, useful for doing searches.</p>