function chado_get_db

3.x tripal_chado.db.api.inc chado_get_db($identifiers, $options = array())

Retrieves a chado db variable.

Example Usage:

  $select_values = array(
    'name' => 'SOFP'
  );
  $db_object = chado_get_db($select_values);

The above code selects the SOFP db and returns the following object:

  $db_object = stdClass Object (
    [db_id] => 49
    [name] => SOFP
    [description] =>
    [urlprefix] =>
    [url] =>
  );

Parameters

$identifier: An array with the key stating what the identifier is. Supported keys (only on of the following unique keys is required):

  • db_id: the chado db.db_id primary key.
  • name: the chado db.name field (assume unique).

$options: An array of options. Supported keys include:

  • Any keys supported by chado_generate_var(). See that function definition for additional details.

NOTE: the $identifier parameter can really be any array similar to $values passed into chado_select_record(). It should fully specify the db record to be returned.

Return value

If unique values were passed in as an identifier then an object describing the cv will be returned (will be a chado variable from chado_generate_var()). Otherwise, an array of objects will be returned.

Related topics

4 calls to chado_get_db()
chado_insert_cvterm in tripal_chado/api/modules/tripal_chado.cv.api.inc
Add's a controlled vocabulary term to Chado.
TaxonomyImporter::addDbxref in tripal_chado/includes/TripalImporter/TaxonomyImporter.inc
tripal_chado_load_ontologies in tripal_chado/includes/setup/tripal_chado.setup.inc
tripal_get_db in tripal_chado/api/modules/tripal_chado.module.DEPRECATED.api.inc
Retrieves a chado db variable.

File

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

Code

function chado_get_db($identifiers, $options = array()) {

  // Set Defaults.
  if (!isset($options['include_fk'])) {
    // Tells chado_generate_var not to follow any foreign keys.
    $options['include_fk'] = array();
  }

  // Error Checking of parameters.
  if (!is_array($identifiers)) {
    tripal_report_error(
    'tripal_chado_database_api', 
    TRIPAL_ERROR, 
    "chado_get_db: The identifier passed in is expected to be an array with the key
        matching a column name in the db table (ie: db_id or name). You passed in %identifier.", 
    array(
      '%identifier' => print_r($identifiers, TRUE)
    )
    );
  }
  elseif (empty($identifiers)) {
    tripal_report_error(
    'tripal_chado_database_api', 
    TRIPAL_ERROR, 
    "chado_get_db: You did not pass in anything to identify the db you want. The identifier
        is expected to be an array with the key matching a column name in the db table
        (ie: db_id or name). You passed in %identifier.", 
    array(
      '%identifier' => print_r($identifiers, TRUE)
    )
    );
  }

  // Try to get the db.
  $db = chado_generate_var(
  'db', 
  $identifiers, 
  $options
  );

  // Ensure the db is singular. If it's an array then it is not singular.
  if (is_array($db)) {
    tripal_report_error(
    'tripal_chado_database_api', 
    TRIPAL_ERROR, 
    "chado_get_db: The identifiers you passed in were not unique. You passed in %identifier.", 
    array(
      '%identifier' => print_r($identifiers, TRUE)
    )
    );
  }

  // Report an error if $db is FALSE since then chado_generate_var has failed.
  elseif ($db === FALSE) {
    tripal_report_error(
    'tripal_chado_database_api', 
    TRIPAL_ERROR, 
    "chado_get_db: chado_generate_var() failed to return a db based on the identifiers
        you passed in. You should check that your identifiers are correct, as well as, look
        for a chado_generate_var error for additional clues. You passed in %identifier.", 
    array(
      '%identifier' => print_r($identifiers, TRUE)
    )
    );
  }

  // Else, as far we know, everything is fine so give them their db :)
  else {
    return $db;
  }
}