function chado_delete_custom_table

2.x chado_delete_custom_table($table_id)

Deletes the specified custom table


$table_id: The unique ID of the custom table for the action to be performed on

Related topics

1 call to chado_delete_custom_table()
tripal_custom_tables_delete_form_submit in tripal_core/includes/
form submit hook for the tripal_custom_tables_delete_form form.


tripal_core/api/, line 319
Provides an API to manage custom tables in Chado.


function chado_delete_custom_table($table_id) {
  global $user;

  $args = array("$table_id");
  if (!$table_id) {
    return '';

  // get this table details
  $sql = "SELECT * FROM {tripal_custom_tables} WHERE table_id = :table_id";
  $results = db_query($sql, array(':table_id' => $table_id));
  $custom_table = $results->fetchObject();

  // if this is a materialized view then don't allow deletion with this function
  if ($custom_table->mview_id) {
    tripal_report_error('tripal_core', TRIPAL_ERROR, "Please use the tripal_delete_mview() function to delete this custom table as it is a materialized view. Table not deleted.", array());
    drupal_set_message("This custom table is a materialized view. Please use the " . l('Materialized View', 'admin/tripal/schema/mviews') . " interface to delete it.", 'error');
    return FALSE;

  // remove the entry from the tripal_custom tables table
  $sql = "DELETE FROM {tripal_custom_tables} WHERE table_id = $table_id";
  $success = db_query($sql);
  if ($success) {
    drupal_set_message(t("Custom Table '%name' removed", array('%name' => $custom_table->table_name)));

  // drop the table from chado if it exists
  if (chado_table_exists($custom_table->table_name)) {
    $success = chado_query("DROP TABLE {" . $custom_table->table_name . "}");
    if ($success) {
      drupal_set_message(t("Custom Table '%name' dropped", array('%name' => $custom_table->table_name)));
    else {
      tripal_report_error('tripal_core', TRIPAL_ERROR, "Cannot drop the custom table: %name", array('%name' => $custom_table->table_name));
      drupal_set_message(t("Cannot drop the custom table: '%name'", array('%name' => $custom_table->table_name)));