public function testRequireQueryForServerVersion() { if ($this->platform->getName() != 'informix') { $this->markTestSkipped('This test only applies to PDO_INFORMIX'); } $this->assertTrue($this->driverConnection->requiresQueryForServerVersion()); }
/** * @group DDC-1360 */ public function testQuoteSingleIdentifier() { if ($this->_platform->getName() == "mssql") { $this->markTestSkipped('Not working this way on mssql.'); } $c = $this->_platform->getIdentifierQuoteCharacter(); $this->assertEquals($c . "test" . $c, $this->_platform->quoteSingleIdentifier("test")); $this->assertEquals($c . "test.test" . $c, $this->_platform->quoteSingleIdentifier("test.test")); $this->assertEquals(str_repeat($c, 4), $this->_platform->quoteSingleIdentifier($c)); }
/** * @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); } }
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) { if ($platform->getName() === 'mysql') { return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration) . " " . $platform->getCollationFieldDeclaration('utf8_bin'); } return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration); }
/** * @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 . ')'; }
/** * {@inheritdoc} */ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) { if ($platform->getName() === 'postgresql') { return 'GEOMETRY'; } return strtoupper($this->getName()); }
/** {@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); } }
/** * Walks down a SelectStatement AST node, wrapping it in a COUNT (SELECT DISTINCT). * * Note that the ORDER BY clause is not removed. Many SQL implementations (e.g. MySQL) * are able to cache subqueries. By keeping the ORDER BY clause intact, the limitSubQuery * that will most likely be executed next can be read from the native SQL cache. * * @param SelectStatement $AST * * @return string * * @throws \RuntimeException */ public function walkSelectStatement(SelectStatement $AST) { if ($this->platform->getName() === "mssql") { $AST->orderByClause = null; } $sql = parent::walkSelectStatement($AST); // Find out the SQL alias of the identifier column of the root entity // It may be possible to make this work with multiple root entities but that // would probably require issuing multiple queries or doing a UNION SELECT // so for now, It's not supported. // Get the root entity and alias from the AST fromClause $from = $AST->fromClause->identificationVariableDeclarations; if (count($from) > 1) { throw new \RuntimeException("Cannot count query which selects two FROM components, cannot make distinction"); } $fromRoot = reset($from); $rootAlias = $fromRoot->rangeVariableDeclaration->aliasIdentificationVariable; $rootClass = $this->queryComponents[$rootAlias]['metadata']; $rootIdentifier = $rootClass->identifier; // For every identifier, find out the SQL alias by combing through the ResultSetMapping $sqlIdentifier = []; foreach ($rootIdentifier as $property) { if (isset($rootClass->fieldMappings[$property])) { foreach (array_keys($this->rsm->fieldMappings, $property) as $alias) { if ($this->rsm->columnOwnerMap[$alias] == $rootAlias) { $sqlIdentifier[$property] = $alias; } } } if (isset($rootClass->associationMappings[$property])) { $joinColumn = $rootClass->associationMappings[$property]['joinColumns'][0]['name']; foreach (array_keys($this->rsm->metaMappings, $joinColumn) as $alias) { if ($this->rsm->columnOwnerMap[$alias] == $rootAlias) { $sqlIdentifier[$property] = $alias; } } } } if (count($rootIdentifier) != count($sqlIdentifier)) { throw new \RuntimeException(sprintf('Not all identifier properties can be found in the ResultSetMapping: %s', implode(', ', array_diff($rootIdentifier, array_keys($sqlIdentifier))))); } // Build the counter query return sprintf('SELECT %s AS dctrn_count FROM (SELECT DISTINCT %s FROM (%s) dctrn_result) dctrn_table', $this->platform->getCountExpression('*'), implode(', ', $sqlIdentifier), $sql); }
public function create($formatter, Platform $platform, $options = array()) { $formatter = strtolower($formatter); if (isset(self::$formatters[$formatter]) === false) { throw new EngineException('Formatter does not exist at::' . $formatter); } $class = new self::$formatters[$formatter]($this->event, $this->writer->getWriter($platform->getName(), $formatter), $platform, $this->visitor, $options); # register this formatter as a subscriber $this->event->addSubscriber($class); return $class; }
/** * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform * @return \Doctrine\Spatial\DBAL\HandlerInterface */ public function getHandler(AbstractPlatform $platform) { $name = $platform->getName(); if (isset($this->handlerMap[$name])) { return $this->handlerMap[$name]; } if (!isset($this->handlerClasses[$name])) { throw new \RuntimeException('The database platform ' . $name . ' is not supported'); } return $this->handlerMap[$name] = new $this->handlerClasses[$name](); }
/** * Create oro_search_index_text table * * @param Schema $schema */ protected function createOroSearchIndexTextTable(Schema $schema) { $table = $schema->createTable('oro_search_index_text'); $table->addColumn('id', 'integer', ['autoincrement' => true]); $table->addColumn('item_id', 'integer', []); $table->addColumn('field', 'string', ['length' => 250]); $table->addColumn('value', 'text', []); $table->addIndex(['item_id'], 'idx_a0243539126f525e', []); $table->setPrimaryKey(['id']); if ($this->platform->getName() === DatabasePlatformInterface::DATABASE_MYSQL) { $table->addOption('engine', PdoMysql::ENGINE_MYISAM); } }
/** * @param array $fieldDeclaration * @param AbstractPlatform $platform * * @throws DBALException * * @return string */ public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform) { if ($platform instanceof DB2Platform or $platform instanceof OraclePlatform or $platform instanceof SqlitePlatform or $platform instanceof SQLServerPlatform) { throw new DBALException('ENUMs are not supported by ' . $platform->getName() . '.'); } if (!empty($fieldDeclaration['values']) && is_array($fieldDeclaration['values'])) { $values = array(); foreach ($fieldDeclaration['values'] as $value) { $values[] = $platform->quoteStringLiteral($value); } return 'ENUM (' . implode(',', $values) . ')'; } }
public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform) { $values = implode(", ", array_map(function ($val) { return "'" . $val . "'"; }, static::getValues())); if ($platform instanceof MysqlPlatform) { return sprintf('ENUM(%s)', $values); } elseif ($platform instanceof SqlitePlatform) { return sprintf('TEXT CHECK(%s IN (%s))', $fieldDeclaration['name'], $values); } elseif ($platform instanceof PostgreSqlPlatform) { return sprintf('VARCHAR(255) CHECK(%s IN (%s))', $fieldDeclaration['name'], $values); } else { throw new \Exception(sprintf("Sorry, platform %s currently not supported enums", $platform->getName())); } }
/** * Dump the statistics of executed queries * * @param boolean $dumpOnlySql * @return void */ public function getOutput($dumpOnlySql = false) { $output = ''; if (!$dumpOnlySql) { $output .= 'Platform: ' . $this->platform->getName() . PHP_EOL; $output .= 'Executed queries: ' . count($this->queries) . ', total time: ' . $this->totalExecutionTime . ' ms' . PHP_EOL; } foreach ($this->queries as $index => $sql) { if (!$dumpOnlySql) { $output .= 'Query(' . ($index + 1) . ') - ' . $this->queryExecutionTimes[$index] . ' ms' . PHP_EOL; } $output .= $sql . ';' . PHP_EOL; } $output .= PHP_EOL; return $output; }
/** * @param $alias * @param $property * @param $value * @param string $operator * * @return string * * @throws NotImplementedException if the storage backend is neither mysql * nor postgres nor sqlite */ private function sqlXpathComparePropertyValue($alias, $property, $value, $operator) { $expression = null; if ($this->platform instanceof MySqlPlatform) { $expression = "EXTRACTVALUE({$alias}.props, 'count(//sv:property[@sv:name=\"" . $property . "\"]/sv:value[text()%s%s]) > 0')"; // mysql does not escape the backslashes for us, while postgres and sqlite do $value = Xpath::escapeBackslashes($value); } elseif ($this->platform instanceof PostgreSqlPlatform) { $expression = "xpath_exists('//sv:property[@sv:name=\"" . $property . "\"]/sv:value[text()%s%s]', CAST({$alias}.props AS xml), " . $this->sqlXpathPostgreSQLNamespaces() . ") = 't'"; } elseif ($this->platform instanceof SqlitePlatform) { $expression = "EXTRACTVALUE({$alias}.props, 'count(//sv:property[@sv:name=\"" . $property . "\"]/sv:value[text()%s%s]) > 0')"; } else { throw new NotImplementedException("Xpath evaluations cannot be executed with '" . $this->platform->getName() . "' yet."); } return sprintf($expression, $this->walkOperator($operator), Xpath::escape($value)); }
/** * Converts a value from its database representation to its PHP representation * of this type. * * @param mixed $value The value to convert. * @param AbstractPlatform $platform The currently used database platform. * @return array The PHP representation of the value. */ public function convertToPHPValue($value, AbstractPlatform $platform) { $this->initializeDependencies(); switch ($platform->getName()) { case 'postgresql': $value = is_resource($value) ? stream_get_contents($value) : $value; $array = parent::convertToPHPValue($value, $platform); break; default: $array = parent::convertToPHPValue($value, $platform); } if (is_array($array)) { $this->decodeObjectReferences($array); } return $array; }
/** * Converts a value from its PHP representation to its database representation * of this type. * * @param array $array The value to convert. * @param AbstractPlatform $platform The currently used database platform. * @return mixed The database representation of the value. */ public function convertToDatabaseValue($array, AbstractPlatform $platform) { $this->initializeDependencies(); $this->encodeObjectReferences($array); switch ($platform->getName()) { case 'postgresql': return bin2hex(parent::convertToDatabaseValue($array, $platform)); default: return parent::convertToDatabaseValue($array, $platform); } }
/** * @param AbstractPlatform $platform * @return bool */ private function isPlatformSupported(AbstractPlatform $platform) { return in_array($platform->getName(), $this->supportedPlatforms); }
protected static function getOptArray(SimpleXMLElement $xOptParent, AbstractPlatform $platform) { $result = array(); foreach ($xOptParent->opt as $xOpt) { $forThisPlatform = false; foreach (explode(',', (string) $xOpt['for']) as $for) { $for = trim($for); if ($for === '*' || strcasecmp($for, $platform->getName()) === 0) { $forThisPlatform = true; break; } } if ($forThisPlatform) { foreach ($xOpt->attributes() as $name => $value) { if ($name !== 'for') { $value = trim((string) $value); if ($value !== '') { $result[$name] = $value; } } } } } return $result; }
/** * @param AbstractPlatform $platform * * @return PlatformInterface * @throws UnsupportedPlatformException */ private function getSpatialPlatform(AbstractPlatform $platform) { $const = sprintf('self::PLATFORM_%s', strtoupper($platform->getName())); if (!defined($const)) { throw new UnsupportedPlatformException(sprintf('DBAL platform "%s" is not currently supported.', $platform->getName())); } $class = sprintf('CrEOF\\Spatial\\DBAL\\Platform\\%s', constant($const)); return new $class(); }
/** * @param AbstractPlatform $platform * * @throws UnsupportedPlatformException */ protected function validatePlatform(AbstractPlatform $platform) { $platformName = $platform->getName(); if (isset($this->platforms) && !in_array($platformName, $this->platforms)) { throw new UnsupportedPlatformException(sprintf('DBAL platform "%s" is not currently supported.', $platformName)); } }
/** * @param AbstractPlatform $platform * * @return string * @throws UnsupportedPlatformException */ private function getPlatformName(AbstractPlatform $platform) { $name = __CLASS__ . '::PLATFORM_' . strtoupper($platform->getName()); if (!defined($name)) { throw UnsupportedPlatformException::unsupportedPlatform($name); } return constant($name); }