db_change_column

  1. drupal
    1. drupal6
    2. drupal7
Versionen
drupal6 – drupal7 db_change_column(&$ret, $table, $column, $column_new, $type, $attributes = array())

Change a column definition using syntax appropriate for PostgreSQL. Save result of SQL commands in $ret array.

Remember that changing a column definition involves adding a new column and dropping an old one. This means that any indices, primary keys and sequences from serial-type columns are dropped and might need to be recreated.

Übergabeparameter

$ret Array to which results will be added.

$table Name of the table, without {}

$column Name of the column to change

$column_new New name for the column (set to the same as $column if you don't want to change the name)

$type Type of column

$attributes Additional optional attributes. Recognized attributes: not null => TRUE|FALSE default => NULL|FALSE|value (with or without '', it won't be added)

Rückgabewert

nothing, but modifies $ret parameter.

▾ 1 function calls db_change_column()

statistics_update_1000 in modules/statistics/statistics.install
Changes session ID field to VARCHAR(64) to add support for SHA-1 hashes.

Code

./update.php, line 107

<?php
function db_change_column(&$ret, $table, $column, $column_new, $type, $attributes = array()) {
  if (array_key_exists('not null', $attributes) and $attributes['not null']) {
    $not_null = 'NOT NULL';
  }
  if (array_key_exists('default', $attributes)) {
    if (is_null($attributes['default'])) {
      $default_val = 'NULL';
      $default = 'default NULL';
    }
    elseif ($attributes['default'] === FALSE) {
      $default = '';
    }
    else {
      $default_val = "$attributes[default]";
      $default = "default $attributes[default]";
    }
  }

  $ret[] = update_sql("ALTER TABLE {" . $table . "} RENAME $column TO " . $column . "_old");
  $ret[] = update_sql("ALTER TABLE {" . $table . "} ADD $column_new $type");
  $ret[] = update_sql("UPDATE {" . $table . "} SET $column_new = " . $column . "_old");
  if ($default) {
    $ret[] = update_sql("ALTER TABLE {" . $table . "} ALTER $column_new SET $default");
  }
  if ($not_null) {
    $ret[] = update_sql("ALTER TABLE {" . $table . "} ALTER $column_new SET NOT NULL");
  }
  $ret[] = update_sql("ALTER TABLE {" . $table . "} DROP " . $column . "_old");
}
?>

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