queryTableInformation

  1. drupal
    1. drupal7
Versionen
drupal7 public DatabaseSchema_pgsql::queryTableInformation($table)

Fetch the list of blobs and sequences used on a table.

We introspect the database to collect the information required by insert and update queries.

Übergabeparameter

$table_name The non-prefixed name of the table.

Rückgabewert

An object with two member variables:

  • 'blob_fields' that lists all the blob fields in the table.
  • 'sequences' that lists the sequences used in that table.

Verwandte Themen

Code

includes/database/pgsql/schema.inc, line 40

<?php
public function queryTableInformation($table) {
  // Generate a key to reference this table's information on.
  $key = $this->connection->prefixTables('{' . $table . '}');
  if (!strpos($key, '.')) {
    $key = 'public.' . $key;
  }

  if (!isset($this->tableInformation[$key])) {
    // Split the key into schema and table for querying.
    list($schema, $table_name) = explode('.', $key);
    $table_information = (object) array(
        'blob_fields' => array(),
        'sequences' => array(),
      );
    // Don't use {} around information_schema table.
    $result = db_query("SELECT column_name, data_type, column_default FROM information_schema.columns WHERE table_schema = :schema AND table_name = :table AND (data_type = 'bytea' OR (numeric_precision IS NOT NULL AND column_default LIKE :default))", array(':schema' => $schema, ':table' => $table_name, ':default' => '%nextval%'));
    foreach ($result as $column) {
      if ($column->data_type == 'bytea') {
        $table_information->blob_fields[$column->column_name] = TRUE;
      }
      elseif (preg_match("/nextval\('([^']+)'/", $column->column_default, $matches)) {
        // We must know of any sequences in the table structure to help us
        // return the last insert id. If there is more than 1 sequences the
        // first one (index 0 of the sequences array) will be used.
        $table_information->sequences[] = $matches[1];
      }
    }
    $this->tableInformation[$key] = $table_information;
  }
  return $this->tableInformation[$key];
}
?>

Kommentare

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen