function tripal_get_db

2.x tripal_db.api.inc tripal_get_db($identifiers, $options = array())

Retrieves a chado db variable

Example Usage:

   $select_values = array(
     'name' => 'SOFP'
   );
   $db_object = tripal_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 tripal_get_db()
tripal_db_get_db in tripal_db/api/tripal_db.DEPRECATED.inc
tripal_db_get_db_by_db_id in tripal_db/api/tripal_db.DEPRECATED.inc
tripal_db_get_db_by_name in tripal_db/api/tripal_db.DEPRECATED.inc
tripal_insert_cvterm in tripal_cv/api/tripal_cv.api.inc
Add's a controlled vocabulary term to Chado.
3 string references to 'tripal_get_db'

File

tripal_db/api/tripal_db.api.inc, line 57
Provides an application programming interface (API) to manage references to external databases

Code

function tripal_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_db_api', 
    TRIPAL_ERROR, 
    "tripal_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_db_api', 
    TRIPAL_ERROR, 
    "tripal_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_db_api', 
    TRIPAL_ERROR, 
    "tripal_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_db_api', 
    TRIPAL_ERROR, 
    "tripal_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;
  }
}