summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDerek Allard <derek.allard@ellislab.com>2007-12-19 16:01:55 +0100
committerDerek Allard <derek.allard@ellislab.com>2007-12-19 16:01:55 +0100
commite77d77c6b4c094483a3d85b23845436b77796d07 (patch)
tree616c036495ba4f76aeb9f8f964e0f549980ef691
parentda6d240d7b8615b5ae628496c42cb216658eb6e4 (diff)
Added support for limit() into update() and delete() statements in Active Record.
-rw-r--r--system/database/DB_active_rec.php15
-rw-r--r--system/database/drivers/mssql/mssql_driver.php6
-rw-r--r--system/database/drivers/mysql/mysql_driver.php6
-rw-r--r--system/database/drivers/mysqli/mysqli_driver.php6
-rw-r--r--system/database/drivers/oci8/oci8_driver.php6
-rw-r--r--system/database/drivers/odbc/odbc_driver.php6
-rw-r--r--system/database/drivers/postgre/postgre_driver.php6
-rw-r--r--system/database/drivers/sqlite/sqlite_driver.php6
-rw-r--r--user_guide/changelog.html2
9 files changed, 39 insertions, 20 deletions
diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php
index 4a88bd816..cea9bddc5 100644
--- a/system/database/DB_active_rec.php
+++ b/system/database/DB_active_rec.php
@@ -856,12 +856,12 @@ class CI_DB_active_record extends CI_DB_driver {
$table = $this->ar_from[0];
}
- if ($where != null)
+ if ($where != NULL)
{
$this->where($where);
}
- if ($limit != null)
+ if ($limit != NULL)
{
$this->limit($limit);
}
@@ -884,7 +884,7 @@ class CI_DB_active_record extends CI_DB_driver {
* @param mixed the where clause
* @return object
*/
- function delete($table = '', $where = '')
+ function delete($table = '', $where = '', $limit = NULL)
{
if ($table == '')
{
@@ -905,6 +905,11 @@ class CI_DB_active_record extends CI_DB_driver {
$this->where($where);
}
+ if ($limit != NULL)
+ {
+ $this->limit($limit);
+ }
+
if (count($this->ar_where) == 0)
{
if ($this->db_debug)
@@ -914,7 +919,7 @@ class CI_DB_active_record extends CI_DB_driver {
return FALSE;
}
- $sql = $this->_delete($this->dbprefix.$table, $this->ar_where);
+ $sql = $this->_delete($this->dbprefix.$table, $this->ar_where, $this->ar_limit);
$this->_reset_write();
return $this->query($sql);
@@ -1096,7 +1101,7 @@ class CI_DB_active_record extends CI_DB_driver {
/**
* Resets the active record "write" values.
*
- * Called by the insert() or update() functions
+ * Called by the insert() update() and delete() functions
*
* @access private
* @return void
diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php
index 613be69b5..044fb3ced 100644
--- a/system/database/drivers/mssql/mssql_driver.php
+++ b/system/database/drivers/mssql/mssql_driver.php
@@ -445,9 +445,11 @@ class CI_DB_mssql_driver extends CI_DB {
* @param array the where clause
* @return string
*/
- function _delete($table, $where)
+ function _delete($table, $where, $limit = FALSE)
{
- return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where);
+ $limit = (!$limit) ? '' : ' LIMIT '.$limit;
+
+ return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where).$limit;
}
// --------------------------------------------------------------------
diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php
index aaa9cc635..cd86ebf52 100644
--- a/system/database/drivers/mysql/mysql_driver.php
+++ b/system/database/drivers/mysql/mysql_driver.php
@@ -463,9 +463,11 @@ class CI_DB_mysql_driver extends CI_DB {
* @param array the where clause
* @return string
*/
- function _delete($table, $where)
+ function _delete($table, $where, $limit = FALSE)
{
- return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where);
+ $limit = (!$limit) ? '' : ' LIMIT '.$limit;
+
+ return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where).$limit;
}
// --------------------------------------------------------------------
diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php
index f6f106eba..ebed81390 100644
--- a/system/database/drivers/mysqli/mysqli_driver.php
+++ b/system/database/drivers/mysqli/mysqli_driver.php
@@ -456,9 +456,11 @@ class CI_DB_mysqli_driver extends CI_DB {
* @param array the where clause
* @return string
*/
- function _delete($table, $where)
+ function _delete($table, $where, $limit = FALSE)
{
- return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where);
+ $limit = (!$limit) ? '' : ' LIMIT '.$limit;
+
+ return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where).$limit;
}
// --------------------------------------------------------------------
diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php
index 1dd157cca..c4ab70051 100644
--- a/system/database/drivers/oci8/oci8_driver.php
+++ b/system/database/drivers/oci8/oci8_driver.php
@@ -559,9 +559,11 @@ class CI_DB_oci8_driver extends CI_DB {
* @param array the where clause
* @return string
*/
- function _delete($table, $where)
+ function _delete($table, $where, $limit = FALSE)
{
- return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where);
+ $limit = (!$limit) ? '' : ' LIMIT '.$limit;
+
+ return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where).$limit;
}
// --------------------------------------------------------------------
diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php
index 66d5f89b9..040ffed9e 100644
--- a/system/database/drivers/odbc/odbc_driver.php
+++ b/system/database/drivers/odbc/odbc_driver.php
@@ -418,9 +418,11 @@ class CI_DB_odbc_driver extends CI_DB {
* @param array the where clause
* @return string
*/
- function _delete($table, $where)
+ function _delete($table, $where, $limit = FALSE)
{
- return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where);
+ $limit = (!$limit) ? '' : ' LIMIT '.$limit;
+
+ return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where).$limit;
}
// --------------------------------------------------------------------
diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php
index 076d87a58..88f08b2d7 100644
--- a/system/database/drivers/postgre/postgre_driver.php
+++ b/system/database/drivers/postgre/postgre_driver.php
@@ -447,9 +447,11 @@ class CI_DB_postgre_driver extends CI_DB {
* @param array the where clause
* @return string
*/
- function _delete($table, $where)
+ function _delete($table, $where, $limit = FALSE)
{
- return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where);
+ $limit = (!$limit) ? '' : ' LIMIT '.$limit;
+
+ return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where).$limit;
}
// --------------------------------------------------------------------
diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php
index b701d6b96..6189b1ff0 100644
--- a/system/database/drivers/sqlite/sqlite_driver.php
+++ b/system/database/drivers/sqlite/sqlite_driver.php
@@ -442,9 +442,11 @@ class CI_DB_sqlite_driver extends CI_DB {
* @param array the where clause
* @return string
*/
- function _delete($table, $where)
+ function _delete($table, $where, $limit = FALSE)
{
- return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where);
+ $limit = (!$limit) ? '' : ' LIMIT '.$limit;
+
+ return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where).$limit;
}
// --------------------------------------------------------------------
diff --git a/user_guide/changelog.html b/user_guide/changelog.html
index 96e5724c0..b122c42fa 100644
--- a/user_guide/changelog.html
+++ b/user_guide/changelog.html
@@ -69,7 +69,7 @@ Change Log
<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>, <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 support for limit() into update() statements in <a href="./database/active_record.html">Active Record</a>.</li>
+ <li>Added support for <kbd>limit()</kbd> into <kbd>update()</kbd> and <kbd>delete()</kbd> statements in <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>