function hook_chado_query_alter

2.x tripal_core.chado_query.api.inc hook_chado_query_alter(&$sql, &$args)
3.x tripal_chado.query.api.inc hook_chado_query_alter(&$sql, &$args)

This hook provides a way for module developers to alter any/all queries on the chado schema by Tripal.

Example: a module developer might want to remove schema prefixing from queries and rely on the search path. This alter hook would allow them to do that by implementing mymodule_chado_query_alter($sql, $args) and using a regular expression to remove table prefixing from the query.

Parameters

$sql: A string describing the SQL query to be executed by Tripal. All parameters should be indicated by :tokens with values being in the $args array and all tables should be prefixed with the schema name described in tripal_get_schema_name().

$args: An array of arguments where the key is the token used in $sql (for example, :value) and the value is the value you would like substituted in.

Related topics

1 invocation of hook_chado_query_alter()
chado_query in tripal_core/api/tripal_core.chado_query.api.inc
Use this function instead of db_query() to avoid switching databases when making query to the chado database.

File

tripal_core/api/tripal_core.chado_query.api.inc, line 1581
Provides an API for querying of chado including inserting, updating, deleting and selecting from chado.

Code

function hook_chado_query_alter(&$sql, &$args) {

  // The following code is an example of how this alter function might be used.
  // Say you would like only a portion of node => feature connections available
  // for a period of time or under a specific condition. To "hide" the other connections
  // you might create a temporary view of the chado_feature table that only includes
  // the connections you would like to be available. In order to ensure this view
  // is used rather than the original chado_feature table you could alter all Tripal
  // queries referring to chado_feature to instead refer to your view.
  if (preg_match('/(\w+)\.chado_feature/', $sql, $matches)) {

    $sql = str_replace(
    $matches[1] . '.chado_feature', 
    'chado_feature_view', 
    $sql
    );
  }
}