⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Query update errors not caught by grocery CRUD?



lherlaar
  • profile picture
  • Member

Posted 20 May 2012 - 11:59 AM

Hi,

I noticed while writing code for graceful handling of database error (such as foreign key violations) that it seems that insert and delete errors are caught by grocery CRUD, but not all update errors.

If I look at the library code, I notice the following:

For insert and delete, the actual query result is returned from the model to the library and stored in a variable:

line 775: $insert_result = $this->basic_model->db_insert($insert_data);
line 1007: $delete_result = $this->basic_model->db_delete($primary_key);

if $insert_result or $delete_result are false, the library function then returns false a few lines below and the error is eventually caught in the insert_layout or delete_layout functions.

For update, however, the library code is:

line 885: $this->basic_model->db_update($update_data, $primary_key);

So, the actual query result is not stored in a variable nor returned and any potential error will not be caught by the update_layout function.

Is this omission a bug or is there a purpose to this difference?

Thanks!

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 21 May 2012 - 07:09 AM

It is not on purpose I just forgot it! Thanks to mention that ( https://github.com/scoumbourdis/grocery-crud/commit/d4fd94dcbd090b8388ba9f3ee936a3c3c84f1529 )