Tripal
Functions
Chado Custom Tables
Collaboration diagram for Chado Custom Tables:

Functions

 chado_edit_custom_table ($table_id, $table_name, $schema, $skip_if_exists=1)
 
 chado_create_custom_table ($table, $schema, $skip_if_exists=TRUE, $mview_id=NULL, $redirect=TRUE)
 
 chado_validate_custom_table_schema ($schema_array)
 
 chado_get_custom_table_id ($table_name)
 
 chado_get_custom_table_names ($include_mview=TRUE)
 
 chado_delete_custom_table ($table_id)
 

Detailed Description

Provides an API to manage custom tables in Chado.

Function Documentation

◆ chado_create_custom_table()

chado_create_custom_table (   $table,
  $schema,
  $skip_if_exists = TRUE,
  $mview_id = NULL,
  $redirect = TRUE 
)

Add a new table to the Chado schema.

This function is simply a wrapper for the db_create_table() function of Drupal, but ensures the table is created inside the Chado schema rather than the Drupal schema. If the table already exists then it will be dropped and recreated using the schema provided. However, it will only drop a table if it exsits in the tripal_custom_tables table. This way the function cannot be used to accidentally alter existing non custom tables. If $skip_if_exists is set then the table is simply added to the tripal_custom_tables and no table is created in Chado.

If you are creating a materialized view do not use this function, but rather use the chado_add_mview(). A materialized view is also considered a custom table and an entry for it will be added to both the tripal_mviews and tripal_custom_tables tables, but only if the chado_add_mview() function is used. The optional $mview_id parameters in this function is intended for use by the chado_add_mview() function when it calls this function to create the table.

Parameters
$tableThe name of the table to create.
$schemaA Drupal-style Schema API definition of the table.
$skip_if_existsSet as TRUE to skip dropping and re-creation of the table if it already exists. This is useful if the table was already created through another means and you simply want to make Tripal aware of the table schema. If the table does not exist it will be created.
$mview_idOptional. If this custom table is also a materialized view then provide it's mview_id. This paramter is intended only when this function is called by the chado_add_mview() function. When creating a custom table you shouldn't need to use this parameter.
$redirectOptional (default: TRUE). By default this function redirects back to admin pages. However, when called by Drush we don't want to redirect. This parameter allows this to be used as a true API function.
Returns
TRUE on success, FALSE on failure.

◆ chado_delete_custom_table()

chado_delete_custom_table (   $table_id)

Deletes the specified custom table.

Parameters
$table_idThe unique ID of the custom table for the action to be performed on.

◆ chado_edit_custom_table()

chado_edit_custom_table (   $table_id,
  $table_name,
  $schema,
  $skip_if_exists = 1 
)

Edits a custom table in the chado database. It supports using the Drupal Schema API array.

Parameters
$table_idThe table_id of the table to edit.
$table_nameThe name of the custom table.
$schemaUse the Schema API array to define the custom table.
$skip_if_existsSet as TRUE to skip dropping and re-creation of the table. This is useful if the table was already created through another means and you simply want to make Tripal aware of the table schema.

◆ chado_get_custom_table_id()

chado_get_custom_table_id (   $table_name)

Retrieve the custom table id given the name.

Parameters
$table_nameThe name of the custom table.
Returns
The unique identifier for the given table.

◆ chado_get_custom_table_names()

chado_get_custom_table_names (   $include_mview = TRUE)

Retrieves the list of custom tables in this site.

Returns
An associative array where the key and value pairs are the table names.

◆ chado_validate_custom_table_schema()

chado_validate_custom_table_schema (   $schema_array)

This function is used to validate a Drupal Schema API array prior to passing it ot the chado_create_custom_table_schema(). This function can be used in a form validate function or whenver a schema is provided by a user and needs validation.

Parameters
$schema_arraythe Drupal Schema API compatible array.
Returns
An empty string for success or a message string for failure.