lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
public function getCreateConstraintSQL(Constraint $constraint, $table)
    {
        if ($table instanceof Table) {
            $table = $table->getQuotedName($this);
        }

        $query = 'ALTER TABLE ' . $table . ' ADD CONSTRAINT ' . $constraint->getQuotedName($this);

        $columnList = '(' . implode(', ', $constraint->getQuotedColumns($this)) . ')';

        $referencesClause = '';
        if ($constraint instanceof Index) {
            if ($constraint->isPrimary()) {
                $query .= ' PRIMARY KEY';
            } elseif ($constraint->isUnique()) {
                $query .= ' UNIQUE';
            } else {
                throw new InvalidArgumentException(
                    'Can only create primary or unique constraints, no common indexes with getCreateConstraintSQL().'
                );
            }
        } elseif ($constraint instanceof ForeignKeyConstraint) {
            $query .= ' FOREIGN KEY';

            $referencesClause = ' REFERENCES ' . $constraint->getQuotedForeignTableName($this) .
                ' (' . implode(', ', $constraint->getQuotedForeignColumns($this)) . ')';
        }
        $query .= ' ' . $columnList . $referencesClause;

        return $query;
    }
public function getCreateConstraintSQL(Constraint $constraint, $table)
    {
        if ($table instanceof Table) {
            $table = $table->getQuotedName($this);
        }

        $query = 'ALTER TABLE ' . $table . ' ADD CONSTRAINT ' . $constraint->getQuotedName($this);

        $columnList = '(' . implode(', ', $constraint->getQuotedColumns($this)) . ')';

        $referencesClause = '';
        if ($constraint instanceof Index) {
            if ($constraint->isPrimary()) {
                $query .= ' PRIMARY KEY';
            } elseif ($constraint->isUnique()) {
                $query .= ' UNIQUE';
            } else {
                throw new InvalidArgumentException(
                    'Can only create primary or unique constraints, no common indexes with getCreateConstraintSQL().'
                );
            }
        } elseif ($constraint instanceof ForeignKeyConstraint) {
            $query .= ' FOREIGN KEY';

            $referencesClause = ' REFERENCES ' . $constraint->getQuotedForeignTableName($this) .
                ' (' . implode(', ', $constraint->getQuotedForeignColumns($this)) . ')';
        }
        $query .= ' ' . $columnList . $referencesClause;

        return $query;
    }
public function getCreateConstraintSQL ( Constraint $ constraint , $ table ) { if ( $ table instanceof Table ) { $ table = $ table -> getQuotedName ( $ this ) ; } $ query = 'ALTER TABLE ' . $ table . ' ADD CONSTRAINT ' . $ constraint -> getQuotedName ( $ this ) ; $ columnList = '(' . implode ( ', ' , $ constraint -> getQuotedColumns ( $ this ) ) . ')' ; $ referencesClause = '' ; if ( $ constraint instanceof Index ) { if ( $ constraint -> isPrimary ( ) ) { $ query .= ' PRIMARY KEY' ; } elseif ( $ constraint -> isUnique ( ) ) { $ query .= ' UNIQUE' ; } else { throw new InvalidArgumentException ( 'Can only create primary or unique constraints, no common indexes with getCreateConstraintSQL().' ) ; } } elseif ( $ constraint instanceof ForeignKeyConstraint ) { $ query .= ' FOREIGN KEY' ; $ referencesClause = ' REFERENCES ' . $ constraint -> getQuotedForeignTableName ( $ this ) . ' (' . implode ( ', ' , $ constraint -> getQuotedForeignColumns ( $ this ) ) . ')' ; } $ query .= ' ' . $ columnList . $ referencesClause ; return $ query ; }
Returns the SQL to create a constraint on a table on this platform.

@param Table|string $table

@return string

@throws InvalidArgumentException
Returns the SQL to create a constraint on a table on this platform .