function chado_delete_mview

3.x tripal_chado.mviews.api.inc chado_delete_mview($mview_id)

Does the specified action for the specified Materialized View.

Parameters

$op: The action to be taken. One of update or delete.

$mview_id: The unique ID of the materialized view for the action to be performed on.

Related topics

3 calls to chado_delete_mview()
tripal_chado_update_7324 in tripal_chado/tripal_chado.install
Updating the db2cv materialized view.
tripal_delete_mview in tripal_chado/api/tripal_chado.DEPRECATED.api.inc
Does the specified action for the specified Materialized View.
tripal_mviews_delete_form_submit in tripal_chado/includes/tripal_chado.mviews.inc
form submit hook for the tripal_custom_tables_delete_form form.

File

tripal_chado/api/tripal_chado.mviews.api.inc, line 313
Provides an application programming interface (API) to manage materialized views in Chado.

Code

function chado_delete_mview($mview_id) {
  global $user;

  if (!$mview_id) {
    return '';
  }

  // Get this mview details.
  $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = :mview_id";
  $results = db_query($sql, array(':mview_id' => $mview_id));
  $mview = $results->fetchObject();

  // If op is to delete then do so.
  // Remove the mview from the tripal_mviews table.
  $sql = "DELETE FROM {tripal_mviews} WHERE mview_id = $mview_id";
  db_query($sql);

  // Does the table already exist?
  $mview_exists = chado_table_exists($mview->mv_table);

  // Drop the table from chado if it exists.
  if ($mview_exists) {
    $sql = "DROP TABLE {" . $mview->mv_table . "}";
    $success = chado_query($sql);
    if ($success) {
      drupal_set_message(t("Materialized view, %name, deleted.", array('%name' => $mview->name)));
    }
    else {
      drupal_set_message(t("Problem deleting materialized view, %name.", array('%name' => $mview->name)), 'error');
    }
  }
}