/**
  * @param AbstractPlatform $platform
  *
  * @throws UnsupportedPlatformException
  */
 protected function validatePlatform(AbstractPlatform $platform)
 {
     $platformName = $platform->getName();
     if (isset($this->platforms) && !in_array($platformName, $this->platforms)) {
         throw UnsupportedPlatformException::unsupportedPlatform($platformName);
     }
 }
Ejemplo n.º 2
0
Archivo: IP.php Proyecto: foowie/ip
 public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
 {
     if (!isset($fieldDeclaration['length'])) {
         $fieldDeclaration['length'] = 32;
     }
     return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration);
 }
Ejemplo n.º 3
0
 /**
  * @param DateTimeOfDay $value
  * @param AbstractPlatform $platform
  *
  * @return string
  */
 public function convertToDatabaseValue($value, AbstractPlatform $platform)
 {
     if ($value instanceof DateTimeOfDay) {
         return $value->toDateTime()->format($platform->getDateTimeFormatString());
     }
     return parent::convertToDatabaseValue($value, $platform);
 }
Ejemplo n.º 4
0
 /**
  * ->processQueueCallback(function (\Dja\Db\Model\Metadata $metadata, \Doctrine\DBAL\Schema\Table $table, array $sql, \Doctrine\DBAL\Connection $db) {})
  * @param callable|\Closure $callBack
  */
 public function processQueueCallback(\Closure $callBack)
 {
     $callbackQueue = [];
     while (count($this->generateQueue)) {
         $modelName = array_shift($this->generateQueue);
         try {
             /** @var Metadata $metadata */
             $metadata = $modelName::metadata();
             $tblName = $metadata->getDbTableName();
             if ($this->db->getSchemaManager()->tablesExist($tblName)) {
                 continue;
             }
             if (isset($this->generated[$tblName])) {
                 continue;
             }
             $table = $this->metadataToTable($metadata);
             $this->generated[$tblName] = 1;
             $sql = $this->dp->getCreateTableSQL($table, AbstractPlatform::CREATE_INDEXES);
             array_unshift($callbackQueue, [$metadata, $table, $sql]);
             $fks = $table->getForeignKeys();
             if (count($fks)) {
                 $sql = [];
                 foreach ($fks as $fk) {
                     $sql[] = $this->dp->getCreateForeignKeySQL($fk, $table);
                 }
                 array_push($callbackQueue, [$metadata, $table, $sql]);
             }
         } catch (\Exception $e) {
             pr($e->__toString());
         }
     }
     foreach ($callbackQueue as $args) {
         $callBack($args[0], $args[1], $args[2], $this->db);
     }
 }
Ejemplo n.º 5
0
 public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
 {
     $values = array_map(function ($val) {
         return "'" . $val . "'";
     }, $this->values);
     return sprintf("ENUM(%s) COMMENT '%s'", implode(', ', $values), $platform->getDoctrineTypeComment($this));
 }
Ejemplo n.º 6
0
 /**
  * @param string $sqlExpr
  * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
  * @throws \Kdyby\Doctrine\NotImplementedException
  * @return string
  */
 public function convertToDatabaseValueSQL($sqlExpr, AbstractPlatform $platform)
 {
     if (!$platform instanceof Doctrine\DBAL\Platforms\MySqlPlatform) {
         throw new Kdyby\Doctrine\NotImplementedException("Unsupported platform " . $platform->getName());
     }
     return 'GeomFromText(' . $sqlExpr . ')';
 }
Ejemplo n.º 7
0
 public function testRequireQueryForServerVersion()
 {
     if ($this->platform->getName() != 'informix') {
         $this->markTestSkipped('This test only applies to PDO_INFORMIX');
     }
     $this->assertTrue($this->driverConnection->requiresQueryForServerVersion());
 }
 protected function setUp()
 {
     $this->platform = $this->getMockBuilder('Doctrine\\DBAL\\Platforms\\AbstractPlatform')->setMethods(array('getVarcharTypeDeclarationSQL'))->getMockForAbstractClass();
     $this->platform->expects($this->any())->method('getVarcharTypeDeclarationSQL')->will($this->returnValue('DUMMYVARCHAR()'));
     $this->type = Type::getType('phone_number');
     $this->phoneNumberUtil = PhoneNumberUtil::getInstance();
 }
