summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--system/database/DB_active_rec.php10
-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.php8
-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.html1
9 files changed, 38 insertions, 17 deletions
diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php
index 473685874..4a88bd816 100644
--- a/system/database/DB_active_rec.php
+++ b/system/database/DB_active_rec.php
@@ -826,7 +826,7 @@ class CI_DB_active_record extends CI_DB_driver {
* @param mixed the where clause
* @return object
*/
- function update($table = '', $set = NULL, $where = null)
+ function update($table = '', $set = NULL, $where = null, $limit = NULL)
{
if ( ! is_null($set))
{
@@ -860,8 +860,13 @@ class CI_DB_active_record extends CI_DB_driver {
{
$this->where($where);
}
+
+ if ($limit != null)
+ {
+ $this->limit($limit);
+ }
- $sql = $this->_update($this->dbprefix.$table, $this->ar_set, $this->ar_where);
+ $sql = $this->_update($this->dbprefix.$table, $this->ar_set, $this->ar_where, $this->ar_limit);
$this->_reset_write();
return $this->query($sql);
@@ -1101,6 +1106,7 @@ class CI_DB_active_record extends CI_DB_driver {
$this->ar_set = array();
$this->ar_from = array();
$this->ar_where = array();
+ $this->ar_limit = FALSE;
}
}
diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php
index 89610455b..613be69b5 100644
--- a/system/database/drivers/mssql/mssql_driver.php
+++ b/system/database/drivers/mssql/mssql_driver.php
@@ -421,14 +421,16 @@ class CI_DB_mssql_driver extends CI_DB {
* @param array the where clause
* @return string
*/
- function _update($table, $values, $where)
+ function _update($table, $values, $where, $limit = FALSE)
{
foreach($values as $key => $val)
{
$valstr[] = $key." = ".$val;
}
+
+ $limit = (!$limit) ? '' : ' LIMIT '.$limit;
- return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where);
+ return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$limit;
}
// --------------------------------------------------------------------
diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php
index 2d91c5927..aaa9cc635 100644
--- a/system/database/drivers/mysql/mysql_driver.php
+++ b/system/database/drivers/mysql/mysql_driver.php
@@ -439,14 +439,16 @@ class CI_DB_mysql_driver extends CI_DB {
* @param array the where clause
* @return string
*/
- function _update($table, $values, $where)
+ function _update($table, $values, $where, $limit = FALSE)
{
foreach($values as $key => $val)
{
$valstr[] = $key." = ".$val;
}
+
+ $limit = (!$limit) ? '' : ' LIMIT '.$limit;
- return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where);
+ return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$limit;
}
// --------------------------------------------------------------------
diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php
index 099117097..f6f106eba 100644
--- a/system/database/drivers/mysqli/mysqli_driver.php
+++ b/system/database/drivers/mysqli/mysqli_driver.php
@@ -432,14 +432,16 @@ class CI_DB_mysqli_driver extends CI_DB {
* @param array the where clause
* @return string
*/
- function _update($table, $values, $where)
+ function _update($table, $values, $where, $limit = FALSE)
{
foreach($values as $key => $val)
{
$valstr[] = $key." = ".$val;
}
+
+ $limit = (!$limit) ? '' : ' LIMIT '.$limit;
- return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where);
+ return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$limit;
}
// --------------------------------------------------------------------
diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php
index e6bcefef1..1dd157cca 100644
--- a/system/database/drivers/oci8/oci8_driver.php
+++ b/system/database/drivers/oci8/oci8_driver.php
@@ -535,14 +535,16 @@ class CI_DB_oci8_driver extends CI_DB {
* @param array the where clause
* @return string
*/
- function _update($table, $values, $where)
+ function _update($table, $values, $where, $limit = FALSE)
{
foreach($values as $key => $val)
{
$valstr[] = $key." = ".$val;
}
-
- return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where);
+
+ $limit = (!$limit) ? '' : ' LIMIT '.$limit;
+
+ return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$limit;
}
// --------------------------------------------------------------------
diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php
index 5e1676244..66d5f89b9 100644
--- a/system/database/drivers/odbc/odbc_driver.php
+++ b/system/database/drivers/odbc/odbc_driver.php
@@ -394,14 +394,16 @@ class CI_DB_odbc_driver extends CI_DB {
* @param array the where clause
* @return string
*/
- function _update($table, $values, $where)
+ function _update($table, $values, $where, $limit = FALSE)
{
foreach($values as $key => $val)
{
$valstr[] = $key." = ".$val;
}
+
+ $limit = (!$limit) ? '' : ' LIMIT '.$limit;
- return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where);
+ return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$limit;
}
// --------------------------------------------------------------------
diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php
index e54f9cceb..076d87a58 100644
--- a/system/database/drivers/postgre/postgre_driver.php
+++ b/system/database/drivers/postgre/postgre_driver.php
@@ -423,14 +423,16 @@ class CI_DB_postgre_driver extends CI_DB {
* @param array the where clause
* @return string
*/
- function _update($table, $values, $where)
+ function _update($table, $values, $where, $limit = FALSE)
{
foreach($values as $key => $val)
{
$valstr[] = $key." = ".$val;
}
+
+ $limit = (!$limit) ? '' : ' LIMIT '.$limit;
- return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where);
+ return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$limit;
}
// --------------------------------------------------------------------
diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php
index aa6738c03..b701d6b96 100644
--- a/system/database/drivers/sqlite/sqlite_driver.php
+++ b/system/database/drivers/sqlite/sqlite_driver.php
@@ -418,14 +418,16 @@ class CI_DB_sqlite_driver extends CI_DB {
* @param array the where clause
* @return string
*/
- function _update($table, $values, $where)
+ function _update($table, $values, $where, $limit = FALSE)
{
foreach($values as $key => $val)
{
$valstr[] = $key." = ".$val;
}
+
+ $limit = (!$limit) ? '' : ' LIMIT '.$limit;
- return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where);
+ return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$limit;
}
// --------------------------------------------------------------------
diff --git a/user_guide/changelog.html b/user_guide/changelog.html
index 55edb75d1..96e5724c0 100644
--- a/user_guide/changelog.html
+++ b/user_guide/changelog.html
@@ -69,6 +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 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>