createPrimaryKeySql example


  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) . ')';
      }
    }

    
Home | Imprint | This part of the site doesn't use cookies.