(Similar bug #4871 I think)
Started since v3.1.2: example code:
$data = array(
array(
'setting_key' => 'test',
'setting_value' => 'test'
)
);
$this->db->where('user_id', 1);
$this->db->update_batch('settingstable', $data, 'setting_key');`
Returning
ERROR - 2016-10-31 10:05:32 --> Severity: Notice --> Undefined index: setting_key system\database\DB_query_builder.php 1949
ERROR - 2016-10-31 10:05:32 --> Severity: Notice --> Undefined index: setting_key system\database\DB_query_builder.php 1955
ERROR - 2016-10-31 10:05:32 --> Severity: Notice --> Undefined index: setting_key system\database\DB_query_builder.php 1955
Line 1949
$ids[] = $val[$index];
The items in $val are escaped and the $index search on non escaped name. I think the keys shouldn't be escaped?
I have come across the same issue with v3.1.2
Using the example data below:
$data = array(
array(
'title' => 'My title' ,
'name' => 'My Name 2' ,
'date' => 'My date 2'
),
array(
'title' => 'Another title' ,
'name' => 'Another Name 2' ,
'date' => 'Another date 2'
)
);
$this->db->update_batch('mytable', $data, 'title');
Produces the following incorrectly formed query
UPDATE
mytableSETtitle= CASE WHENtitle= THEN 'My title' WHENtitle= THEN 'Another title' ELSEtitleEND,name= CASE WHENtitle= THEN 'My Name 2' WHENtitle= THEN 'Another Name 2' ELSEnameEND,date= CASE WHENtitle= THEN 'My date 2' WHENtitle= THEN 'Another date 2' ELSEdateEND WHEREtitleIN(,)
Prior to Fix #4871
UPDATE
mytableSETname= CASE WHENtitle= 'My title' THEN 'My Name 2' WHENtitle= 'Another title' THEN 'Another Name 2' ELSEnameEND,date= CASE WHENtitle= 'My title' THEN 'My date 2' WHENtitle= 'Another title' THEN 'Another date 2' ELSEdateEND WHEREtitleIN('My title','Another title')
I have found that replacing the $index argument back to $this->protect_identifiers($index) in the update_batch function in DB_query_builder.php on the following line will fix the creation of these batch update SQL statements. I am unsure if this will affect anything else? Can anyone else confirm this?
if ($this->query($this->_update_batch($this->protect_identifiers($table, TRUE, NULL, FALSE), array_slice($this->qb_set, $i, $batch_size), $index)))
I have the same issue, please fix this as soon as possible
Same here, a fix is more than welcome.
I'll go back to 3.1.0 until this is solved.
Please test with 8338bbb3586e31432caa503b6530dcea583dd8d8
@narfbg just tested, looks good! Thanks
Most helpful comment
I have found that replacing the
$indexargument back to$this->protect_identifiers($index)in the update_batch function in DB_query_builder.php on the following line will fix the creation of these batch update SQL statements. I am unsure if this will affect anything else? Can anyone else confirm this?https://github.com/bcit-ci/CodeIgniter/blob/84f5366a8d76fe935a57cb9dbf61c970d98a0a27/system/database/DB_query_builder.php#L1918