Ejemplo n.º 9
0
 public function convertToDatabaseValue($timepoint, AbstractPlatform $platform)
 {
     if ($timepoint !== null) {
         $dtime = $timepoint->asPHPDateTime();
         return $dtime->format($platform->getDateTimeFormatString());
     }
 }
Ejemplo n.º 10
0
 public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
 {
     $fieldDeclaration['length'] = 255;
     $fieldDeclaration['notnull'] = false;
     $fieldDeclaration['default'] = null;
     return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration);
 }
Ejemplo n.º 11
0
 protected function setUp()
 {
     // class has private constructor
     $this->type = $this->getMockBuilder('Oro\\Bundle\\LocaleBundle\\DoctrineExtensions\\DBAL\\Types\\UTCTimeType')->setMethods(null)->disableOriginalConstructor()->getMock();
     $this->platform = $this->getMockBuilder('Doctrine\\DBAL\\Platforms\\AbstractPlatform')->disableOriginalConstructor()->setMethods(array('getTimeFormatString'))->getMockForAbstractClass();
     $this->platform->expects($this->any())->method('getTimeFormatString')->will($this->returnValue('H:i:s'));
 }
Ejemplo n.º 12
0
 /**
  * {@inheritdoc}
  */
 public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
 {
     if ($platform->getName() === 'postgresql') {
         return 'GEOMETRY';
     }
     return strtoupper($this->getName());
 }
Ejemplo n.º 13
0
 /**
  * @param Schema   $schema
  * @param QueryBag $queries
  * @param string   $tableName
  * @param string   $columnName
  * @param string   $type
  *
  * @throws \Exception
  */
 public function changePrimaryKeyType(Schema $schema, QueryBag $queries, $tableName, $columnName, $type)
 {
     $targetColumn = $schema->getTable($tableName)->getColumn($columnName);
     $type = Type::getType($type);
     if ($targetColumn->getType() === $type) {
         return;
     }
     /** @var ForeignKeyConstraint[] $foreignKeys */
     $foreignKeys = [];
     foreach ($schema->getTables() as $table) {
         /** @var ForeignKeyConstraint[] $tableForeignKeys */
         $tableForeignKeys = array_filter($table->getForeignKeys(), function (ForeignKeyConstraint $tableForeignKey) use($tableName, $columnName) {
             if ($tableForeignKey->getForeignTableName() !== $tableName) {
                 return false;
             }
             return $tableForeignKey->getForeignColumns() === [$columnName];
         });
         foreach ($tableForeignKeys as $tableForeignKey) {
             $foreignKeys[$tableForeignKey->getName()] = $tableForeignKey;
             $foreignKeyTableName = $tableForeignKey->getLocalTable()->getName();
             $foreignKeyColumnNames = $tableForeignKey->getLocalColumns();
             $queries->addPreQuery($this->platform->getDropForeignKeySQL($tableForeignKey, $foreignKeyTableName));
             $column = $schema->getTable($foreignKeyTableName)->getColumn(reset($foreignKeyColumnNames));
             if ($column instanceof ExtendColumn) {
                 $column->disableExtendOptions()->setType($type)->enableExtendOptions();
             } else {
                 $column->setType($type);
             }
         }
     }
     $targetColumn->setType($type);
     foreach ($foreignKeys as $foreignKey) {
         $queries->addPostQuery($this->platform->getCreateForeignKeySQL($foreignKey, $foreignKey->getLocalTable()));
     }
 }
Ejemplo n.º 14
0
 public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
 {
     $fieldDeclaration['length'] = 25;
     $fieldDeclaration['fixed'] = true;
     $fieldDeclaration['notnull'] = true;
     return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration);
 }
