public function getSql(Index $index, $table)
 {
     if ($table instanceof Table) {
         $table = $table->getQuotedName($this->platform);
     }
     $name = $index->getQuotedName($this->platform);
     $columns = $index->getQuotedColumns($this->platform);
     if (count($columns) == 0) {
         throw new \InvalidArgumentException("Incomplete definition. 'columns' required.");
     }
     if ($index->isPrimary()) {
         return $this->platform->getCreatePrimaryKeySQL($index, $table);
     }
     $query = 'CREATE INDEX ' . $name . ' ON ' . $table;
     $query .= ' USING gist(' . $this->platform->getIndexFieldDeclarationListSQL($columns) . ')';
     return $query;
 }
Example #2
0
 /**
  * Extend unique key constraint with required filters
  *
  * @param string                      $sql
  * @param \Doctrine\DBAL\Schema\Index $index
  *
  * @return string
  */
 private function _appendUniqueConstraintDefinition($sql, Index $index)
 {
     $fields = array();
     foreach ($index->getQuotedColumns($this) as $field) {
         $fields[] = $field . ' IS NOT NULL';
     }
     return $sql . ' WHERE ' . implode(' AND ', $fields);
 }
Example #3
0
 /**
  * Obtains DBMS specific SQL code portion needed to set an index
  * declaration to be used in statements like CREATE TABLE.
  *
  * @param string                       $name  The name of the index.
  * @param \Doctrine\DBAL\Schema\Index  $index The index definition.
  *
  * @return string DBMS specific SQL code portion needed to set an index.
  *
  * @throws \InvalidArgumentException
  */
 public function getIndexDeclarationSQL($name, Index $index)
 {
     $columns = $index->getQuotedColumns($this);
     if (count($columns) === 0) {
         throw new \InvalidArgumentException("Incomplete definition. 'columns' required.");
     }
     return $this->getCreateIndexSQLFlags($index) . 'INDEX ' . $name . ' (' . $this->getIndexFieldDeclarationListSQL($columns) . ')' . $this->getPartialIndexSQL($index);
 }
Example #4
0
 public function getCreatePrimaryKeySQL(Index $index, $table)
 {
     if ($table instanceof Table) {
         $table = $table->getQuotedName($this);
     }
     return 'ALTER TABLE ' . $this->espoQuote($table) . ' ADD PRIMARY KEY (' . $this->getIndexFieldDeclarationListSQL($index->getQuotedColumns($this)) . ')';
 }
Example #5
0
 /**
  * Generate table index column declaration
  * @codeCoverageIgnore
  */
 public function getIndexDeclarationSQL($name, Index $index)
 {
     $columns = $index->getQuotedColumns($this);
     $name = new Identifier($name);
     if (count($columns) == 0) {
         throw new \InvalidArgumentException("Incomplete definition. 'columns' required.");
     }
     return 'INDEX ' . $name->getQuotedName($this) . ' USING FULLTEXT (' . $this->getIndexFieldDeclarationListSQL($columns) . ')';
 }
 /**
  * Returns the SQL to create an unnamed primary key constraint.
  *
  * @param \Doctrine\DBAL\Schema\Index        $index
  * @param \Doctrine\DBAL\Schema\Table|string $table
  *
  * @return string
  */
 public function getCreatePrimaryKeySQL(Index $index, $table)
 {
     return 'ALTER TABLE ' . $table . ' ADD PRIMARY KEY (' . $this->getIndexFieldDeclarationListSQL($index->getQuotedColumns($this)) . ')';
 }
Example #7
0
 /**
  * {@inheritDoc}
  */
 public function getCreatePrimaryKeySQL(Index $index, $table)
 {
     $sql = 'ALTER TABLE ' . $table . ' ADD CONSTRAINT PRIMARY KEY (' . $this->getIndexFieldDeclarationListSQL($index->getQuotedColumns($this)) . ')';
     if ($index->getName()) {
         $sql .= ' CONSTRAINT ' . $index->getQuotedName($this);
     }
     return $sql;
 }