/**
  * @group DBAL-585
  */
 public function testAlterTableChangeQuotedColumn()
 {
     $tableDiff = new \Doctrine\DBAL\Schema\TableDiff('mytable');
     $tableDiff->fromTable = new \Doctrine\DBAL\Schema\Table('mytable');
     $tableDiff->changedColumns['foo'] = new \Doctrine\DBAL\Schema\ColumnDiff('select', new \Doctrine\DBAL\Schema\Column('select', \Doctrine\DBAL\Types\Type::getType('string')), array('type'));
     $this->assertContains($this->_platform->quoteIdentifier('select'), implode(';', $this->_platform->getAlterTableSQL($tableDiff)));
 }
 private function getDiscriminatorColumn(ClassMetadata $meta)
 {
     if (!$meta->isInheritanceTypeSingleTable()) {
         return [];
     }
     $column = $meta->discriminatorColumn;
     return [$column['fieldName'] => ['value' => $meta->discriminatorValue, 'quotedColumn' => $this->platform->quoteIdentifier($column['name']), 'type' => Type::getType($column['type'])]];
 }
Beispiel #3
0
 /**
  * @param \Doctrine\DBAL\Schema\Table $table
  * @param \SimpleXMLElement $xml
  * @throws \DomainException
  */
 private function loadIndex($table, $xml)
 {
     $name = null;
     $fields = array();
     foreach ($xml->children() as $child) {
         /**
          * @var \SimpleXMLElement $child
          */
         switch ($child->getName()) {
             case 'name':
                 $name = (string) $child;
                 break;
             case 'primary':
                 $primary = $this->asBool($child);
                 break;
             case 'unique':
                 $unique = $this->asBool($child);
                 break;
             case 'field':
                 foreach ($child->children() as $field) {
                     /**
                      * @var \SimpleXMLElement $field
                      */
                     switch ($field->getName()) {
                         case 'name':
                             $field_name = (string) $field;
                             $field_name = $this->platform->quoteIdentifier($field_name);
                             $fields[] = $field_name;
                             break;
                         case 'sorting':
                             break;
                         default:
                             throw new \DomainException('Unknown element: ' . $field->getName());
                     }
                 }
                 break;
             default:
                 throw new \DomainException('Unknown element: ' . $child->getName());
         }
     }
     if (!empty($fields)) {
         if (isset($primary) && $primary) {
             if ($table->hasPrimaryKey()) {
                 return;
             }
             $table->setPrimaryKey($fields, $name);
         } else {
             if (isset($unique) && $unique) {
                 $table->addUniqueIndex($fields, $name);
             } else {
                 $table->addIndex($fields, $name);
             }
         }
     } else {
         throw new \DomainException('Empty index definition: ' . $name . ' options:' . print_r($fields, true));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function getJoinTableName(array $association, ClassMetadata $class, AbstractPlatform $platform)
 {
     $schema = '';
     if (isset($association['joinTable']['schema'])) {
         $schema = $association['joinTable']['schema'] . '.';
     }
     $tableName = $association['joinTable']['name'];
     if (isset($association['joinTable']['quoted'])) {
         $tableName = $platform->quoteIdentifier($tableName);
     }
     return $schema . $tableName;
 }
 /**
  * Quotes a string so it can be safely used as a table or column name, even if
  * it is a reserved name.
  *
  * Delimiting style depends on the underlying database platform that is being used.
  *
  * NOTE: Just because you CAN use quoted identifiers does not mean
  * you SHOULD use them. In general, they end up causing way more
  * problems than they solve.
  *
  * @param string $str The name to be quoted.
  *
  * @return string The quoted name.
  */
 public function quoteIdentifier($str)
 {
     return $this->_platform->quoteIdentifier($str);
 }
 /**
  * {@inheritdoc}
  */
 public function getJoinTableName(array $association, ClassMetadata $class, AbstractPlatform $platform)
 {
     return isset($association['joinTable']['quoted']) ? $platform->quoteIdentifier($association['joinTable']['name']) : $association['joinTable']['name'];
 }
 /**
  * Gets the (possibly quoted) name of the join table.
  *
  * @deprecated Deprecated since version 2.3 in favor of \Doctrine\ORM\Mapping\QuoteStrategy
  *
  * @param array $assoc
  * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
  * @return string
  */
 public function getQuotedJoinTableName(array $assoc, $platform)
 {
     return isset($assoc['joinTable']['quoted']) ? $platform->quoteIdentifier($assoc['joinTable']['name']) : $assoc['joinTable']['name'];
 }
Beispiel #8
0
 /**
  * Get the quoted representation of this asset but only if it was defined with one. Otherwise
  * return the plain unquoted value as inserted.
  *
  * @param AbstractPlatform $platform
  * @return string
  */
 public function getQuotedName(AbstractPlatform $platform)
 {
     $keywords = $platform->getReservedKeywordsList();
     $parts = explode(".", $this->getName());
     foreach ($parts as $k => $v) {
         $parts[$k] = $this->_quoted || $keywords->isKeyword($v) ? $platform->quoteIdentifier($v) : $v;
     }
     return implode(".", $parts);
 }
Beispiel #9
0
 /**
  * Get the quoted representation of this asset but only if it was defined with one. Otherwise
  * return the plain unquoted value as inserted.
  *
  * @param AbstractPlatform $platform
  * @return string
  */
 public function getQuotedName(AbstractPlatform $platform)
 {
     return $this->_quoted ? $platform->quoteIdentifier($this->_name) : $this->_name;
 }
 /**
  * Creates a foreign index replacement, which has quoted column names.
  *
  * @param ForeignKeyConstraint $fk
  *
  * @return ForeignKeyConstraint
  */
 private function createForeignKeyReplacement(ForeignKeyConstraint $fk)
 {
     return new ForeignKeyConstraint($this->quoteIdentifiers($fk->getLocalColumns()), $this->platform->quoteIdentifier($fk->getForeignTableName()), $this->quoteIdentifiers($fk->getForeignColumns()), $this->platform->quoteIdentifier($fk->getName()), $fk->getOptions());
 }