function tripal_update_mview
2.x tripal_core.DEPRECATED.api.inc | tripal_update_mview($mview_id) |
3.x tripal_core.DEPRECATED.inc | tripal_update_mview($mview_id) |
1.x tripal_core_mviews.api.inc | tripal_update_mview($mview_id) |
Update a Materialized View
Parameters
$mview_id: The unique identifier for the materialized view to be updated
Return value
True if successful, FALSE otherwise
Related topics
1 call to tripal_update_mview()
- drush_tripal_core_tripal_update_mview in tripal_core/
tripal_core.drush.inc - Updates the specified materialized view
2 string references to 'tripal_update_mview'
- tripal_core_job_describe_args in tripal_core/
tripal_core.module - Implements hook_job_describe_args(). Describes the arguements for the tripal_update_mview job to allow for greater readability in the jobs details pages.
- tripal_mviews_action in tripal_core/
api/ tripal_core_mviews.api.inc - Does the specified action for the specified Materialized View
File
- tripal_core/
api/ tripal_core_mviews.api.inc, line 345 - Contains functions for the Materialized Views API
Code
function tripal_update_mview($mview_id) {
$sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = %d ";
$mview = db_fetch_object(db_query($sql, $mview_id));
if ($mview) {
// execute the query inside a transaction so that it doesn't destroy existing data
// that may leave parts of the site unfunctional
tripal_db_start_transaction();
$previous_db = tripal_db_set_active('chado'); // use chado database
$results = db_query("DELETE FROM {%s}", $mview->mv_table);
$results = db_query("INSERT INTO {%s} ($mview->query)", $mview->mv_table);
tripal_db_set_active($previous_db); // now use drupal database
if ($results) {
// commit the transaction
tripal_db_commit_transaction();
$sql = "SELECT count(*) as cnt FROM {%s}";
$previous_db = tripal_db_set_active('chado'); // use chado database
$count = db_fetch_object(db_query($sql, $mview->mv_table));
tripal_db_set_active($previous_db); // now use drupal database
$record = new stdClass();
$record->mview_id = $mview_id;
$record->last_update = time();
$record->status = "Populated with " . number_format($count->cnt) . " rows";
drupal_write_record('tripal_mviews', $record, 'mview_id');
return TRUE;
}
else {
// rollback the transaction
tripal_db_rollback_transaction();
// print and save the error message
$record = new stdClass();
$record->mview_id = $mview_id;
$record->status = "ERROR populating. See Drupal's recent log entries for details.";
print $record->status . "\n";
drupal_write_record('tripal_mviews', $record, 'mview_id');
return FALSE;
}
}
}