Commit 87049d69 authored by Steve Müller's avatar Steve Müller

fix CS

parent 0083774f
...@@ -131,4 +131,4 @@ class Driver implements \Doctrine\DBAL\Driver ...@@ -131,4 +131,4 @@ class Driver implements \Doctrine\DBAL\Driver
{ {
return new SQLAnywhereSchemaManager($conn); return new SQLAnywhereSchemaManager($conn);
} }
} }
\ No newline at end of file
...@@ -33,7 +33,7 @@ class SQLAnywhereConnection implements Connection ...@@ -33,7 +33,7 @@ class SQLAnywhereConnection implements Connection
/** /**
* @var resource The SQL Anywhere connection resource. * @var resource The SQL Anywhere connection resource.
*/ */
private $conn; private $connection;
/** /**
* Constructor. * Constructor.
...@@ -47,31 +47,25 @@ class SQLAnywhereConnection implements Connection ...@@ -47,31 +47,25 @@ class SQLAnywhereConnection implements Connection
*/ */
public function __construct($dsn, $persistent = false) public function __construct($dsn, $persistent = false)
{ {
$this->conn = $persistent ? @sasql_pconnect($dsn) : @sasql_connect($dsn); $this->connection = $persistent ? @sasql_pconnect($dsn) : @sasql_connect($dsn);
if ( ! is_resource($this->conn) || get_resource_type($this->conn) != 'SQLAnywhere connection') { if ( ! is_resource($this->connection) || get_resource_type($this->connection) !== 'SQLAnywhere connection') {
throw SQLAnywhereException::fromSQLAnywhereError(); throw SQLAnywhereException::fromSQLAnywhereError();
} }
/** // Disable PHP warnings on error.
* Disable PHP warnings on error if ( ! sasql_set_option($this->connection, 'verbose_errors', false)) {
*/ throw SQLAnywhereException::fromSQLAnywhereError($this->connection);
if ( ! sasql_set_option($this->conn, 'verbose_errors', false)) {
throw SQLAnywhereException::fromSQLAnywhereError($this->conn);
} }
/** // Enable auto committing by default.
* Enable auto committing by default if ( ! sasql_set_option($this->connection, 'auto_commit', 'on')) {
*/ throw SQLAnywhereException::fromSQLAnywhereError($this->connection);
if ( ! sasql_set_option($this->conn, 'auto_commit', 'on')) {
throw SQLAnywhereException::fromSQLAnywhereError($this->conn);
} }
/** // Enable exact, non-approximated row count retrieval.
* Enable exact, non-approximated row count retrieval if ( ! sasql_set_option($this->connection, 'row_counts', true)) {
*/ throw SQLAnywhereException::fromSQLAnywhereError($this->connection);
if ( ! sasql_set_option($this->conn, 'row_counts', true)) {
throw SQLAnywhereException::fromSQLAnywhereError($this->conn);
} }
} }
...@@ -82,8 +76,8 @@ class SQLAnywhereConnection implements Connection ...@@ -82,8 +76,8 @@ class SQLAnywhereConnection implements Connection
*/ */
public function beginTransaction() public function beginTransaction()
{ {
if ( ! sasql_set_option($this->conn, 'auto_commit', 'off')) { if ( ! sasql_set_option($this->connection, 'auto_commit', 'off')) {
throw SQLAnywhereException::fromSQLAnywhereError($this->conn); throw SQLAnywhereException::fromSQLAnywhereError($this->connection);
} }
return true; return true;
...@@ -96,8 +90,8 @@ class SQLAnywhereConnection implements Connection ...@@ -96,8 +90,8 @@ class SQLAnywhereConnection implements Connection
*/ */
public function commit() public function commit()
{ {
if ( ! sasql_commit($this->conn)) { if ( ! sasql_commit($this->connection)) {
throw SQLAnywhereException::fromSQLAnywhereError($this->conn); throw SQLAnywhereException::fromSQLAnywhereError($this->connection);
} }
$this->endTransaction(); $this->endTransaction();
...@@ -110,7 +104,7 @@ class SQLAnywhereConnection implements Connection ...@@ -110,7 +104,7 @@ class SQLAnywhereConnection implements Connection
*/ */
public function errorCode() public function errorCode()
{ {
return sasql_errorcode($this->conn); return sasql_errorcode($this->connection);
} }
/** /**
...@@ -118,7 +112,7 @@ class SQLAnywhereConnection implements Connection ...@@ -118,7 +112,7 @@ class SQLAnywhereConnection implements Connection
*/ */
public function errorInfo() public function errorInfo()
{ {
return sasql_error($this->conn); return sasql_error($this->connection);
} }
/** /**
...@@ -127,6 +121,7 @@ class SQLAnywhereConnection implements Connection ...@@ -127,6 +121,7 @@ class SQLAnywhereConnection implements Connection
public function exec($statement) public function exec($statement)
{ {
$stmt = $this->prepare($statement); $stmt = $this->prepare($statement);
$stmt->execute(); $stmt->execute();
return $stmt->rowCount(); return $stmt->rowCount();
...@@ -137,8 +132,8 @@ class SQLAnywhereConnection implements Connection ...@@ -137,8 +132,8 @@ class SQLAnywhereConnection implements Connection
*/ */
public function lastInsertId($name = null) public function lastInsertId($name = null)
{ {
if ($name === null) { if (null === $name) {
return sasql_insert_id($this->conn); return sasql_insert_id($this->connection);
} }
return $this->query('SELECT ' . $name . '.CURRVAL')->fetchColumn(); return $this->query('SELECT ' . $name . '.CURRVAL')->fetchColumn();
...@@ -149,7 +144,7 @@ class SQLAnywhereConnection implements Connection ...@@ -149,7 +144,7 @@ class SQLAnywhereConnection implements Connection
*/ */
public function prepare($prepareString) public function prepare($prepareString)
{ {
return new SQLAnywhereStatement($this->conn, $prepareString); return new SQLAnywhereStatement($this->connection, $prepareString);
} }
/** /**
...@@ -159,6 +154,7 @@ class SQLAnywhereConnection implements Connection ...@@ -159,6 +154,7 @@ class SQLAnywhereConnection implements Connection
{ {
$args = func_get_args(); $args = func_get_args();
$stmt = $this->prepare($args[0]); $stmt = $this->prepare($args[0]);
$stmt->execute(); $stmt->execute();
return $stmt; return $stmt;
...@@ -173,7 +169,7 @@ class SQLAnywhereConnection implements Connection ...@@ -173,7 +169,7 @@ class SQLAnywhereConnection implements Connection
return $input; return $input;
} }
return "'" . sasql_escape_string($this->conn, $input) . "'"; return "'" . sasql_escape_string($this->connection, $input) . "'";
} }
/** /**
...@@ -183,8 +179,8 @@ class SQLAnywhereConnection implements Connection ...@@ -183,8 +179,8 @@ class SQLAnywhereConnection implements Connection
*/ */
public function rollBack() public function rollBack()
{ {
if ( ! sasql_rollback($this->conn)) { if ( ! sasql_rollback($this->connection)) {
throw SQLAnywhereException::fromSQLAnywhereError($this->conn); throw SQLAnywhereException::fromSQLAnywhereError($this->connection);
} }
$this->endTransaction(); $this->endTransaction();
...@@ -201,10 +197,10 @@ class SQLAnywhereConnection implements Connection ...@@ -201,10 +197,10 @@ class SQLAnywhereConnection implements Connection
*/ */
private function endTransaction() private function endTransaction()
{ {
if ( ! sasql_set_option($this->conn, 'auto_commit', 'on')) { if ( ! sasql_set_option($this->connection, 'auto_commit', 'on')) {
throw SQLAnywhereException::fromSQLAnywhereError($this->conn); throw SQLAnywhereException::fromSQLAnywhereError($this->connection);
} }
return true; return true;
} }
} }
\ No newline at end of file
...@@ -42,24 +42,23 @@ class SQLAnywhereException extends DBALException ...@@ -42,24 +42,23 @@ class SQLAnywhereException extends DBALException
*/ */
public static function fromSQLAnywhereError($conn = null, $stmt = null) public static function fromSQLAnywhereError($conn = null, $stmt = null)
{ {
if ($conn !== null && ! (is_resource($conn) && get_resource_type($conn) == 'SQLAnywhere connection')) { if (null !== $conn && ! (is_resource($conn) && get_resource_type($conn) === 'SQLAnywhere connection')) {
throw new \InvalidArgumentException('Invalid SQL Anywhere connection resource given: ' . $conn); throw new \InvalidArgumentException('Invalid SQL Anywhere connection resource given: ' . $conn);
} }
if ($stmt !== null && ! (is_resource($stmt) && get_resource_type($stmt) == 'SQLAnywhere statement')) { if (null !== $stmt && ! (is_resource($stmt) && get_resource_type($stmt) === 'SQLAnywhere statement')) {
throw new \InvalidArgumentException('Invalid SQL Anywhere statement resource given: ' . $stmt); throw new \InvalidArgumentException('Invalid SQL Anywhere statement resource given: ' . $stmt);
} }
$state = $conn ? sasql_sqlstate($conn) : sasql_sqlstate(); $state = $conn ? sasql_sqlstate($conn) : sasql_sqlstate();
$code = null;
$code = null;
$message = null; $message = null;
/** /**
* Try retrieving the last error from statement resource if given * Try retrieving the last error from statement resource if given
*/ */
if ($stmt) { if ($stmt) {
$code = sasql_stmt_errno($stmt); $code = sasql_stmt_errno($stmt);
$message = sasql_stmt_error($stmt); $message = sasql_stmt_error($stmt);
} }
...@@ -72,7 +71,7 @@ class SQLAnywhereException extends DBALException ...@@ -72,7 +71,7 @@ class SQLAnywhereException extends DBALException
* a prepared statement. * a prepared statement.
*/ */
if ($conn && ! $code) { if ($conn && ! $code) {
$code = sasql_errorcode($conn); $code = sasql_errorcode($conn);
$message = sasql_error($conn); $message = sasql_error($conn);
} }
...@@ -82,17 +81,15 @@ class SQLAnywhereException extends DBALException ...@@ -82,17 +81,15 @@ class SQLAnywhereException extends DBALException
* connection / statement resource. * connection / statement resource.
*/ */
if ( ! $conn || ! $code) { if ( ! $conn || ! $code) {
$code = sasql_errorcode(); $code = sasql_errorcode();
$message = sasql_error(); $message = sasql_error();
} }
if ($message) { if ($message) {
$message = 'SQLSTATE [' . $state . '] [' . $code . '] ' . $message; return new self('SQLSTATE [' . $state . '] [' . $code . '] ' . $message, $code);
} else {
$message = 'SQL Anywhere error occurred but no error message was retrieved from driver.';
} }
return new self($message, $code); return new self('SQL Anywhere error occurred but no error message was retrieved from driver.', $code);
} }
} }
...@@ -36,22 +36,27 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement ...@@ -36,22 +36,27 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
* @var resource The connection resource. * @var resource The connection resource.
*/ */
private $conn; private $conn;
/** /**
* @var string Name of the default class to instantiate when fetch mode is \PDO::FETCH_CLASS. * @var string Name of the default class to instantiate when fetch mode is \PDO::FETCH_CLASS.
*/ */
private $defaultFetchClass = '\stdClass'; private $defaultFetchClass = '\stdClass';
/** /**
* @var string Constructor arguments for the default class to instantiate when fetch mode is \PDO::FETCH_CLASS. * @var string Constructor arguments for the default class to instantiate when fetch mode is \PDO::FETCH_CLASS.
*/ */
private $defaultFetchClassCtorArgs = array(); private $defaultFetchClassCtorArgs = array();
/** /**
* @var int Default fetch mode to use. * @var int Default fetch mode to use.
*/ */
private $defaultFetchMode = PDO::FETCH_BOTH; private $defaultFetchMode = PDO::FETCH_BOTH;
/** /**
* @var resource The result set resource to fetch. * @var resource The result set resource to fetch.
*/ */
private $result; private $result;
/** /**
* @var resource The prepared SQL statement to execute. * @var resource The prepared SQL statement to execute.
*/ */
...@@ -69,14 +74,14 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement ...@@ -69,14 +74,14 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
*/ */
public function __construct($conn, $sql) public function __construct($conn, $sql)
{ {
if ( ! is_resource($conn) || get_resource_type($conn) != 'SQLAnywhere connection') { if ( ! is_resource($conn) || get_resource_type($conn) !== 'SQLAnywhere connection') {
throw new SQLAnywhereException('Invalid SQL Anywhere connection resource: ' . $conn); throw new SQLAnywhereException('Invalid SQL Anywhere connection resource: ' . $conn);
} }
$this->conn = $conn; $this->conn = $conn;
$this->stmt = sasql_prepare($conn, $sql); $this->stmt = sasql_prepare($conn, $sql);
if ( ! is_resource($this->stmt) || get_resource_type($this->stmt) != 'SQLAnywhere statement') { if ( ! is_resource($this->stmt) || get_resource_type($this->stmt) !== 'SQLAnywhere statement') {
throw SQLAnywhereException::fromSQLAnywhereError($conn); throw SQLAnywhereException::fromSQLAnywhereError($conn);
} }
} }
...@@ -164,10 +169,12 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement ...@@ -164,10 +169,12 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
*/ */
public function execute($params = null) public function execute($params = null)
{ {
if ($params) { if (is_array($params)) {
$hasZeroIndex = array_key_exists(0, $params); $hasZeroIndex = array_key_exists(0, $params);
foreach ($params as $key => $val) { foreach ($params as $key => $val) {
$key = ($hasZeroIndex && is_numeric($key)) ? $key + 1 : $key; $key = ($hasZeroIndex && is_numeric($key)) ? $key + 1 : $key;
$this->bindValue($key, $val); $this->bindValue($key, $val);
} }
} }
...@@ -188,7 +195,7 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement ...@@ -188,7 +195,7 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
*/ */
public function fetch($fetchMode = null) public function fetch($fetchMode = null)
{ {
if ( ! is_resource($this->result) || get_resource_type($this->result) != 'SQLAnywhere result') { if ( ! is_resource($this->result) || get_resource_type($this->result) !== 'SQLAnywhere result') {
return false; return false;
} }
...@@ -201,12 +208,12 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement ...@@ -201,12 +208,12 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
return sasql_fetch_array($this->result, SASQL_BOTH); return sasql_fetch_array($this->result, SASQL_BOTH);
case PDO::FETCH_CLASS: case PDO::FETCH_CLASS:
$className = $this->defaultFetchClass; $className = $this->defaultFetchClass;
$ctorArgs = $this->defaultFetchClassCtorArgs; $ctorArgs = $this->defaultFetchClassCtorArgs;
if (func_num_args() >= 2) { if (func_num_args() >= 2) {
$args = func_get_args(); $args = func_get_args();
$className = $args[1]; $className = $args[1];
$ctorArgs = isset($args[2]) ? $args[2] : array(); $ctorArgs = isset($args[2]) ? $args[2] : array();
} }
$result = sasql_fetch_object($this->result); $result = sasql_fetch_object($this->result);
...@@ -287,8 +294,8 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement ...@@ -287,8 +294,8 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
*/ */
public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null) public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null)
{ {
$this->defaultFetchMode = $fetchMode; $this->defaultFetchMode = $fetchMode;
$this->defaultFetchClass = $arg2 ? $arg2 : $this->defaultFetchClass; $this->defaultFetchClass = $arg2 ? $arg2 : $this->defaultFetchClass;
$this->defaultFetchClassCtorArgs = $arg3 ? (array) $arg3 : $this->defaultFetchClassCtorArgs; $this->defaultFetchClassCtorArgs = $arg3 ? (array) $arg3 : $this->defaultFetchClassCtorArgs;
} }
...@@ -316,16 +323,18 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement ...@@ -316,16 +323,18 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
$destinationClass = $destinationClass->newInstanceArgs($ctorArgs); $destinationClass = $destinationClass->newInstanceArgs($ctorArgs);
} }
$sourceReflection = new \ReflectionObject($sourceObject); $sourceReflection = new \ReflectionObject($sourceObject);
$destinationClassReflection = new \ReflectionObject($destinationClass); $destinationClassReflection = new \ReflectionObject($destinationClass);
foreach ($sourceReflection->getProperties() as $sourceProperty) { foreach ($sourceReflection->getProperties() as $sourceProperty) {
$sourceProperty->setAccessible(true); $sourceProperty->setAccessible(true);
$name = $sourceProperty->getName();
$name = $sourceProperty->getName();
$value = $sourceProperty->getValue($sourceObject); $value = $sourceProperty->getValue($sourceObject);
if ($destinationClassReflection->hasProperty($name)) { if ($destinationClassReflection->hasProperty($name)) {
$destinationProperty = $destinationClassReflection->getProperty($name); $destinationProperty = $destinationClassReflection->getProperty($name);
$destinationProperty->setAccessible(true); $destinationProperty->setAccessible(true);
$destinationProperty->setValue($destinationClass, $value); $destinationProperty->setValue($destinationClass, $value);
} else { } else {
...@@ -336,4 +345,3 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement ...@@ -336,4 +345,3 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
return $destinationClass; return $destinationClass;
} }
} }
...@@ -38,18 +38,18 @@ final class DriverManager ...@@ -38,18 +38,18 @@ final class DriverManager
* @var array * @var array
*/ */
private static $_driverMap = array( private static $_driverMap = array(
'pdo_mysql' => 'Doctrine\DBAL\Driver\PDOMySql\Driver', 'pdo_mysql' => 'Doctrine\DBAL\Driver\PDOMySql\Driver',
'pdo_sqlite' => 'Doctrine\DBAL\Driver\PDOSqlite\Driver', 'pdo_sqlite' => 'Doctrine\DBAL\Driver\PDOSqlite\Driver',
'pdo_pgsql' => 'Doctrine\DBAL\Driver\PDOPgSql\Driver', 'pdo_pgsql' => 'Doctrine\DBAL\Driver\PDOPgSql\Driver',
'pdo_oci' => 'Doctrine\DBAL\Driver\PDOOracle\Driver', 'pdo_oci' => 'Doctrine\DBAL\Driver\PDOOracle\Driver',
'oci8' => 'Doctrine\DBAL\Driver\OCI8\Driver', 'oci8' => 'Doctrine\DBAL\Driver\OCI8\Driver',
'ibm_db2' => 'Doctrine\DBAL\Driver\IBMDB2\DB2Driver', 'ibm_db2' => 'Doctrine\DBAL\Driver\IBMDB2\DB2Driver',
'pdo_ibm' => 'Doctrine\DBAL\Driver\PDOIbm\Driver', 'pdo_ibm' => 'Doctrine\DBAL\Driver\PDOIbm\Driver',
'pdo_sqlsrv' => 'Doctrine\DBAL\Driver\PDOSqlsrv\Driver', 'pdo_sqlsrv' => 'Doctrine\DBAL\Driver\PDOSqlsrv\Driver',
'mysqli' => 'Doctrine\DBAL\Driver\Mysqli\Driver', 'mysqli' => 'Doctrine\DBAL\Driver\Mysqli\Driver',
'drizzle_pdo_mysql' => 'Doctrine\DBAL\Driver\DrizzlePDOMySql\Driver', 'drizzle_pdo_mysql' => 'Doctrine\DBAL\Driver\DrizzlePDOMySql\Driver',
'sqlanywhere' => 'Doctrine\DBAL\Driver\SQLAnywhere\Driver', 'sqlanywhere' => 'Doctrine\DBAL\Driver\SQLAnywhere\Driver',
'sqlsrv' => 'Doctrine\DBAL\Driver\SQLSrv\Driver' 'sqlsrv' => 'Doctrine\DBAL\Driver\SQLSrv\Driver',
); );
/** /**
......
...@@ -41,9 +41,15 @@ class SQLAnywhere11Keywords extends SQLAnywhereKeywords ...@@ -41,9 +41,15 @@ class SQLAnywhere11Keywords extends SQLAnywhereKeywords
*/ */
protected function getKeywords() protected function getKeywords()
{ {
return array_merge(array_diff(parent::getKeywords(), array('IQ')), array( return array_merge(
'MERGE', array_diff(
'OPENSTRING' parent::getKeywords(),
)); array('IQ')
),
array(
'MERGE',
'OPENSTRING'
)
);
} }
} }
\ No newline at end of file
...@@ -41,18 +41,24 @@ class SQLAnywhere12Keywords extends SQLAnywhere11Keywords ...@@ -41,18 +41,24 @@ class SQLAnywhere12Keywords extends SQLAnywhere11Keywords
*/ */
protected function getKeywords() protected function getKeywords()
{ {
return array_merge(array_diff(parent::getKeywords(), array( return array_merge(
'INDEX_LPAREN', array_diff(
'SYNTAX_ERROR', parent::getKeywords(),
'WITH_CUBE', array(
'WITH_LPAREN', 'INDEX_LPAREN',
'WITH_ROLLUP' 'SYNTAX_ERROR',
)), array( 'WITH_CUBE',
'DATETIMEOFFSET', 'WITH_LPAREN',
'LIMIT', 'WITH_ROLLUP'
'OPENXML', )
'SPATIAL', ),
'TREAT' array(
)); 'DATETIMEOFFSET',
'LIMIT',
'OPENXML',
'SPATIAL',
'TREAT'
)
);
} }
} }
\ No newline at end of file
...@@ -41,13 +41,16 @@ class SQLAnywhere16Keywords extends SQLAnywhere12Keywords ...@@ -41,13 +41,16 @@ class SQLAnywhere16Keywords extends SQLAnywhere12Keywords
*/ */
protected function getKeywords() protected function getKeywords()
{ {
return array_merge(parent::getKeywords(), array( return array_merge(
'ARRAY', parent::getKeywords(),
'JSON', array(
'ROW', 'ARRAY',
'ROWTYPE', 'JSON',
'UNNEST', 'ROW',
'VARRAY' 'ROWTYPE',
)); 'UNNEST',
'VARRAY'
)
);
} }
} }
\ No newline at end of file
...@@ -278,4 +278,4 @@ class SQLAnywhereKeywords extends KeywordList ...@@ -278,4 +278,4 @@ class SQLAnywhereKeywords extends KeywordList
'XML' 'XML'
); );
} }
} }
\ No newline at end of file
...@@ -77,8 +77,6 @@ class SQLAnywhere12Platform extends SQLAnywhere11Platform ...@@ -77,8 +77,6 @@ class SQLAnywhere12Platform extends SQLAnywhere11Platform
$sequence = $sequence->getQuotedName($this); $sequence = $sequence->getQuotedName($this);
} }
/** @var string $sequence */
return 'DROP SEQUENCE ' . $sequence; return 'DROP SEQUENCE ' . $sequence;
} }
...@@ -111,13 +109,11 @@ class SQLAnywhere12Platform extends SQLAnywhere11Platform ...@@ -111,13 +109,11 @@ class SQLAnywhere12Platform extends SQLAnywhere11Platform
*/ */
protected function getAdvancedIndexOptionsSQL(Index $index) protected function getAdvancedIndexOptionsSQL(Index $index)
{ {
$sql = '';
if (!$index->isPrimary() && $index->isUnique() && $index->hasFlag('with_nulls_not_distinct')) { if (!$index->isPrimary() && $index->isUnique() && $index->hasFlag('with_nulls_not_distinct')) {
$sql .= ' WITH NULLS NOT DISTINCT'; return ' WITH NULLS NOT DISTINCT' . parent::getAdvancedIndexOptionsSQL($index);
} }
return $sql . parent::getAdvancedIndexOptionsSQL($index); return parent::getAdvancedIndexOptionsSQL($index);
} }
/** /**
......
...@@ -43,13 +43,11 @@ class SQLAnywhere16Platform extends SQLAnywhere12Platform ...@@ -43,13 +43,11 @@ class SQLAnywhere16Platform extends SQLAnywhere12Platform
); );
} }
$sql = '';
if (!$index->isPrimary() && $index->isUnique() && $index->hasFlag('with_nulls_distinct')) { if (!$index->isPrimary() && $index->isUnique() && $index->hasFlag('with_nulls_distinct')) {
$sql .= ' WITH NULLS DISTINCT'; return ' WITH NULLS DISTINCT' . parent::getAdvancedIndexOptionsSQL($index);
} }
return $sql . parent::getAdvancedIndexOptionsSQL($index); return parent::getAdvancedIndexOptionsSQL($index);
} }
/** /**
......
...@@ -129,11 +129,11 @@ class SQLAnywherePlatform extends AbstractPlatform ...@@ -129,11 +129,11 @@ class SQLAnywherePlatform extends AbstractPlatform
*/ */
public function getAlterTableSQL(TableDiff $diff) public function getAlterTableSQL(TableDiff $diff)
{ {
$sql = array(); $sql = array();
$columnSql = array(); $columnSql = array();
$commentsSQL = array(); $commentsSQL = array();
$tableSql = array(); $tableSql = array();
$queryParts = array(); $queryParts = array();
/** @var \Doctrine\DBAL\Schema\Column $column */ /** @var \Doctrine\DBAL\Schema\Column $column */
foreach ($diff->addedColumns as $column) { foreach ($diff->addedColumns as $column) {
...@@ -262,7 +262,7 @@ class SQLAnywherePlatform extends AbstractPlatform ...@@ -262,7 +262,7 @@ class SQLAnywherePlatform extends AbstractPlatform
*/ */
public function getConcatExpression() public function getConcatExpression()
{ {
return 'STRING(' . join(', ', (array) func_get_args()) . ')'; return 'STRING(' . implode(', ', (array) func_get_args()) . ')';
} }
/** /**
...@@ -278,25 +278,24 @@ class SQLAnywherePlatform extends AbstractPlatform ...@@ -278,25 +278,24 @@ class SQLAnywherePlatform extends AbstractPlatform
$table = $table->getQuotedName($this); $table = $table->getQuotedName($this);
} }
/** @var string $table */
$query = 'ALTER TABLE ' . $table . ' ADD '; $query = 'ALTER TABLE ' . $table . ' ADD ';
if ($constraint instanceof Index) { if ($constraint instanceof Index) {
if ($constraint->isPrimary()) { if ($constraint->isPrimary()) {
$query .= $this->getPrimaryKeyDeclarationSQL($constraint, $constraint->getQuotedName($this)); return $query . $this->getPrimaryKeyDeclarationSQL($constraint, $constraint->getQuotedName($this));
} elseif ($constraint->isUnique()) {
$query .= $this->getUniqueConstraintDeclarationSQL($constraint->getQuotedName($this), $constraint);
} else {
throw new \InvalidArgumentException(
'Can only create primary or unique constraints, no common indexes with getCreateConstraintSQL().'
);
} }
} else {
throw new \InvalidArgumentException('Unsupported constraint type: ' . get_class($constraint)); if ($constraint->isUnique()) {
return $query .
$this->getUniqueConstraintDeclarationSQL($constraint->getQuotedName($this), $constraint);
}
throw new \InvalidArgumentException(
'Can only create primary or unique constraints, no common indexes with getCreateConstraintSQL().'
);
} }
return $query; throw new \InvalidArgumentException('Unsupported constraint type: ' . get_class($constraint));
} }
/** /**
...@@ -326,8 +325,6 @@ class SQLAnywherePlatform extends AbstractPlatform ...@@ -326,8 +325,6 @@ class SQLAnywherePlatform extends AbstractPlatform
$table = $table->getQuotedName($this); $table = $table->getQuotedName($this);
} }
/** @var string $table */
return 'ALTER TABLE ' . $table . ' ADD ' . $this->getPrimaryKeyDeclarationSQL($index); return 'ALTER TABLE ' . $table . ' ADD ' . $this->getPrimaryKeyDeclarationSQL($index);
} }
...@@ -490,7 +487,9 @@ class SQLAnywherePlatform extends AbstractPlatform ...@@ -490,7 +487,9 @@ class SQLAnywherePlatform extends AbstractPlatform
{ {
if ($index instanceof Index) { if ($index instanceof Index) {
$index = $index->getQuotedName($this); $index = $index->getQuotedName($this);
} elseif ( ! is_string($index)) { }
if ( ! is_string($index)) {
throw new \InvalidArgumentException( throw new \InvalidArgumentException(
'SQLAnywherePlatform::getDropIndexSQL() expects $index parameter to be string or ' . 'SQLAnywherePlatform::getDropIndexSQL() expects $index parameter to be string or ' .
'\Doctrine\DBAL\Schema\Index.' '\Doctrine\DBAL\Schema\Index.'
...@@ -503,7 +502,9 @@ class SQLAnywherePlatform extends AbstractPlatform ...@@ -503,7 +502,9 @@ class SQLAnywherePlatform extends AbstractPlatform
if ($table instanceof Table) { if ($table instanceof Table) {
$table = $table->getQuotedName($this); $table = $table->getQuotedName($this);
} elseif ( ! is_string($table)) { }
if ( ! is_string($table)) {
throw new \InvalidArgumentException( throw new \InvalidArgumentException(
'SQLAnywherePlatform::getDropIndexSQL() expects $table parameter to be string or ' . 'SQLAnywherePlatform::getDropIndexSQL() expects $table parameter to be string or ' .
'\Doctrine\DBAL\Schema\Table.' '\Doctrine\DBAL\Schema\Table.'
...@@ -526,10 +527,10 @@ class SQLAnywherePlatform extends AbstractPlatform ...@@ -526,10 +527,10 @@ class SQLAnywherePlatform extends AbstractPlatform
*/ */
public function getForeignKeyBaseDeclarationSQL(ForeignKeyConstraint $foreignKey) public function getForeignKeyBaseDeclarationSQL(ForeignKeyConstraint $foreignKey)
{ {
$sql = ''; $sql = '';
$foreignKeyName = $foreignKey->getName(); $foreignKeyName = $foreignKey->getName();
$localColumns = $foreignKey->getQuotedLocalColumns($this); $localColumns = $foreignKey->getQuotedLocalColumns($this);
$foreignColumns = $foreignKey->getQuotedForeignColumns($this); $foreignColumns = $foreignKey->getQuotedForeignColumns($this);
$foreignTableName = $foreignKey->getQuotedForeignTableName($this); $foreignTableName = $foreignKey->getQuotedForeignTableName($this);
if ( ! empty($foreignKeyName)) { if ( ! empty($foreignKeyName)) {
...@@ -633,9 +634,7 @@ class SQLAnywherePlatform extends AbstractPlatform ...@@ -633,9 +634,7 @@ class SQLAnywherePlatform extends AbstractPlatform
*/ */
public function getIndexDeclarationSQL($name, Index $index) public function getIndexDeclarationSQL($name, Index $index)
{ {
/** // Index declaration in statements like CREATE TABLE is not supported.
* Index declaration in statements like CREATE TABLE is not supported
*/
throw DBALException::notSupported(__METHOD__); throw DBALException::notSupported(__METHOD__);
} }
...@@ -902,7 +901,7 @@ class SQLAnywherePlatform extends AbstractPlatform ...@@ -902,7 +901,7 @@ class SQLAnywherePlatform extends AbstractPlatform
throw new \InvalidArgumentException("Incomplete definition. 'columns' required."); throw new \InvalidArgumentException("Incomplete definition. 'columns' required.");
} }
$sql = ''; $sql = '';
$flags = ''; $flags = '';
if ( ! empty($name)) { if ( ! empty($name)) {
...@@ -974,7 +973,7 @@ class SQLAnywherePlatform extends AbstractPlatform ...@@ -974,7 +973,7 @@ class SQLAnywherePlatform extends AbstractPlatform
*/ */
public function getSubstringExpression($value, $from, $length = null) public function getSubstringExpression($value, $from, $length = null)
{ {
if ($length === null) { if (null === $length) {
return 'SUBSTRING(' . $value . ', ' . $from . ')'; return 'SUBSTRING(' . $value . ', ' . $from . ')';
} }
...@@ -1054,7 +1053,7 @@ class SQLAnywherePlatform extends AbstractPlatform ...@@ -1054,7 +1053,7 @@ class SQLAnywherePlatform extends AbstractPlatform
throw new \InvalidArgumentException("Incomplete definition. 'columns' required."); throw new \InvalidArgumentException("Incomplete definition. 'columns' required.");
} }
$sql = ''; $sql = '';
$flags = ''; $flags = '';
if ( ! empty($name)) { if ( ! empty($name)) {
...@@ -1138,7 +1137,7 @@ class SQLAnywherePlatform extends AbstractPlatform ...@@ -1138,7 +1137,7 @@ class SQLAnywherePlatform extends AbstractPlatform
*/ */
protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef) protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef)
{ {
$unsigned = ! empty($columnDef['unsigned']) ? 'UNSIGNED ' : ''; $unsigned = ! empty($columnDef['unsigned']) ? 'UNSIGNED ' : '';
$autoincrement = ! empty($columnDef['autoincrement']) ? ' IDENTITY' : ''; $autoincrement = ! empty($columnDef['autoincrement']) ? ' IDENTITY' : '';
return $unsigned . $columnDef['integer_type'] . $autoincrement; return $unsigned . $columnDef['integer_type'] . $autoincrement;
...@@ -1231,11 +1230,12 @@ class SQLAnywherePlatform extends AbstractPlatform ...@@ -1231,11 +1230,12 @@ class SQLAnywherePlatform extends AbstractPlatform
if ($limit == 0) { if ($limit == 0) {
$limitOffsetClause = 'TOP ALL '; $limitOffsetClause = 'TOP ALL ';
} }
$limitOffsetClause .= 'START AT ' . ($offset + 1) . ' '; $limitOffsetClause .= 'START AT ' . ($offset + 1) . ' ';
} }
if ($limitOffsetClause) { if ($limitOffsetClause) {
$query = preg_replace('/^\s*(SELECT\s+(DISTINCT\s+)?)/i', '\1' . $limitOffsetClause, $query); return preg_replace('/^\s*(SELECT\s+(DISTINCT\s+)?)/i', '\1' . $limitOffsetClause, $query);
} }
return $query; return $query;
......
...@@ -101,18 +101,16 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager ...@@ -101,18 +101,16 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager
*/ */
protected function _getPortableTableColumnDefinition($tableColumn) protected function _getPortableTableColumnDefinition($tableColumn)
{ {
$type = $this->_platform->getDoctrineTypeMapping($tableColumn['type']); $type = $this->_platform->getDoctrineTypeMapping($tableColumn['type']);
$type = $this->extractDoctrineTypeFromComment($tableColumn['comment'], $type); $type = $this->extractDoctrineTypeFromComment($tableColumn['comment'], $type);
$tableColumn['comment'] = $this->removeDoctrineTypeFromComment($tableColumn['comment'], $type); $tableColumn['comment'] = $this->removeDoctrineTypeFromComment($tableColumn['comment'], $type);
$precision = null; $precision = null;
$scale = null; $scale = null;
$fixed = false; $fixed = false;
$default = null; $default = null;
if ($tableColumn['default']) { if ($tableColumn['default']) {
/** // Strip quotes from default value.
* Strip quotes from default value
*/
$default = preg_replace(array("/^'(.*)'$/", "/''/"), array("$1", "'"), $tableColumn['default']); $default = preg_replace(array("/^'(.*)'$/", "/''/"), array("$1", "'"), $tableColumn['default']);
} }
...@@ -134,15 +132,15 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager ...@@ -134,15 +132,15 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager
$tableColumn['column_name'], $tableColumn['column_name'],
Type::getType($type), Type::getType($type),
array( array(
'length' => $type == 'string' ? $tableColumn['length'] : null, 'length' => $type == 'string' ? $tableColumn['length'] : null,
'precision' => $precision, 'precision' => $precision,
'scale' => $scale, 'scale' => $scale,
'unsigned' => (bool) $tableColumn['unsigned'], 'unsigned' => (bool) $tableColumn['unsigned'],
'fixed' => $fixed, 'fixed' => $fixed,
'notnull' => (bool) $tableColumn['notnull'], 'notnull' => (bool) $tableColumn['notnull'],
'default' => $default, 'default' => $default,
'autoincrement' => (bool) $tableColumn['autoincrement'], 'autoincrement' => (bool) $tableColumn['autoincrement'],
'comment' => $tableColumn['comment'] 'comment' => $tableColumn['comment']
)); ));
} }
...@@ -178,17 +176,17 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager ...@@ -178,17 +176,17 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager
foreach ($tableForeignKeys as $tableForeignKey) { foreach ($tableForeignKeys as $tableForeignKey) {
if (!isset($foreignKeys[$tableForeignKey['index_name']])) { if (!isset($foreignKeys[$tableForeignKey['index_name']])) {
$foreignKeys[$tableForeignKey['index_name']] = array( $foreignKeys[$tableForeignKey['index_name']] = array(
'local_columns' => array($tableForeignKey['local_column']), 'local_columns' => array($tableForeignKey['local_column']),
'foreign_table' => $tableForeignKey['foreign_table'], 'foreign_table' => $tableForeignKey['foreign_table'],
'foreign_columns' => array($tableForeignKey['foreign_column']), 'foreign_columns' => array($tableForeignKey['foreign_column']),
'name' => $tableForeignKey['index_name'], 'name' => $tableForeignKey['index_name'],
'options' => array( 'options' => array(
'notnull' => $tableForeignKey['notnull'], 'notnull' => $tableForeignKey['notnull'],
'match' => $tableForeignKey['match'], 'match' => $tableForeignKey['match'],
'onUpdate' => $tableForeignKey['on_update'], 'onUpdate' => $tableForeignKey['on_update'],
'onDelete' => $tableForeignKey['on_delete'], 'onDelete' => $tableForeignKey['on_delete'],
'check_on_commit' => $tableForeignKey['check_on_commit'], 'check_on_commit' => $tableForeignKey['check_on_commit'],
'clustered' => $tableForeignKey['clustered'], 'clustered' => $tableForeignKey['clustered'],
'for_olap_workload' => $tableForeignKey['for_olap_workload'] 'for_olap_workload' => $tableForeignKey['for_olap_workload']
) )
); );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment