You are here

function content_db_index_exists in Content Construction Kit (CCK) 6.2

Same name and namespace in other branches
  1. 6.3 content.module \content_db_index_exists()

Checks if an index exists.

@todo: May we remove this funcion when implemented by Drupal core itself? @link http://drupal.org/node/360854 @link http://dev.mysql.com/doc/refman/5.0/en/extended-show.html

Parameters

$table: Name of the table.

$name: Name of the index.

Return value

TRUE if the table exists. Otherwise FALSE.

3 calls to content_db_index_exists()
content_alter_db in includes/content.admin.inc
Perform adds, alters, and drops as needed to synchronize the database with new field definitions.
nodereference_update_6001 in modules/nodereference/nodereference.install
Create an index by node reference column for all fields.
userreference_update_6001 in modules/userreference/userreference.install
Create an index by user reference column for all fields.

File

./content.module, line 2116
Allows administrators to associate custom fields to content types.

Code

function content_db_index_exists($table, $name) {
  global $db_type;
  if ($db_type == 'mysql' || $db_type == 'mysqli') {
    if (version_compare(db_version(), '5.0.3') < 0) {

      // Earlier versions of MySQL don't support a WHERE clause for SHOW.
      $result = db_query('SHOW INDEX FROM {' . $table . '}');
      while ($row = db_fetch_array($result)) {
        if ($row['Key_name'] == $name) {
          return TRUE;
        }
      }
      return FALSE;
    }
    return (bool) db_result(db_query("SHOW INDEX FROM {" . $table . "} WHERE key_name = '{$name}'"));
  }
  elseif ($db_type == 'pgsql') {

    // Note that the index names in Schema API for PostgreSQL are prefixed by
    // the table name and suffixed by '_idx'.
    return (bool) db_result(db_query("SELECT COUNT(indexname) FROM pg_indexes WHERE indexname = '{" . $table . "}_{$name}_idx'"));
  }
  return FALSE;
}