Ejemplo n.º 15
0
 /**
  * {@inheritdoc}
  * @param array $fieldDeclaration
  * @param AbstractPlatform $platform
  * @return 
  */
 public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
 {
     if (empty($fieldDeclaration['length'])) {
         $fieldDeclaration['length'] = Path::MAX_LENGTH;
     }
     $type = $platform->getVarcharTypeDeclarationSQL($fieldDeclaration);
     return $type;
 }
 /** @noinspection PhpMissingParentCallCommonInspection
  * @inheritdoc
  */
 public function convertToDatabaseValue($value, AbstractPlatform $platform)
 {
     /** @var DateTime|null $value */
     if ($value === null) {
         return null;
     }
     return $value->format($platform->getDateTimeFormatString());
 }
 /** @noinspection PhpMissingParentCallCommonInspection
  * @inheritdoc
  */
 public function convertToPHPValue($value, AbstractPlatform $platform)
 {
     /** @var string|null $value */
     if ($value === null) {
         return null;
     }
     return $this->convertDateTimeString($value, $platform->getDateTimeFormatString(), static::JSON_API_FORMAT);
 }
Ejemplo n.º 18
0
 /**
  * Build a Doctrine column object for TYPE/TYPE columns.
  *
  * @param array $tableColumn
  * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
  * @return \Doctrine\DBAL\Schema\Column
  * @throws \Doctrine\DBAL\DBALException
  * @todo: The $tableColumn source currently only support MySQL definition style.
  */
 protected function getEnumerationTableColumnDefinition(array $tableColumn, AbstractPlatform $platform) : Column
 {
     $options = ['length' => $tableColumn['length'] ?: null, 'unsigned' => false, 'fixed' => false, 'default' => $tableColumn['default'] ?: null, 'notnull' => (bool) ($tableColumn['null'] !== 'YES'), 'scale' => null, 'precision' => null, 'autoincrement' => false, 'comment' => $tableColumn['comment'] ?: null];
     $dbType = $this->getDatabaseType($tableColumn['type']);
     $doctrineType = $platform->getDoctrineTypeMapping($dbType);
     $column = new Column($tableColumn['field'], Type::getType($doctrineType), $options);
     $column->setPlatformOption('unquotedValues', $this->getUnquotedEnumerationValues($tableColumn['type']));
     return $column;
 }
Ejemplo n.º 19
0
 /**
  * Dump the constraints / foreign keys of all tables.
  *
  * The constraints should be created at the end to speed up the import of the dump.
  *
  * @param Table[]            $tables
  */
 public function dumpConstraints(array $tables)
 {
     foreach ($tables as $table) {
         foreach ($table->getForeignKeys() as $constraint) {
             $constraint = $this->platform->getCreateConstraintSQL($constraint, $table);
             $this->dumpOutput->writeln($constraint . ';');
         }
     }
 }
Ejemplo n.º 20
0
 /** {@inheritdoc} */
 public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
 {
     switch ($platform->getName()) {
         case 'mysql':
             return 'TINYINT' . (isset($fieldDeclaration['unsigned']) && $fieldDeclaration['unsigned'] ? ' UNSIGNED' : '');
         default:
             return $platform->getSmallIntTypeDeclarationSQL($fieldDeclaration);
     }
 }
Ejemplo n.º 21
0
 /**
  * {@inheritdoc}
  * @param array $fieldDeclaration
  * @param AbstractPlatform $platform
  * @return string
  */
 public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
 {
     $fieldDeclaration['length'] = 20;
     $fieldDeclaration['fixed'] = true;
     $sql = $platform->getVarcharTypeDeclarationSQL($fieldDeclaration);
     //todo: check if this is sane, at least
     $sql .= ' COLLATE ascii_general_ci';
     return $sql;
 }
