⚠ 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

logging sql queries



o_Odin
  • profile picture
  • Member

Posted 13 January 2013 - 16:49 PM

Hello! I apologize to bother you, but can you tell me, please, can i somehow write sql queries performed grocerycrud (inserts, updates and deletes)?

victor
  • profile picture
  • Member

Posted 14 January 2013 - 07:35 AM

Yes. You can use callback functions as solution

o_Odin
  • profile picture
  • Member

Posted 14 January 2013 - 17:35 PM

Agreed. Unfortunately, this method does not work if i use many-to-many relation. In this case GC performs multiple queries for each junction table, and method $this->db->last_query() in callback is useless. Is there a way to capture these queries without changing the source code?

zrmba
  • profile picture
  • Member

Posted 21 January 2013 - 22:26 PM

Then what about our last exchange on this o_Odin?

Helton Eduardo Ritter
  • profile picture
  • Member

Posted 24 January 2013 - 19:21 PM

maybe it's not the most correct approach, but I have had to log SQL's too, and do it in each controller, each one call theses callbacks was so boring that I've decided to do it inside /application/models/grocery_crud_model.php

Find in that file for: "function db_update($post_array, $primary_key_value)"
And add so in insert, delete methods.

Just take care to put it in the begining of the method. Otherwise, it will not work your n to n relations, because grocery use the last ID inserted, and then the last ID inserted will be from your log table, not from the table related in a n to n relarion.

* See the picture attached, some idea of how do it.

victor
  • profile picture
  • Member

Posted 24 January 2013 - 23:29 PM

Yes, it's correctly.
You can change this library as you like )