alterTable

  1. drupal
    1. drupal7
Versionen
drupal7 protected DatabaseSchema_sqlite::alterTable(&$ret, $table, $new_schema)

Create a table with a new schema containing the old content.

As SQLite does not support ALTER TABLE (with a few exceptions) it is necessary to create a new table and copy over the old content.

Übergabeparameter

$ret Array to which query results will be added.

$table Name of the table to be altered.

$new_schema The new schema array for the table.

Verwandte Themen

Code

includes/database/sqlite/schema.inc, line 268

<?php
protected function alterTable(&$ret, $table, $new_schema) {
  $i = 0;
  do {
    $new_table = $table . '_' . $i++;
  } while ($this->tableExists($new_table));
  $this->createTable($ret, $new_table, $new_schema);
  $fields = implode(', ', array_keys($new_schema['fields']));
  $ret[] = update_sql('INSERT INTO {' . $new_table . "} ($fields) SELECT $fields FROM {" . $table . '}');
  $old_count = db_query('SELECT COUNT(*) FROM {' . $table . '}')->fetchField();
  $new_count = db_query('SELECT COUNT(*) FROM {' . $new_table . '}')->fetchField();
  if ($old_count == $new_count) {
    do {
      $temp_table = $table . '_' . $i++;
    } while ($this->tableExists($temp_table));
    $this->renameTable($ret, $table, $temp_table);
    $this->renameTable($ret, $new_table, $table);
    $this->dropTable($ret, $temp_table);
  }
}
?>

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