Ejemplo n.º 22
0
 /**
  * {@inheritdoc}
  */
 public function convertToDatabaseValue($value, AbstractPlatform $platform)
 {
     if ($value === null) {
         return null;
     }
     if ($value instanceof Carbon) {
         return $value->copy()->setTimezone('UTC')->format($platform->getDateTimeFormatString());
     }
     throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getDateTimeFormatString());
 }
 /**
  * @param array $fieldDeclaration
  * @param AbstractPlatform $platform
  * @return string
  */
 public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
 {
     $values = implode(', ', array_map(function ($value) {
         return "'{$value}'";
     }, $this->getValues()));
     if (!$platform instanceof MySqlPlatform) {
         return $platform->getClobTypeDeclarationSQL($fieldDeclaration);
     }
     return sprintf('SET(%s)', $values);
 }
 /**
  * @param mixed            $value
  * @param AbstractPlatform $platform
  *
  * @return null|FamilyInterface
  * @throws MissingFamilyException
  */
 public function convertToPHPValue($value, AbstractPlatform $platform)
 {
     if (null === $value) {
         return null;
     }
     $listeners = $platform->getEventManager()->getListeners('sidus_family_configuration');
     /** @var FamilyConfigurationHandler $familyConfigurationHandler */
     $familyConfigurationHandler = array_shift($listeners);
     return $familyConfigurationHandler->getFamily($value);
 }
Ejemplo n.º 25
0
 /**
  * {@inheritdoc}
  */
 public function up(Schema $schema, QueryBag $queries)
 {
     /**
      * After v1_3 migration
      * Undefined table: 7 ERROR:  relation "oro_dashboard_active_id_seq" does not exist
      */
     if ($this->platform->supportsSequences()) {
         $queries->addPostQuery('ALTER SEQUENCE IF EXISTS oro_dashboard_active_copy_id_seq RENAME TO oro_dashboard_active_id_seq;');
     }
 }
Ejemplo n.º 26
0
 /**
  * {@inheritdoc}
  */
 public function convertToPHPValue($value, AbstractPlatform $platform)
 {
     if ($value === null || $value instanceof \DateTime) {
         return $value;
     }
     $val = \DateTime::createFromFormat('!' . $platform->getTimeFormatString(), $value);
     if (!$val) {
         throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getTimeFormatString());
     }
     return $val;
 }
 /**
  * {@inheritdoc}
  *
  * @throws \RuntimeException If the data decode fails.
  */
 public function convertToPHPValue($value, AbstractPlatform $platform) : array
 {
     $raw = json_decode($value, true);
     if (JSON_ERROR_NONE !== json_last_error()) {
         throw new \RuntimeException(sprintf('The decode of the JSON string from the database ("%s") failed due to the following error: "%s"!', $value, json_last_error_msg()));
     }
     $dbFormat = $platform->getDateTimeFormatString();
     return array_map(function ($format) use($dbFormat) {
         return \DateTime::createFromFormat($dbFormat, $format);
     }, $raw);
 }
 /**
  * @param \DateTimeImmutable|string|null $value
  * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
  * @return \DateTimeImmutable|null
  */
 public function convertToPHPValue($value, AbstractPlatform $platform)
 {
     if ($value === null || $value instanceof DateTimeImmutable) {
         return $value;
     }
     $dateTime = DateTimeImmutable::createFromFormat('!' . $platform->getTimeFormatString(), $value);
     if ($dateTime === false) {
         throw \Doctrine\DBAL\Types\ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getTimeFormatString());
     }
     return $dateTime;
 }
Ejemplo n.º 29
0
 public function convertToPHPValue($value, AbstractPlatform $platform)
 {
     if ($value === null) {
         return null;
     }
     $val = \Psc\DateTime\Date::parse($platform->getDateFormatString(), $value);
     if (!$val) {
         throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getDateFormatString());
     }
     return $val;
 }
Ejemplo n.º 30
0
 /**
  * @group DDC-1737
  */
 public function testClobNoAlterTable()
 {
     $tableOld = new Table("test");
     $tableOld->addColumn('id', 'integer');
     $tableOld->addColumn('description', 'string', array('length' => 65536));
     $tableNew = clone $tableOld;
     $tableNew->setPrimaryKey(array('id'));
     $diff = $this->comparator->diffTable($tableOld, $tableNew);
     $sql = $this->platform->getAlterTableSQL($diff);
     $this->assertEquals(array('ALTER TABLE test ADD PRIMARY KEY (id)'), $sql);
 }