[eluser]JustinWyllie[/eluser]
Thanks.
Following what you've explained I tested update_batch() with the obvious case of an error in the first batch of 100 and not in the second. (I'm not 100% certain the batches are in fact per one hundred; I would have to check). In this case _error_message() was clear - presumably the second batch was ok so that is the final result after the call to update_batch even though the first batch of 100 failed and will have produced an error_message.
My suggestion then to use _error_message is wrong. The correct way to use update_batch is as you suggest to use transactions:
Code:
$this->db->trans_start();
$this->db->update_batch('table', $data, 'keyfield');
$this->db->trans_complete();
if ($this->db->trans_status() === FALSE)
{
return false;
}
else
{
return true;
}
I wonder if the reason this isn't in the documentation for update_batch is because CI is trying to support people who don't have transaction enabled databases?
Given that it works as you suggest with transactions and I have InnoBD tables my motivation to look into setting a possible return value (a string of 'ok', 'failed' and 'partial' perhaps?) is not high. And - what good would it do them?
Finally, as a footnote, I also found another anomaly. Tested with update_batch only. If the error is in the naming of the key field the call produces a database error page even if db_debug is off in config. I agree this is a very unlikely scenario.