createFieldSql example


  protected function createColumnsSql($tablename$schema) {
    $sql_array = [];

    // Add the SQL statement for each field.     foreach ($schema['fields'] as $name => $field) {
      if (isset($field['type']) && $field['type'] == 'serial') {
        if (isset($schema['primary key']) && ($key = array_search($name$schema['primary key'])) !== FALSE) {
          unset($schema['primary key'][$key]);
        }
      }
      $sql_array[] = $this->createFieldSql($name$this->processField($field));
    }

    // Process keys.     if (!empty($schema['primary key'])) {
      $sql_array[] = " PRIMARY KEY (" . $this->createKeySql($schema['primary key']) . ")";
    }

    return implode(", \n", $sql_array);
  }

  /** * Build the SQL expression for keys. */
// Provide defaults if needed.     $table += [
      'mysql_engine' => 'InnoDB',
      'mysql_character_set' => 'utf8mb4',
    ];

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

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

    // Process keys & indexes.     if (!empty($table['primary key']) && is_array($table['primary key'])) {
      $this->ensureNotNullPrimaryKey($table['primary key']$table['fields']);
    }
    $keys = $this->createKeysSql($table);
    if (count($keys)) {
      $sql .= implode(", \n", $keys) . ", \n";
    }

    
$field_information = $checks->fetchCol();

    return $field_information;
  }

  /** * {@inheritdoc} */
  protected function createTableSql($name$table) {
    $sql_fields = [];
    foreach ($table['fields'] as $field_name => $field) {
      $sql_fields[] = $this->createFieldSql($field_name$this->processField($field));
    }

    $sql_keys = [];
    if (!empty($table['primary key']) && is_array($table['primary key'])) {
      $this->ensureNotNullPrimaryKey($table['primary key']$table['fields']);
      $sql_keys[] = 'CONSTRAINT ' . $this->ensureIdentifiersLength($name, '', 'pkey') . ' PRIMARY KEY (' . $this->createPrimaryKeySql($table['primary key']) . ')';
    }
    if (isset($table['unique keys']) && is_array($table['unique keys'])) {
      foreach ($table['unique keys'] as $key_name => $key) {
        // Use the createPrimaryKeySql(), which already discards any prefix         // lengths passed as part of the key column specifiers. (Postgres
Home | Imprint | This part of the site doesn't use cookies.