summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--system/database/DB_query_builder.php43
-rw-r--r--user_guide_src/source/changelog.rst1
2 files changed, 29 insertions, 15 deletions
diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php
index c180a17e9..be7582815 100644
--- a/system/database/DB_query_builder.php
+++ b/system/database/DB_query_builder.php
@@ -1458,20 +1458,26 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
* @param bool $escape Whether to escape values and identifiers
* @return int Number of rows inserted or FALSE on failure
*/
- public function insert_batch($table = '', $set = NULL, $escape = NULL)
+ public function insert_batch($table, $set = NULL, $escape = NULL)
{
- if ($set !== NULL)
+ if ($set === NULL)
{
- $this->set_insert_batch($set, '', $escape);
+ if (empty($this->qb_set))
+ {
+ return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE;
+ }
}
-
- if (count($this->qb_set) === 0)
+ else
{
- // No valid data array. Folds in cases where keys and values did not match up
- return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE;
+ if (empty($set))
+ {
+ return ($this->db_debug) ? $this->display_error('insert_batch() called with no data') : FALSE;
+ }
+
+ $this->set_insert_batch($set, '', $escape);
}
- if ($table === '')
+ if (strlen($table) === 0)
{
if ( ! isset($this->qb_from[0]))
{
@@ -1859,7 +1865,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
* @param string the where key
* @return int number of rows affected or FALSE on failure
*/
- public function update_batch($table = '', $set = NULL, $index = NULL)
+ public function update_batch($table, $set = NULL, $index = NULL)
{
// Combine any cached components with the current statements
$this->_merge_cache();
@@ -1869,17 +1875,24 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
return ($this->db_debug) ? $this->display_error('db_must_use_index') : FALSE;
}
- if ($set !== NULL)
+ if ($set === NULL)
{
- $this->set_update_batch($set, $index);
+ if (empty($this->qb_set))
+ {
+ return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE;
+ }
}
-
- if (count($this->qb_set) === 0)
+ else
{
- return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE;
+ if (empty($set))
+ {
+ return ($this->db_debug) ? $this->display_error('update_batch() called with no data') : FALSE;
+ }
+
+ $this->set_update_batch($set, $index);
}
- if ($table === '')
+ if (strlen($table) === 0)
{
if ( ! isset($this->qb_from[0]))
{
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 466726a7e..1623341ea 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -13,6 +13,7 @@ Bug fixes for 3.0.5
- Fixed a bug (#4391) - :doc:`Email Library <libraries/email>` method ``reply_to()`` didn't apply Q-encoding.
- Fixed a bug (#4384) - :doc:`Pagination Library <libraries/pagination>` ignored (possible) *cur_page* configuration value.
- Fixed a bug (#4395) - :doc:`Query Builder <database/query_builder>` method ``count_all_results()`` still fails if an ``ORDER BY`` condition is used.
+- Fixed a bug (#4399) - :doc:`Query Builder <database/query_builder>` methods ``insert_batch()``, ``update_batch()`` produced confusing error messages when called with no data and *db_debug* is enabled.
Version 3.0.4
=============