db_create_table_sql

  1. drupal
    1. drupal6
    2. drupal6 database.pgsql.inc
Versionen
drupal6 db_create_table_sql($name, $table)

Generate SQL to create a new table from a Drupal schema definition.

Übergabeparameter

$name The name of the table to create.

$table A Schema API table definition array.

Rückgabewert

An array of SQL statements to create the table.

Verwandte Themen

Code

includes/database.mysql-common.inc, line 60

<?php
function db_create_table_sql($name, $table) {

  if (empty($table['mysql_suffix'])) {
    $table['mysql_suffix'] = '/*!40100 DEFAULT CHARACTER SET utf8';
    // By default, MySQL uses the default collation for new tables, which is
    // 'utf8_general_ci' for utf8. If an alternate collation has been set, it
    // needs to be explicitly specified.
    // @see db_connect()
    $collation = (!empty($table['collation']) ? $table['collation'] : (!empty($GLOBALS['db_collation']) ? $GLOBALS['db_collation'] : ''));
    if ($collation) {
      $table['mysql_suffix'] .= ' COLLATE ' . $collation;
    }
    $table['mysql_suffix'] .= ' */';
  }

  $sql = "CREATE TABLE {" . $name . "} (\n";

  // Add the SQL statement for each field.
  foreach ($table['fields'] as $field_name => $field) {
    $sql .= _db_create_field_sql($field_name, _db_process_field($field)) . ", \n";
  }

  // Process keys & indexes.
  $keys = _db_create_keys_sql($table);
  if (count($keys)) {
    $sql .= implode(", \n", $keys) . ", \n";
  }

  // Remove the last comma and space.
  $sql = substr($sql, 0, -3) . "\n) ";

  $sql .= $table['mysql_suffix'];

  return array($sql);
}
?>

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