Answers.Body: <p>There is no hook for reading data from the database. There are hooks however for rendering <a href="https://docs.civicrm.org/dev/en/latest/hooks/list/#form-hooks" rel="nofollow noreferrer">forms</a> and <a href="https://docs.civicrm.org/dev/en/latest/hooks/list/#gui-hooks" rel="nofollow noreferrer">pages</a>.</p>
  <p>There is also a hook for api v3 which is called before and after each api call. That hook is called <a href="https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_apiWrappers/" rel="nofollow noreferrer">apiWrapper</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-10-08T14:19:36.627Z
Answers.Text: As you said there is a hook for reading data from the database - can you tell me which one?
Answers.UserDisplayName: emma
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-10-09T12:52:23.200Z
Answers.Text: I believe Jaap dropped a word "no".  There isn't a hook for reading data from the database.  Such a hook would be near impossible to write, because unlike writing to the database, reading the database can happen in many ways - viewing a contact, doing a search, running a report, etc.
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-10-08T13:07:00.703Z
Answers.LastActivityDate: 2020-10-16T07:48:03.413Z
Answers.LastEditDate: 2020-10-16T07:48:03.413Z
Answers.UserDisplayName: Jaap Jansma - CiviCooP
Body: <p>I'm trying to get a little more familiar with writing extensions. I am still struggling with finding the correct / most specific hook function for my patches regularly.</p>
  <p>As a specific example, I am altering an SQL call in sites/all/modules/civicrm/CRM/Case/BAO/Case.php::getCaseActivity().
  So if I want to create an extension for that, I would need a hook function that will be called whenever sth is read from a database table. I checked all the hooks in <a href="https://docs.civicrm.org/dev/en/latest/hooks/" rel="nofollow noreferrer">https://docs.civicrm.org/dev/en/latest/hooks/</a> but couldn't find a suitable one.</p>
  <p>Is there a hook function like that? Is there a more specific alternative to save resources (checking the hook extension each time a database table is called would happen lots of times)?</p>
  <p>Can I create custom hook &quot;call points&quot; to determine at which line of code a hook is called?</p>
  
Tags: <hooks>
Title: Is there a hook that will be called before each database read?
ThreadText: # Is there a hook that will be called before each database read?
  
  (Asked by: username_0 on 2020-10-08)
  
  I'm trying to get a little more familiar with writing extensions. I am still struggling with finding the correct / most specific hook function for my patches regularly.
  
  As a specific example, I am altering an SQL call in sites/all/modules/civicrm/CRM/Case/BAO/Case.php::getCaseActivity().
  So if I want to create an extension for that, I would need a hook function that will be called whenever sth is read from a database table. I checked all the hooks in <https://docs.civicrm.org/dev/en/latest/hooks/> but couldn't find a suitable one.
  
  Is there a hook function like that? Is there a more specific alternative to save resources (checking the hook extension each time a database table is called would happen lots of times)?
  
  Can I create custom hook "call points" to determine at which line of code a hook is called?
  
  **Tags:** hooks
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-10-08. Score: 0 | Accepted answer
  
  There is no hook for reading data from the database. There are hooks however for rendering [forms](https://docs.civicrm.org/dev/en/latest/hooks/list/#form-hooks) and [pages](https://docs.civicrm.org/dev/en/latest/hooks/list/#gui-hooks).
  
  There is also a hook for api v3 which is called before and after each api call. That hook is called [apiWrapper](https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_apiWrappers/)
  
  > **Comments:**
  > **username_0**: As you said there is a hook for reading data from the database - can you tell me which one?  
  > **username_2**: I believe Jaap dropped a word "no".  There isn't a hook for reading data from the database.  Such a hook would be near impossible to write, because unlike writing to the database, reading the database can happen in many ways - viewing a contact, doing a search, running a report, etc.  
  
  ---
  
  