_db_create_field_sql

  1. drupal
    1. drupal6
    2. drupal6 database.pgsql.inc
Versionen
drupal6 _db_create_field_sql($name, $spec)

Create an SQL string for a field to be used in table creation or alteration.

Before passing a field out of a schema definition into this function it has to be processed by _db_process_field().

Übergabeparameter

$name Name of the field.

$spec The field specification, as per the schema data structure format.

Verwandte Themen

Code

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

<?php
function _db_create_field_sql($name, $spec) {
  $sql = "`" . $name . "` " . $spec['mysql_type'];

  if (in_array($spec['type'], array('varchar', 'char', 'text')) && isset($spec['length'])) {
    $sql .= '(' . $spec['length'] . ')';
  }
  elseif (isset($spec['precision']) && isset($spec['scale'])) {
    $sql .= '(' . $spec['precision'] . ', ' . $spec['scale'] . ')';
  }

  if (!empty($spec['unsigned'])) {
    $sql .= ' unsigned';
  }

  if (!empty($spec['not null'])) {
    $sql .= ' NOT NULL';
  }

  if (!empty($spec['auto_increment'])) {
    $sql .= ' auto_increment';
  }

  if (isset($spec['default'])) {
    if (is_string($spec['default'])) {
      $spec['default'] = "'" . $spec['default'] . "'";
    }
    $sql .= ' DEFAULT ' . $spec['default'];
  }

  if (empty($spec['not null']) && !isset($spec['default'])) {
    $sql .= ' DEFAULT NULL';
  }

  return $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