function chado_get_version

2.x chado_get_version($exact = FALSE, $warn_if_unsupported = FALSE)

Returns the version number of the currently installed Chado instance. It can return the real or effective version. Note, this function is executed in the hook_init() of the tripal_core module which then sets the $GLOBAL['exact_chado_version'] and $GLOBAL['chado_version'] variable. You can access these variables rather than calling this function.

@returns The version of Chado


$exact: Set this argument to 1 to retrieve the exact version that is installed. Otherwise, this function will set the version to the nearest 'tenth'. Chado versioning numbers in the hundreds represent changes to the software and not the schema. Changes in the tenth's represent changes in the schema.

$warn_if_unsupported: If the currently installed version of Chado is not supported by Tripal this generates a Drupal warning.

Related topics

9 calls to chado_get_version()
1 string reference to 'chado_get_version'


tripal_core/api/, line 307


function chado_get_version($exact = FALSE, $warn_if_unsupported = FALSE) {

  global $databases;
  $version = '';
  $is_local = 0;

  // check that Chado is installed if not return 'uninstalled as the version'
  $chado_exists = chado_is_local();
  if (!$chado_exists) {
    // if it's not in the drupal database check to see if it's specified in the $db_url
    // in the settings.php
    if (!array_key_exists(tripal_get_schema_name('chado'), $databases)) {
      // if it's not in the drupal database or specified in the $db_url then
      // return uninstalled as the version
      return 'not installed';
    $is_local = 0;
    $previous_db = chado_set_active('chado');
    $prop_exists = db_table_exists('chadoprop');
  else {
    $is_local = 1;
    // @todo we need a chado aware db_table_exists.
    $prop_exists = db_table_exists(tripal_get_schema_name('chado') . '.chadoprop');

  // if the table doesn't exist then we don't know what version but we know
  // it must be 1.11 or older.
  if (!$prop_exists) {
    $version = "1.11 or older";
  else {
    $sql = "
      SELECT value
      FROM {chadoprop} CP
        INNER JOIN {cvterm} CVT on CVT.cvterm_id = CP.type_id
        INNER JOIN {cv} CV on CVT.cv_id = CV.cv_id
      WHERE = 'chado_properties' and = 'version'
    if (!$is_local) {
      $previous_db = chado_set_active('chado');
      $results = db_query($sql);
    else {
      $results = chado_query($sql);
    $v = $results->fetchObject();

    // if we don't have a version in the chadoprop table then it must be
    // v1.11 or older
    if (!$v) {
      $version = "1.11 or older";
    else {
      $version = $v->value;

  // next get the exact Chado version that is installed
  $exact_version = $version;

  // Tripal only supports v1.11 or newer.. really this is the same as v1.1
  // but at the time the v1.11 schema API was written we didn't know that so
  // we'll return the version 1.11 so the schema API will work.
  if (strcmp($exact_version, '1.11 or older') == 0) {
    $exact_version = "1.11";
    if ($warn_if_unsupported) {
      drupal_set_message(t("WARNING: Tripal does not fully support Chado version less than v1.11.  If you are certain this is v1.11
         or if Chado was installed using an earlier version of Tripal then all is well. If not please upgrade to v1.11 or later"), 

  // if not returing an exact version, return the version to the nearest 10th.
  // return 1.2 for all versions of 1.2x
  $effective_version = $exact_version;
  if (preg_match('/^1\.2\d+$/', $effective_version)) {
    $effective_version = "1.2";
  else if (preg_match('/^1\.3\d+$/', $effective_version)) {
    $effective_version = "1.3";
  if ($warn_if_unsupported and ($effective_version < 1.11 and $effective_version != 'not installed')) {
    drupal_set_message(t("WARNING: The currently installed version of Chado, v$exact_version, is not fully compatible with Tripal."), 'warning');
  // if the callee has requested the exact version then return it
  if ($exact) {
    return $exact_version;

  return $effective_version;