function tripal_core_chado_prepare
1.x tripal_core_chado.api.inc | tripal_core_chado_prepare($statement_name, $psql, $args) |
Prepare a chado query
Parameters
$statement_name: The name of the prepared statement
$psql: The SQL statement to be executed via chado_query. Should be of the form PREPARE [statement name] AS [SQL Statement to be prepared]
$args: An array of arguements required to execute the prepared statement. The keys of the array should correspond to the variables in the prepared statement and the value should be the type of value needed (ie: text, int, etc.)
9 calls to tripal_core_chado_prepare()
- tripal_core_chado_insert in tripal_core/
api/ tripal_core_chado.api.inc - Provides a generic routine for inserting into any Chado table
- tripal_core_chado_select in tripal_core/
api/ tripal_core_chado.api.inc - Provides a generic routine for selecting data from a Chado table
- tripal_cv_add_cvterm in tripal_cv/
api/ tripal_cv.api.inc - Add's a CV term to the cvterm table. If the parent CV does not exist then that too is added to the CV table. If the cvterm is a relationship term then the $is_relationship argument should be set. The function will try to first find the…
- tripal_feature_get_feature_relationships in tripal_feature/
api/ tripal_feature.api.inc - Using the tripal_core_expand_chado_vars function to retrieve a set of relationships can be very slow, especialy if there are many relationships This function is intended to help speed up the retrieval of relationships by only retrieving the base…
- tripal_feature_get_formatted_sequence in tripal_feature/
api/ tripal_feature.api.inc - Retrieves the sequence for a feature.
File
- tripal_core/
api/ tripal_core_chado.api.inc, line 3038 - The Tripal Core API
Code
function tripal_core_chado_prepare($statement_name, $psql, $args) {
global $persistent_chado;
global $prepared_statements;
if (!$persistent_chado) {
watchdog('tripal_core', "chado_prepare: not able to prepare '%name' statement as no persistent connection is available", array('%name' => $statement_name, '%sql' => $psql), WATCHDOG_ERROR);
return FALSE;
}
// Check to see if this statement was already prepared
if (tripal_core_is_sql_prepared($statement_name)) {
// check that the arguments are the same
$prepared_args = $prepared_statements[$statement_name]['prepared_args'];
$prepared_sql = $prepared_statements[$statement_name]['prepared_sql'];
if ($prepared_args == $args) {
// This statement is already prepared
return TRUE;
}
else {
// Although a statement with this name is already prepared it is not the same!
watchdog('tripal_core', "chado_prepare: '%name' statement already prepared with different arguments! " .
"You want to prepare \n%sql\n with \n%values\n and the existing statement is \n%esql\n with \n%existing",
array('%name' => $statement_name, '%sql' => $psql, '%values' => print_r($args, TRUE), '%esql' => $prepared_sql,
'%existing' => print_r($prepared_args, TRUE)), WATCHDOG_ERROR);
return FALSE;
}
}
$status = chado_query($psql);
if (!$status) {
watchdog('tripal_core', "chado_prepare: not able to prepare '%name' statement for: %sql", array('%name' => $statement_name, '%sql' => $psql), WATCHDOG_ERROR);
return FALSE;
}
else {
$prepared_statements[$statement_name] = array();
$prepared_statements[$statement_name]['prepared_args'] = $args;
$prepared_statements[$statement_name]['prepared_sql'] = $psql;
return TRUE;
}
}