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

fix CS

parent 0083774f
......@@ -33,7 +33,7 @@ class SQLAnywhereConnection implements Connection
/**
* @var resource The SQL Anywhere connection resource.
*/
private $conn;
private $connection;
/**
* Constructor.
......@@ -47,31 +47,25 @@ class SQLAnywhereConnection implements Connection
*/
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();
}
/**
* Disable PHP warnings on error
*/
if ( ! sasql_set_option($this->conn, 'verbose_errors', false)) {
throw SQLAnywhereException::fromSQLAnywhereError($this->conn);
// Disable PHP warnings on error.
if ( ! sasql_set_option($this->connection, 'verbose_errors', false)) {
throw SQLAnywhereException::fromSQLAnywhereError($this->connection);
}
/**
* Enable auto committing by default
*/
if ( ! sasql_set_option($this->conn, 'auto_commit', 'on')) {
throw SQLAnywhereException::fromSQLAnywhereError($this->conn);
// Enable auto committing by default.
if ( ! sasql_set_option($this->connection, 'auto_commit', 'on')) {
throw SQLAnywhereException::fromSQLAnywhereError($this->connection);
}
/**
* Enable exact, non-approximated row count retrieval
*/
if ( ! sasql_set_option($this->conn, 'row_counts', true)) {
throw SQLAnywhereException::fromSQLAnywhereError($this->conn);
// Enable exact, non-approximated row count retrieval.
if ( ! sasql_set_option($this->connection, 'row_counts', true)) {
throw SQLAnywhereException::fromSQLAnywhereError($this->connection);
}
}
......@@ -82,8 +76,8 @@ class SQLAnywhereConnection implements Connection
*/
public function beginTransaction()
{
if ( ! sasql_set_option($this->conn, 'auto_commit', 'off')) {
throw SQLAnywhereException::fromSQLAnywhereError($this->conn);
if ( ! sasql_set_option($this->connection, 'auto_commit', 'off')) {
throw SQLAnywhereException::fromSQLAnywhereError($this->connection);
}
return true;
......@@ -96,8 +90,8 @@ class SQLAnywhereConnection implements Connection
*/
public function commit()
{
if ( ! sasql_commit($this->conn)) {
throw SQLAnywhereException::fromSQLAnywhereError($this->conn);
if ( ! sasql_commit($this->connection)) {
throw SQLAnywhereException::fromSQLAnywhereError($this->connection);
}
$this->endTransaction();
......@@ -110,7 +104,7 @@ class SQLAnywhereConnection implements Connection
*/
public function errorCode()
{
return sasql_errorcode($this->conn);
return sasql_errorcode($this->connection);
}
/**
......@@ -118,7 +112,7 @@ class SQLAnywhereConnection implements Connection
*/
public function errorInfo()
{
return sasql_error($this->conn);
return sasql_error($this->connection);
}
/**
......@@ -127,6 +121,7 @@ class SQLAnywhereConnection implements Connection
public function exec($statement)
{
$stmt = $this->prepare($statement);
$stmt->execute();
return $stmt->rowCount();
......@@ -137,8 +132,8 @@ class SQLAnywhereConnection implements Connection
*/
public function lastInsertId($name = null)
{
if ($name === null) {
return sasql_insert_id($this->conn);
if (null === $name) {
return sasql_insert_id($this->connection);
}
return $this->query('SELECT ' . $name . '.CURRVAL')->fetchColumn();
......@@ -149,7 +144,7 @@ class SQLAnywhereConnection implements Connection
*/
public function prepare($prepareString)
{
return new SQLAnywhereStatement($this->conn, $prepareString);
return new SQLAnywhereStatement($this->connection, $prepareString);
}
/**
......@@ -159,6 +154,7 @@ class SQLAnywhereConnection implements Connection
{
$args = func_get_args();
$stmt = $this->prepare($args[0]);
$stmt->execute();
return $stmt;
......@@ -173,7 +169,7 @@ class SQLAnywhereConnection implements Connection
return $input;
}
return "'" . sasql_escape_string($this->conn, $input) . "'";
return "'" . sasql_escape_string($this->connection, $input) . "'";
}
/**
......@@ -183,8 +179,8 @@ class SQLAnywhereConnection implements Connection
*/
public function rollBack()
{
if ( ! sasql_rollback($this->conn)) {
throw SQLAnywhereException::fromSQLAnywhereError($this->conn);
if ( ! sasql_rollback($this->connection)) {
throw SQLAnywhereException::fromSQLAnywhereError($this->connection);
}
$this->endTransaction();
......@@ -201,8 +197,8 @@ class SQLAnywhereConnection implements Connection
*/
private function endTransaction()
{
if ( ! sasql_set_option($this->conn, 'auto_commit', 'on')) {
throw SQLAnywhereException::fromSQLAnywhereError($this->conn);
if ( ! sasql_set_option($this->connection, 'auto_commit', 'on')) {
throw SQLAnywhereException::fromSQLAnywhereError($this->connection);
}
return true;
......
......@@ -42,16 +42,15 @@ class SQLAnywhereException extends DBALException
*/
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);
}
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);
}
$state = $conn ? sasql_sqlstate($conn) : sasql_sqlstate();
$code = null;
$message = null;
......@@ -87,12 +86,10 @@ class SQLAnywhereException extends DBALException
}
if ($message) {
$message = 'SQLSTATE [' . $state . '] [' . $code . '] ' . $message;
} else {
$message = 'SQL Anywhere error occurred but no error message was retrieved from driver.';
return new self('SQLSTATE [' . $state . '] [' . $code . '] ' . $message, $code);
}
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
* @var resource The connection resource.
*/
private $conn;
/**
* @var string Name of the default class to instantiate when fetch mode is \PDO::FETCH_CLASS.
*/
private $defaultFetchClass = '\stdClass';
/**
* @var string Constructor arguments for the default class to instantiate when fetch mode is \PDO::FETCH_CLASS.
*/
private $defaultFetchClassCtorArgs = array();
/**
* @var int Default fetch mode to use.
*/
private $defaultFetchMode = PDO::FETCH_BOTH;
/**
* @var resource The result set resource to fetch.
*/
private $result;
/**
* @var resource The prepared SQL statement to execute.
*/
......@@ -69,14 +74,14 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
*/
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);
}
$this->conn = $conn;
$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);
}
}
......@@ -164,10 +169,12 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
*/
public function execute($params = null)
{
if ($params) {
if (is_array($params)) {
$hasZeroIndex = array_key_exists(0, $params);
foreach ($params as $key => $val) {
$key = ($hasZeroIndex && is_numeric($key)) ? $key + 1 : $key;
$this->bindValue($key, $val);
}
}
......@@ -188,7 +195,7 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
*/
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;
}
......@@ -321,11 +328,13 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
foreach ($sourceReflection->getProperties() as $sourceProperty) {
$sourceProperty->setAccessible(true);
$name = $sourceProperty->getName();
$value = $sourceProperty->getValue($sourceObject);
if ($destinationClassReflection->hasProperty($name)) {
$destinationProperty = $destinationClassReflection->getProperty($name);
$destinationProperty->setAccessible(true);
$destinationProperty->setValue($destinationClass, $value);
} else {
......@@ -336,4 +345,3 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
return $destinationClass;
}
}
......@@ -49,7 +49,7 @@ final class DriverManager
'mysqli' => 'Doctrine\DBAL\Driver\Mysqli\Driver',
'drizzle_pdo_mysql' => 'Doctrine\DBAL\Driver\DrizzlePDOMySql\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
*/
protected function getKeywords()
{
return array_merge(array_diff(parent::getKeywords(), array('IQ')), array(
return array_merge(
array_diff(
parent::getKeywords(),
array('IQ')
),
array(
'MERGE',
'OPENSTRING'
));
)
);
}
}
......@@ -41,18 +41,24 @@ class SQLAnywhere12Keywords extends SQLAnywhere11Keywords
*/
protected function getKeywords()
{
return array_merge(array_diff(parent::getKeywords(), array(
return array_merge(
array_diff(
parent::getKeywords(),
array(
'INDEX_LPAREN',
'SYNTAX_ERROR',
'WITH_CUBE',
'WITH_LPAREN',
'WITH_ROLLUP'
)), array(
)
),
array(
'DATETIMEOFFSET',
'LIMIT',
'OPENXML',
'SPATIAL',
'TREAT'
));
)
);
}
}
......@@ -41,13 +41,16 @@ class SQLAnywhere16Keywords extends SQLAnywhere12Keywords
*/
protected function getKeywords()
{
return array_merge(parent::getKeywords(), array(
return array_merge(
parent::getKeywords(),
array(
'ARRAY',
'JSON',
'ROW',
'ROWTYPE',
'UNNEST',
'VARRAY'
));
)
);
}
}
......@@ -77,8 +77,6 @@ class SQLAnywhere12Platform extends SQLAnywhere11Platform
$sequence = $sequence->getQuotedName($this);
}
/** @var string $sequence */
return 'DROP SEQUENCE ' . $sequence;
}
......@@ -111,13 +109,11 @@ class SQLAnywhere12Platform extends SQLAnywhere11Platform
*/
protected function getAdvancedIndexOptionsSQL(Index $index)
{
$sql = '';
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
);
}
$sql = '';
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);
}
/**
......
......@@ -262,7 +262,7 @@ class SQLAnywherePlatform extends AbstractPlatform
*/
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
$table = $table->getQuotedName($this);
}
/** @var string $table */
$query = 'ALTER TABLE ' . $table . ' ADD ';
if ($constraint instanceof Index) {
if ($constraint->isPrimary()) {
$query .= $this->getPrimaryKeyDeclarationSQL($constraint, $constraint->getQuotedName($this));
} elseif ($constraint->isUnique()) {
$query .= $this->getUniqueConstraintDeclarationSQL($constraint->getQuotedName($this), $constraint);
} else {
return $query . $this->getPrimaryKeyDeclarationSQL($constraint, $constraint->getQuotedName($this));
}
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().'
);
}
} else {
throw new \InvalidArgumentException('Unsupported constraint type: ' . get_class($constraint));
}
return $query;
throw new \InvalidArgumentException('Unsupported constraint type: ' . get_class($constraint));
}
/**
......@@ -326,8 +325,6 @@ class SQLAnywherePlatform extends AbstractPlatform
$table = $table->getQuotedName($this);
}
/** @var string $table */
return 'ALTER TABLE ' . $table . ' ADD ' . $this->getPrimaryKeyDeclarationSQL($index);
}
......@@ -490,7 +487,9 @@ class SQLAnywherePlatform extends AbstractPlatform
{
if ($index instanceof Index) {
$index = $index->getQuotedName($this);
} elseif ( ! is_string($index)) {
}
if ( ! is_string($index)) {
throw new \InvalidArgumentException(
'SQLAnywherePlatform::getDropIndexSQL() expects $index parameter to be string or ' .
'\Doctrine\DBAL\Schema\Index.'
......@@ -503,7 +502,9 @@ class SQLAnywherePlatform extends AbstractPlatform
if ($table instanceof Table) {
$table = $table->getQuotedName($this);
} elseif ( ! is_string($table)) {
}
if ( ! is_string($table)) {
throw new \InvalidArgumentException(
'SQLAnywherePlatform::getDropIndexSQL() expects $table parameter to be string or ' .
'\Doctrine\DBAL\Schema\Table.'
......@@ -633,9 +634,7 @@ class SQLAnywherePlatform extends AbstractPlatform
*/
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__);
}
......@@ -974,7 +973,7 @@ class SQLAnywherePlatform extends AbstractPlatform
*/
public function getSubstringExpression($value, $from, $length = null)
{
if ($length === null) {
if (null === $length) {
return 'SUBSTRING(' . $value . ', ' . $from . ')';
}
......@@ -1231,11 +1230,12 @@ class SQLAnywherePlatform extends AbstractPlatform
if ($limit == 0) {
$limitOffsetClause = 'TOP ALL ';
}
$limitOffsetClause .= 'START AT ' . ($offset + 1) . ' ';
}
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;
......
......@@ -110,9 +110,7 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager
$default = null;
if ($tableColumn['default']) {
/**
* Strip quotes from default value
*/
// Strip quotes from default value.
$default = preg_replace(array("/^'(.*)'$/", "/''/"), array("$1", "'"), $tableColumn['default']);
}
......
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