function chado_insert_db

3.x tripal_chado.db.api.inc chado_insert_db($values, $options = array())

Adds a new database to the Chado DB table and returns the DB object.

Parameters

$values: An associative array of the values of the db (those to be inserted):

  • name: The name of the database. This name is usually used as the prefix for CV term accessions.
  • description: (Optional) A description of the database. By default no description is required.
  • url: (Optional) The URL for the database.
  • urlprefix: (Optional) The URL that is to be used as a prefix when constructing a link to a database term.

$options: Optional. An associative array of options that can include:

  • update_existing: Set this to '1' to force an update of the database if it already exists. The default is to not update. If the database exists then nothing is added.

Return value

An object populated with fields from the newly added database. If the database already exists it returns the values in the current entry.

Related topics

34 calls to chado_insert_db()
chado_insert_cvterm in tripal_chado/api/modules/tripal_chado.cv.api.inc
Add's a controlled vocabulary term to Chado.
OBOImporter::addCvtermDbxref in tripal_chado/includes/TripalImporter/OBOImporter.inc
Adds a database reference to a cvterm
tripal_chado_install in tripal_chado/tripal_chado.install
tripal_chado_populate_vocab_DC in tripal_chado/includes/tripal_chado.semweb.inc
Adds the DC database.
tripal_chado_populate_vocab_EDAM in tripal_chado/includes/tripal_chado.semweb.inc
Adds the EDAM database and terms.

... See full list

File

tripal_chado/api/modules/tripal_chado.db.api.inc, line 355
Provides API functions specificially for managing external database reference records in Chado.

Code

function chado_insert_db($values, $options = array()) {

  // Default Values.
  $dbname = $values['name'];
  $description = (isset($values['description'])) ? $values['description'] : '';
  $url = (isset($values['url'])) ? $values['url'] : '';
  $urlprefix = (isset($values['urlprefix'])) ? $values['urlprefix'] : '';
  $update = (isset($options['update_existing'])) ? $options['update_existing'] : TRUE;

  // Build the values array for inserting/updating.
  $ins_values = array(
    'name' => $dbname,
    'description' => $description,
    'url' => $url,
    'urlprefix' => $urlprefix
  );

  // Get the database record if it already exists.
  $sel_values = array('name' => $dbname);
  $result = chado_select_record('db', array('*'), $sel_values);

  // If it does not exists then add it.
  if (count($result) == 0) {
    $ins_options = array('statement_name' => 'ins_db_nadeurur');
    $success = chado_insert_record('db', $ins_values, $ins_options);
    if (!$success) {
      tripal_report_error('tripal_chado', TRIPAL_WARNING, "Cannot create db '$dbname'.", NULL);
      return 0;
    }
    $result = chado_select_record('db', array('*'), $sel_values);
  }
  // If it exists and update is enabled the do the update.
  elseif ($update) {
    $upd_options = array('statement_name' => 'upd_db_nadeurur');
    $success = chado_update_record('db', $sel_values, $ins_values, $upd_options);
    if (!$success) {
      tripal_report_error('tripal_chado', TRIPAL_WARNING, "Cannot update db '$dbname'.", NULL);
      return 0;
    }
    $result = chado_select_record('db', array('*'), $sel_values);
  }

  // Return the database object.
  return $result[0];

}