You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public function update_batch($table, $set = NULL, $index = NULL, $batch_size = 100)
{
// Combine any cached components with the current statements
$this->_merge_cache();
if ($index === NULL)
{
return ($this->db_debug) ? $this->display_error('db_must_use_index') : FALSE;
}
if ($set === NULL)
{
if (empty($this->qb_set_ub))
{
return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE;
}
}
else
{
if (empty($set))
{
return ($this->db_debug) ? $this->display_error('update_batch() called with no data') : FALSE;
}
$this->set_update_batch($set, $index);
}
if (strlen($table) === 0)
{
if ( ! isset($this->qb_from[0]))
{
return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
}
$table = $this->qb_from[0];
}
// Batch this baby
$affected_rows = 0;
for ($i = 0, $total = count($this->qb_set_ub); $i < $total; $i += $batch_size)
{
if ($this->query($this->_update_batch($this->protect_identifiers($table, TRUE, NULL, FALSE), array_slice($this->qb_set_ub, $i, $batch_size), $index)))
{
$affected_rows += $this->affected_rows();
}
$this->qb_where = array();
}
$this->_reset_write();
return $affected_rows;
}
PATCHED VERSION
public function update_batch($table, $set = NULL, $index = NULL, $batch_size = 100)
{
// Combine any cached components with the current statements
$this->_merge_cache();
/////<-------------------- REMOVE INDEX SECTION AND PUT BELOW
if ($set === NULL)
{
if (empty($this->qb_set_ub))
{
return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE;
}
}
else
{
if (empty($set))
{
return ($this->db_debug) ? $this->display_error('update_batch() called with no data') : FALSE;
}
$this->set_update_batch($set, $index);
}
if (strlen($table) === 0)
{
if ( ! isset($this->qb_from[0]))
{
return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
}
$table = $this->qb_from[0];
}
// Batch this baby
$affected_rows = 0;
for ($i = 0, $total = count($this->qb_set_ub); $i < $total; $i += $batch_size)
{
$qb_set_ub = current($this->qb_set_ub[$i]); /////<-------------------- NEW LINE
$index = $index !== NULL ? $index : ($qb_set_ub['index'] !== NULL ? $qb_set_ub['index'] : NULL) ; /////<-------------------- NEW LINE
if ($index === NULL) /////<-------------------- SECTION THAT WAS REMOVED FROM ABOVE
{
return ($this->db_debug) ? $this->display_error('db_must_use_index') : FALSE;
}
if ($this->query($this->_update_batch($this->protect_identifiers($table, TRUE, NULL, FALSE), array_slice($this->qb_set_ub, $i, $batch_size), $index)))
{
$affected_rows += $this->affected_rows();
}
$this->qb_where = array();
}
$this->_reset_write();
return $affected_rows;
}
ps. I love CI-3.. query builder is awesome.. I am not moving to CI4 because all I need is simple MVC classes, awesome query builder, simple global post retriever, simple DB integration and I've also customised the query builder for JSON functions. I don't need any other bells and whistles like form validation, front-end stuff, etc. I feel that the power of a php framework is the framework / architecture / security / extensibility, .. it just needs to accommodate and stack other tech and take care of cyber threats.
The text was updated successfully, but these errors were encountered:
@narfbg
I think this is a bug.
To recreate:
$this->db->set_update_batch($dataArrBatch,'index_col')->update_batch('table_name');
Gives error:
"You must specify an index to match on for batch updates."
Hypothesis:
The index parameter in the set_update_batch() function is not parsing to the ->update_batch function
Disclaimer:
Maybe I've completely overlooked the correct usage and assumed the wrong behaviours.. so if that's the case I apologise in advance.
My workaround / patch:
OLD VERSION
PATCHED VERSION
OLD VERSION
PATCHED VERSION
ps. I love CI-3.. query builder is awesome.. I am not moving to CI4 because all I need is simple MVC classes, awesome query builder, simple global post retriever, simple DB integration and I've also customised the query builder for JSON functions. I don't need any other bells and whistles like form validation, front-end stuff, etc. I feel that the power of a php framework is the framework / architecture / security / extensibility, .. it just needs to accommodate and stack other tech and take care of cyber threats.
The text was updated successfully, but these errors were encountered: