ensureNotNullPrimaryKey example



    $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";
    }

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

    $sql .= 'ENGINE = ' . $table['mysql_engine'] . ' DEFAULT CHARACTER SET ' . $table['mysql_character_set'];
    // By default, MySQL uses the default collation for new tables, which is
/** * {@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         // doesn't support setting a prefix length for PRIMARY or UNIQUE         // indices.)         $sql_keys[] = 'CONSTRAINT ' . $this->ensureIdentifiersLength($name$key_name, 'key') . ' UNIQUE (' . $this->createPrimaryKeySql($key) . ')';
      }
    }

    

  public function fieldExists($table$column) {
    $schema = $this->introspectSchema($table);
    return !empty($schema['fields'][$column]);
  }

  /** * {@inheritdoc} */
  public function createTableSql($name$table) {
    if (!empty($table['primary key']) && is_array($table['primary key'])) {
      $this->ensureNotNullPrimaryKey($table['primary key']$table['fields']);
    }

    $sql = [];
    $sql[] = "CREATE TABLE {" . $name . "} (\n" . $this->createColumnsSql($name$table) . "\n)\n";
    return array_merge($sql$this->createIndexSql($name$table));
  }

  /** * Build the SQL expression for indexes. */
  protected function createIndexSql($tablename$schema) {
    
Home | Imprint | This part of the site doesn't use cookies.