@@ -27,25 +27,25 @@ |
||
| 27 | 27 | namespace OC\DB; |
| 28 | 28 | |
| 29 | 29 | class AdapterOCI8 extends Adapter { |
| 30 | - public function lastInsertId($table) { |
|
| 31 | - if (is_null($table)) { |
|
| 32 | - throw new \InvalidArgumentException('Oracle requires a table name to be passed into lastInsertId()'); |
|
| 33 | - } |
|
| 34 | - if ($table !== null) { |
|
| 35 | - $suffix = '_SEQ'; |
|
| 36 | - $table = '"' . $table . $suffix . '"'; |
|
| 37 | - } |
|
| 38 | - return $this->conn->realLastInsertId($table); |
|
| 39 | - } |
|
| 30 | + public function lastInsertId($table) { |
|
| 31 | + if (is_null($table)) { |
|
| 32 | + throw new \InvalidArgumentException('Oracle requires a table name to be passed into lastInsertId()'); |
|
| 33 | + } |
|
| 34 | + if ($table !== null) { |
|
| 35 | + $suffix = '_SEQ'; |
|
| 36 | + $table = '"' . $table . $suffix . '"'; |
|
| 37 | + } |
|
| 38 | + return $this->conn->realLastInsertId($table); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - const UNIX_TIMESTAMP_REPLACEMENT = "(cast(sys_extract_utc(systimestamp) as date) - date'1970-01-01') * 86400"; |
|
| 41 | + const UNIX_TIMESTAMP_REPLACEMENT = "(cast(sys_extract_utc(systimestamp) as date) - date'1970-01-01') * 86400"; |
|
| 42 | 42 | |
| 43 | - public function fixupStatement($statement) { |
|
| 44 | - $statement = preg_replace('( LIKE \?)', '$0 ESCAPE \'\\\'', $statement); |
|
| 45 | - $statement = preg_replace('/`(\w+)` ILIKE \?/', 'REGEXP_LIKE(`$1`, \'^\' || REPLACE(?, \'%\', \'.*\') || \'$\', \'i\')', $statement); |
|
| 46 | - $statement = str_replace('`', '"', $statement); |
|
| 47 | - $statement = str_ireplace('NOW()', 'CURRENT_TIMESTAMP', $statement); |
|
| 48 | - $statement = str_ireplace('UNIX_TIMESTAMP()', self::UNIX_TIMESTAMP_REPLACEMENT, $statement); |
|
| 49 | - return $statement; |
|
| 50 | - } |
|
| 43 | + public function fixupStatement($statement) { |
|
| 44 | + $statement = preg_replace('( LIKE \?)', '$0 ESCAPE \'\\\'', $statement); |
|
| 45 | + $statement = preg_replace('/`(\w+)` ILIKE \?/', 'REGEXP_LIKE(`$1`, \'^\' || REPLACE(?, \'%\', \'.*\') || \'$\', \'i\')', $statement); |
|
| 46 | + $statement = str_replace('`', '"', $statement); |
|
| 47 | + $statement = str_ireplace('NOW()', 'CURRENT_TIMESTAMP', $statement); |
|
| 48 | + $statement = str_ireplace('UNIX_TIMESTAMP()', self::UNIX_TIMESTAMP_REPLACEMENT, $statement); |
|
| 49 | + return $statement; |
|
| 50 | + } |
|
| 51 | 51 | } |
@@ -33,7 +33,7 @@ |
||
| 33 | 33 | } |
| 34 | 34 | if ($table !== null) { |
| 35 | 35 | $suffix = '_SEQ'; |
| 36 | - $table = '"' . $table . $suffix . '"'; |
|
| 36 | + $table = '"'.$table.$suffix.'"'; |
|
| 37 | 37 | } |
| 38 | 38 | return $this->conn->realLastInsertId($table); |
| 39 | 39 | } |
@@ -29,28 +29,28 @@ |
||
| 29 | 29 | use Doctrine\DBAL\Schema\Table; |
| 30 | 30 | |
| 31 | 31 | class MySQLMigrator extends Migrator { |
| 32 | - /** |
|
| 33 | - * @param Schema $targetSchema |
|
| 34 | - * @param \Doctrine\DBAL\Connection $connection |
|
| 35 | - * @return \Doctrine\DBAL\Schema\SchemaDiff |
|
| 36 | - */ |
|
| 37 | - protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) { |
|
| 38 | - $platform = $connection->getDatabasePlatform(); |
|
| 39 | - $platform->registerDoctrineTypeMapping('enum', 'string'); |
|
| 40 | - $platform->registerDoctrineTypeMapping('bit', 'string'); |
|
| 32 | + /** |
|
| 33 | + * @param Schema $targetSchema |
|
| 34 | + * @param \Doctrine\DBAL\Connection $connection |
|
| 35 | + * @return \Doctrine\DBAL\Schema\SchemaDiff |
|
| 36 | + */ |
|
| 37 | + protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) { |
|
| 38 | + $platform = $connection->getDatabasePlatform(); |
|
| 39 | + $platform->registerDoctrineTypeMapping('enum', 'string'); |
|
| 40 | + $platform->registerDoctrineTypeMapping('bit', 'string'); |
|
| 41 | 41 | |
| 42 | - $schemaDiff = parent::getDiff($targetSchema, $connection); |
|
| 42 | + $schemaDiff = parent::getDiff($targetSchema, $connection); |
|
| 43 | 43 | |
| 44 | - // identifiers need to be quoted for mysql |
|
| 45 | - foreach ($schemaDiff->changedTables as $tableDiff) { |
|
| 46 | - $tableDiff->name = $this->connection->quoteIdentifier($tableDiff->name); |
|
| 47 | - foreach ($tableDiff->changedColumns as $column) { |
|
| 48 | - $column->oldColumnName = $this->connection->quoteIdentifier($column->oldColumnName); |
|
| 49 | - } |
|
| 50 | - } |
|
| 44 | + // identifiers need to be quoted for mysql |
|
| 45 | + foreach ($schemaDiff->changedTables as $tableDiff) { |
|
| 46 | + $tableDiff->name = $this->connection->quoteIdentifier($tableDiff->name); |
|
| 47 | + foreach ($tableDiff->changedColumns as $column) { |
|
| 48 | + $column->oldColumnName = $this->connection->quoteIdentifier($column->oldColumnName); |
|
| 49 | + } |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - return $schemaDiff; |
|
| 53 | - } |
|
| 52 | + return $schemaDiff; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | 55 | /** |
| 56 | 56 | * Speed up migration test by disabling autocommit and unique indexes check |
@@ -23,27 +23,27 @@ |
||
| 23 | 23 | namespace OC\DB; |
| 24 | 24 | |
| 25 | 25 | class OCSqlitePlatform extends \Doctrine\DBAL\Platforms\SqlitePlatform { |
| 26 | - /** |
|
| 27 | - * {@inheritDoc} |
|
| 28 | - */ |
|
| 29 | - public function getColumnDeclarationSQL($name, array $field) { |
|
| 30 | - $def = parent::getColumnDeclarationSQL($name, $field); |
|
| 31 | - if (!empty($field['autoincrement'])) { |
|
| 32 | - $def .= ' PRIMARY KEY AUTOINCREMENT'; |
|
| 33 | - } |
|
| 34 | - return $def; |
|
| 35 | - } |
|
| 26 | + /** |
|
| 27 | + * {@inheritDoc} |
|
| 28 | + */ |
|
| 29 | + public function getColumnDeclarationSQL($name, array $field) { |
|
| 30 | + $def = parent::getColumnDeclarationSQL($name, $field); |
|
| 31 | + if (!empty($field['autoincrement'])) { |
|
| 32 | + $def .= ' PRIMARY KEY AUTOINCREMENT'; |
|
| 33 | + } |
|
| 34 | + return $def; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * {@inheritDoc} |
|
| 39 | - */ |
|
| 40 | - protected function _getCreateTableSQL($name, array $columns, array $options = array()){ |
|
| 41 | - // if auto increment is set the column is already defined as primary key |
|
| 42 | - foreach ($columns as $column) { |
|
| 43 | - if (!empty($column['autoincrement'])) { |
|
| 44 | - $options['primary'] = null; |
|
| 45 | - } |
|
| 46 | - } |
|
| 47 | - return parent::_getCreateTableSQL($name, $columns, $options); |
|
| 48 | - } |
|
| 37 | + /** |
|
| 38 | + * {@inheritDoc} |
|
| 39 | + */ |
|
| 40 | + protected function _getCreateTableSQL($name, array $columns, array $options = array()){ |
|
| 41 | + // if auto increment is set the column is already defined as primary key |
|
| 42 | + foreach ($columns as $column) { |
|
| 43 | + if (!empty($column['autoincrement'])) { |
|
| 44 | + $options['primary'] = null; |
|
| 45 | + } |
|
| 46 | + } |
|
| 47 | + return parent::_getCreateTableSQL($name, $columns, $options); |
|
| 48 | + } |
|
| 49 | 49 | } |
@@ -37,7 +37,7 @@ |
||
| 37 | 37 | /** |
| 38 | 38 | * {@inheritDoc} |
| 39 | 39 | */ |
| 40 | - protected function _getCreateTableSQL($name, array $columns, array $options = array()){ |
|
| 40 | + protected function _getCreateTableSQL($name, array $columns, array $options = array()) { |
|
| 41 | 41 | // if auto increment is set the column is already defined as primary key |
| 42 | 42 | foreach ($columns as $column) { |
| 43 | 43 | if (!empty($column['autoincrement'])) { |
@@ -25,17 +25,17 @@ |
||
| 25 | 25 | use OCP\DB\QueryBuilder\IQueryFunction; |
| 26 | 26 | |
| 27 | 27 | class QueryFunction implements IQueryFunction { |
| 28 | - /** @var string */ |
|
| 29 | - protected $function; |
|
| 28 | + /** @var string */ |
|
| 29 | + protected $function; |
|
| 30 | 30 | |
| 31 | - public function __construct($function) { |
|
| 32 | - $this->function = $function; |
|
| 33 | - } |
|
| 31 | + public function __construct($function) { |
|
| 32 | + $this->function = $function; |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @return string |
|
| 37 | - */ |
|
| 38 | - public function __toString() { |
|
| 39 | - return (string) $this->function; |
|
| 40 | - } |
|
| 35 | + /** |
|
| 36 | + * @return string |
|
| 37 | + */ |
|
| 38 | + public function __toString() { |
|
| 39 | + return (string) $this->function; |
|
| 40 | + } |
|
| 41 | 41 | } |
@@ -73,9 +73,9 @@ |
||
| 73 | 73 | return $string; |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - return $alias . '.`' . $columnName . '`'; |
|
| 76 | + return $alias.'.`'.$columnName.'`'; |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - return '`' . $string . '`'; |
|
| 79 | + return '`'.$string.'`'; |
|
| 80 | 80 | } |
| 81 | 81 | } |
@@ -27,50 +27,50 @@ |
||
| 27 | 27 | use OCP\DB\QueryBuilder\IQueryFunction; |
| 28 | 28 | |
| 29 | 29 | class QuoteHelper { |
| 30 | - /** |
|
| 31 | - * @param array|string|ILiteral|IParameter|IQueryFunction $strings string, Literal or Parameter |
|
| 32 | - * @return array|string |
|
| 33 | - */ |
|
| 34 | - public function quoteColumnNames($strings) { |
|
| 35 | - if (!is_array($strings)) { |
|
| 36 | - return $this->quoteColumnName($strings); |
|
| 37 | - } |
|
| 30 | + /** |
|
| 31 | + * @param array|string|ILiteral|IParameter|IQueryFunction $strings string, Literal or Parameter |
|
| 32 | + * @return array|string |
|
| 33 | + */ |
|
| 34 | + public function quoteColumnNames($strings) { |
|
| 35 | + if (!is_array($strings)) { |
|
| 36 | + return $this->quoteColumnName($strings); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - $return = []; |
|
| 40 | - foreach ($strings as $string) { |
|
| 41 | - $return[] = $this->quoteColumnName($string); |
|
| 42 | - } |
|
| 39 | + $return = []; |
|
| 40 | + foreach ($strings as $string) { |
|
| 41 | + $return[] = $this->quoteColumnName($string); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - return $return; |
|
| 45 | - } |
|
| 44 | + return $return; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @param string|ILiteral|IParameter|IQueryFunction $string string, Literal or Parameter |
|
| 49 | - * @return string |
|
| 50 | - */ |
|
| 51 | - public function quoteColumnName($string) { |
|
| 52 | - if ($string instanceof IParameter || $string instanceof ILiteral || $string instanceof IQueryFunction) { |
|
| 53 | - return (string) $string; |
|
| 54 | - } |
|
| 47 | + /** |
|
| 48 | + * @param string|ILiteral|IParameter|IQueryFunction $string string, Literal or Parameter |
|
| 49 | + * @return string |
|
| 50 | + */ |
|
| 51 | + public function quoteColumnName($string) { |
|
| 52 | + if ($string instanceof IParameter || $string instanceof ILiteral || $string instanceof IQueryFunction) { |
|
| 53 | + return (string) $string; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - if ($string === null || $string === 'null' || $string === '*') { |
|
| 57 | - return $string; |
|
| 58 | - } |
|
| 56 | + if ($string === null || $string === 'null' || $string === '*') { |
|
| 57 | + return $string; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - if (!is_string($string)) { |
|
| 61 | - throw new \InvalidArgumentException('Only strings, Literals and Parameters are allowed'); |
|
| 62 | - } |
|
| 60 | + if (!is_string($string)) { |
|
| 61 | + throw new \InvalidArgumentException('Only strings, Literals and Parameters are allowed'); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - if (substr_count($string, '.')) { |
|
| 65 | - list($alias, $columnName) = explode('.', $string, 2); |
|
| 64 | + if (substr_count($string, '.')) { |
|
| 65 | + list($alias, $columnName) = explode('.', $string, 2); |
|
| 66 | 66 | |
| 67 | - if ($columnName === '*') { |
|
| 68 | - return $string; |
|
| 69 | - } |
|
| 67 | + if ($columnName === '*') { |
|
| 68 | + return $string; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - return $alias . '.`' . $columnName . '`'; |
|
| 72 | - } |
|
| 71 | + return $alias . '.`' . $columnName . '`'; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - return '`' . $string . '`'; |
|
| 75 | - } |
|
| 74 | + return '`' . $string . '`'; |
|
| 75 | + } |
|
| 76 | 76 | } |
@@ -25,69 +25,69 @@ |
||
| 25 | 25 | use OCP\DB\QueryBuilder\ICompositeExpression; |
| 26 | 26 | |
| 27 | 27 | class CompositeExpression implements ICompositeExpression, \Countable { |
| 28 | - /** @var \Doctrine\DBAL\Query\Expression\CompositeExpression */ |
|
| 29 | - protected $compositeExpression; |
|
| 28 | + /** @var \Doctrine\DBAL\Query\Expression\CompositeExpression */ |
|
| 29 | + protected $compositeExpression; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Constructor. |
|
| 33 | - * |
|
| 34 | - * @param \Doctrine\DBAL\Query\Expression\CompositeExpression $compositeExpression |
|
| 35 | - */ |
|
| 36 | - public function __construct(\Doctrine\DBAL\Query\Expression\CompositeExpression $compositeExpression) { |
|
| 37 | - $this->compositeExpression = $compositeExpression; |
|
| 38 | - } |
|
| 31 | + /** |
|
| 32 | + * Constructor. |
|
| 33 | + * |
|
| 34 | + * @param \Doctrine\DBAL\Query\Expression\CompositeExpression $compositeExpression |
|
| 35 | + */ |
|
| 36 | + public function __construct(\Doctrine\DBAL\Query\Expression\CompositeExpression $compositeExpression) { |
|
| 37 | + $this->compositeExpression = $compositeExpression; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Adds multiple parts to composite expression. |
|
| 42 | - * |
|
| 43 | - * @param array $parts |
|
| 44 | - * |
|
| 45 | - * @return \OCP\DB\QueryBuilder\ICompositeExpression |
|
| 46 | - */ |
|
| 47 | - public function addMultiple(array $parts = array()) { |
|
| 48 | - $this->compositeExpression->addMultiple($parts); |
|
| 40 | + /** |
|
| 41 | + * Adds multiple parts to composite expression. |
|
| 42 | + * |
|
| 43 | + * @param array $parts |
|
| 44 | + * |
|
| 45 | + * @return \OCP\DB\QueryBuilder\ICompositeExpression |
|
| 46 | + */ |
|
| 47 | + public function addMultiple(array $parts = array()) { |
|
| 48 | + $this->compositeExpression->addMultiple($parts); |
|
| 49 | 49 | |
| 50 | - return $this; |
|
| 51 | - } |
|
| 50 | + return $this; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Adds an expression to composite expression. |
|
| 55 | - * |
|
| 56 | - * @param mixed $part |
|
| 57 | - * |
|
| 58 | - * @return \OCP\DB\QueryBuilder\ICompositeExpression |
|
| 59 | - */ |
|
| 60 | - public function add($part) { |
|
| 61 | - $this->compositeExpression->add($part); |
|
| 53 | + /** |
|
| 54 | + * Adds an expression to composite expression. |
|
| 55 | + * |
|
| 56 | + * @param mixed $part |
|
| 57 | + * |
|
| 58 | + * @return \OCP\DB\QueryBuilder\ICompositeExpression |
|
| 59 | + */ |
|
| 60 | + public function add($part) { |
|
| 61 | + $this->compositeExpression->add($part); |
|
| 62 | 62 | |
| 63 | - return $this; |
|
| 64 | - } |
|
| 63 | + return $this; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * Retrieves the amount of expressions on composite expression. |
|
| 68 | - * |
|
| 69 | - * @return integer |
|
| 70 | - */ |
|
| 71 | - public function count() { |
|
| 72 | - return $this->compositeExpression->count(); |
|
| 73 | - } |
|
| 66 | + /** |
|
| 67 | + * Retrieves the amount of expressions on composite expression. |
|
| 68 | + * |
|
| 69 | + * @return integer |
|
| 70 | + */ |
|
| 71 | + public function count() { |
|
| 72 | + return $this->compositeExpression->count(); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * Returns the type of this composite expression (AND/OR). |
|
| 77 | - * |
|
| 78 | - * @return string |
|
| 79 | - */ |
|
| 80 | - public function getType() { |
|
| 81 | - return $this->compositeExpression->getType(); |
|
| 82 | - } |
|
| 75 | + /** |
|
| 76 | + * Returns the type of this composite expression (AND/OR). |
|
| 77 | + * |
|
| 78 | + * @return string |
|
| 79 | + */ |
|
| 80 | + public function getType() { |
|
| 81 | + return $this->compositeExpression->getType(); |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * Retrieves the string representation of this composite expression. |
|
| 86 | - * |
|
| 87 | - * @return string |
|
| 88 | - */ |
|
| 89 | - public function __toString() |
|
| 90 | - { |
|
| 91 | - return (string) $this->compositeExpression; |
|
| 92 | - } |
|
| 84 | + /** |
|
| 85 | + * Retrieves the string representation of this composite expression. |
|
| 86 | + * |
|
| 87 | + * @return string |
|
| 88 | + */ |
|
| 89 | + public function __toString() |
|
| 90 | + { |
|
| 91 | + return (string) $this->compositeExpression; |
|
| 92 | + } |
|
| 93 | 93 | } |
@@ -25,17 +25,17 @@ |
||
| 25 | 25 | use OCP\DB\QueryBuilder\ILiteral; |
| 26 | 26 | |
| 27 | 27 | class Literal implements ILiteral{ |
| 28 | - /** @var mixed */ |
|
| 29 | - protected $literal; |
|
| 28 | + /** @var mixed */ |
|
| 29 | + protected $literal; |
|
| 30 | 30 | |
| 31 | - public function __construct($literal) { |
|
| 32 | - $this->literal = $literal; |
|
| 33 | - } |
|
| 31 | + public function __construct($literal) { |
|
| 32 | + $this->literal = $literal; |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @return string |
|
| 37 | - */ |
|
| 38 | - public function __toString() { |
|
| 39 | - return (string) $this->literal; |
|
| 40 | - } |
|
| 35 | + /** |
|
| 36 | + * @return string |
|
| 37 | + */ |
|
| 38 | + public function __toString() { |
|
| 39 | + return (string) $this->literal; |
|
| 40 | + } |
|
| 41 | 41 | } |
@@ -24,7 +24,7 @@ |
||
| 24 | 24 | |
| 25 | 25 | use OCP\DB\QueryBuilder\ILiteral; |
| 26 | 26 | |
| 27 | -class Literal implements ILiteral{ |
|
| 27 | +class Literal implements ILiteral { |
|
| 28 | 28 | /** @var mixed */ |
| 29 | 29 | protected $literal; |
| 30 | 30 | |
@@ -25,17 +25,17 @@ |
||
| 25 | 25 | use OCP\DB\QueryBuilder\IParameter; |
| 26 | 26 | |
| 27 | 27 | class Parameter implements IParameter { |
| 28 | - /** @var mixed */ |
|
| 29 | - protected $name; |
|
| 28 | + /** @var mixed */ |
|
| 29 | + protected $name; |
|
| 30 | 30 | |
| 31 | - public function __construct($name) { |
|
| 32 | - $this->name = $name; |
|
| 33 | - } |
|
| 31 | + public function __construct($name) { |
|
| 32 | + $this->name = $name; |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @return string |
|
| 37 | - */ |
|
| 38 | - public function __toString() { |
|
| 39 | - return (string) $this->name; |
|
| 40 | - } |
|
| 35 | + /** |
|
| 36 | + * @return string |
|
| 37 | + */ |
|
| 38 | + public function __toString() { |
|
| 39 | + return (string) $this->name; |
|
| 40 | + } |
|
| 41 | 41 | } |
@@ -33,132 +33,132 @@ |
||
| 33 | 33 | |
| 34 | 34 | class OCIExpressionBuilder extends ExpressionBuilder { |
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @param mixed $column |
|
| 38 | - * @param mixed|null $type |
|
| 39 | - * @return array|IQueryFunction|string |
|
| 40 | - */ |
|
| 41 | - protected function prepareColumn($column, $type) { |
|
| 42 | - if ($type === IQueryBuilder::PARAM_STR && !is_array($column) && !($column instanceof IParameter) && !($column instanceof ILiteral)) { |
|
| 43 | - $column = $this->castColumn($column, $type); |
|
| 44 | - } else { |
|
| 45 | - $column = $this->helper->quoteColumnNames($column); |
|
| 46 | - } |
|
| 47 | - return $column; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @inheritdoc |
|
| 52 | - */ |
|
| 53 | - public function comparison($x, $operator, $y, $type = null) { |
|
| 54 | - $x = $this->prepareColumn($x, $type); |
|
| 55 | - $y = $this->prepareColumn($y, $type); |
|
| 56 | - |
|
| 57 | - return $this->expressionBuilder->comparison($x, $operator, $y); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @inheritdoc |
|
| 62 | - */ |
|
| 63 | - public function eq($x, $y, $type = null) { |
|
| 64 | - $x = $this->prepareColumn($x, $type); |
|
| 65 | - $y = $this->prepareColumn($y, $type); |
|
| 66 | - |
|
| 67 | - return $this->expressionBuilder->eq($x, $y); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @inheritdoc |
|
| 72 | - */ |
|
| 73 | - public function neq($x, $y, $type = null) { |
|
| 74 | - $x = $this->prepareColumn($x, $type); |
|
| 75 | - $y = $this->prepareColumn($y, $type); |
|
| 76 | - |
|
| 77 | - return $this->expressionBuilder->neq($x, $y); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @inheritdoc |
|
| 82 | - */ |
|
| 83 | - public function lt($x, $y, $type = null) { |
|
| 84 | - $x = $this->prepareColumn($x, $type); |
|
| 85 | - $y = $this->prepareColumn($y, $type); |
|
| 86 | - |
|
| 87 | - return $this->expressionBuilder->lt($x, $y); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * @inheritdoc |
|
| 92 | - */ |
|
| 93 | - public function lte($x, $y, $type = null) { |
|
| 94 | - $x = $this->prepareColumn($x, $type); |
|
| 95 | - $y = $this->prepareColumn($y, $type); |
|
| 96 | - |
|
| 97 | - return $this->expressionBuilder->lte($x, $y); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * @inheritdoc |
|
| 102 | - */ |
|
| 103 | - public function gt($x, $y, $type = null) { |
|
| 104 | - $x = $this->prepareColumn($x, $type); |
|
| 105 | - $y = $this->prepareColumn($y, $type); |
|
| 106 | - |
|
| 107 | - return $this->expressionBuilder->gt($x, $y); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * @inheritdoc |
|
| 112 | - */ |
|
| 113 | - public function gte($x, $y, $type = null) { |
|
| 114 | - $x = $this->prepareColumn($x, $type); |
|
| 115 | - $y = $this->prepareColumn($y, $type); |
|
| 116 | - |
|
| 117 | - return $this->expressionBuilder->gte($x, $y); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * @inheritdoc |
|
| 122 | - */ |
|
| 123 | - public function in($x, $y, $type = null) { |
|
| 124 | - $x = $this->prepareColumn($x, $type); |
|
| 125 | - $y = $this->prepareColumn($y, $type); |
|
| 126 | - |
|
| 127 | - return $this->expressionBuilder->in($x, $y); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * @inheritdoc |
|
| 132 | - */ |
|
| 133 | - public function notIn($x, $y, $type = null) { |
|
| 134 | - $x = $this->prepareColumn($x, $type); |
|
| 135 | - $y = $this->prepareColumn($y, $type); |
|
| 136 | - |
|
| 137 | - return $this->expressionBuilder->notIn($x, $y); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Returns a IQueryFunction that casts the column to the given type |
|
| 142 | - * |
|
| 143 | - * @param string $column |
|
| 144 | - * @param mixed $type One of IQueryBuilder::PARAM_* |
|
| 145 | - * @return IQueryFunction |
|
| 146 | - */ |
|
| 147 | - public function castColumn($column, $type) { |
|
| 148 | - if ($type === IQueryBuilder::PARAM_STR) { |
|
| 149 | - $column = $this->helper->quoteColumnName($column); |
|
| 150 | - return new QueryFunction('to_char(' . $column . ')'); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - return parent::castColumn($column, $type); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * @inheritdoc |
|
| 158 | - */ |
|
| 159 | - public function iLike($x, $y, $type = null) { |
|
| 160 | - $x = $this->helper->quoteColumnName($x); |
|
| 161 | - $y = $this->helper->quoteColumnName($y); |
|
| 162 | - return new QueryFunction('REGEXP_LIKE('.$x.', \'^\' || REPLACE('.$y.', \'%\', \'.*\') || \'$\', \'i\')'); |
|
| 163 | - } |
|
| 36 | + /** |
|
| 37 | + * @param mixed $column |
|
| 38 | + * @param mixed|null $type |
|
| 39 | + * @return array|IQueryFunction|string |
|
| 40 | + */ |
|
| 41 | + protected function prepareColumn($column, $type) { |
|
| 42 | + if ($type === IQueryBuilder::PARAM_STR && !is_array($column) && !($column instanceof IParameter) && !($column instanceof ILiteral)) { |
|
| 43 | + $column = $this->castColumn($column, $type); |
|
| 44 | + } else { |
|
| 45 | + $column = $this->helper->quoteColumnNames($column); |
|
| 46 | + } |
|
| 47 | + return $column; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @inheritdoc |
|
| 52 | + */ |
|
| 53 | + public function comparison($x, $operator, $y, $type = null) { |
|
| 54 | + $x = $this->prepareColumn($x, $type); |
|
| 55 | + $y = $this->prepareColumn($y, $type); |
|
| 56 | + |
|
| 57 | + return $this->expressionBuilder->comparison($x, $operator, $y); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @inheritdoc |
|
| 62 | + */ |
|
| 63 | + public function eq($x, $y, $type = null) { |
|
| 64 | + $x = $this->prepareColumn($x, $type); |
|
| 65 | + $y = $this->prepareColumn($y, $type); |
|
| 66 | + |
|
| 67 | + return $this->expressionBuilder->eq($x, $y); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @inheritdoc |
|
| 72 | + */ |
|
| 73 | + public function neq($x, $y, $type = null) { |
|
| 74 | + $x = $this->prepareColumn($x, $type); |
|
| 75 | + $y = $this->prepareColumn($y, $type); |
|
| 76 | + |
|
| 77 | + return $this->expressionBuilder->neq($x, $y); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @inheritdoc |
|
| 82 | + */ |
|
| 83 | + public function lt($x, $y, $type = null) { |
|
| 84 | + $x = $this->prepareColumn($x, $type); |
|
| 85 | + $y = $this->prepareColumn($y, $type); |
|
| 86 | + |
|
| 87 | + return $this->expressionBuilder->lt($x, $y); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * @inheritdoc |
|
| 92 | + */ |
|
| 93 | + public function lte($x, $y, $type = null) { |
|
| 94 | + $x = $this->prepareColumn($x, $type); |
|
| 95 | + $y = $this->prepareColumn($y, $type); |
|
| 96 | + |
|
| 97 | + return $this->expressionBuilder->lte($x, $y); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * @inheritdoc |
|
| 102 | + */ |
|
| 103 | + public function gt($x, $y, $type = null) { |
|
| 104 | + $x = $this->prepareColumn($x, $type); |
|
| 105 | + $y = $this->prepareColumn($y, $type); |
|
| 106 | + |
|
| 107 | + return $this->expressionBuilder->gt($x, $y); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * @inheritdoc |
|
| 112 | + */ |
|
| 113 | + public function gte($x, $y, $type = null) { |
|
| 114 | + $x = $this->prepareColumn($x, $type); |
|
| 115 | + $y = $this->prepareColumn($y, $type); |
|
| 116 | + |
|
| 117 | + return $this->expressionBuilder->gte($x, $y); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * @inheritdoc |
|
| 122 | + */ |
|
| 123 | + public function in($x, $y, $type = null) { |
|
| 124 | + $x = $this->prepareColumn($x, $type); |
|
| 125 | + $y = $this->prepareColumn($y, $type); |
|
| 126 | + |
|
| 127 | + return $this->expressionBuilder->in($x, $y); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * @inheritdoc |
|
| 132 | + */ |
|
| 133 | + public function notIn($x, $y, $type = null) { |
|
| 134 | + $x = $this->prepareColumn($x, $type); |
|
| 135 | + $y = $this->prepareColumn($y, $type); |
|
| 136 | + |
|
| 137 | + return $this->expressionBuilder->notIn($x, $y); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Returns a IQueryFunction that casts the column to the given type |
|
| 142 | + * |
|
| 143 | + * @param string $column |
|
| 144 | + * @param mixed $type One of IQueryBuilder::PARAM_* |
|
| 145 | + * @return IQueryFunction |
|
| 146 | + */ |
|
| 147 | + public function castColumn($column, $type) { |
|
| 148 | + if ($type === IQueryBuilder::PARAM_STR) { |
|
| 149 | + $column = $this->helper->quoteColumnName($column); |
|
| 150 | + return new QueryFunction('to_char(' . $column . ')'); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + return parent::castColumn($column, $type); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * @inheritdoc |
|
| 158 | + */ |
|
| 159 | + public function iLike($x, $y, $type = null) { |
|
| 160 | + $x = $this->helper->quoteColumnName($x); |
|
| 161 | + $y = $this->helper->quoteColumnName($y); |
|
| 162 | + return new QueryFunction('REGEXP_LIKE('.$x.', \'^\' || REPLACE('.$y.', \'%\', \'.*\') || \'$\', \'i\')'); |
|
| 163 | + } |
|
| 164 | 164 | } |
@@ -147,7 +147,7 @@ |
||
| 147 | 147 | public function castColumn($column, $type) { |
| 148 | 148 | if ($type === IQueryBuilder::PARAM_STR) { |
| 149 | 149 | $column = $this->helper->quoteColumnName($column); |
| 150 | - return new QueryFunction('to_char(' . $column . ')'); |
|
| 150 | + return new QueryFunction('to_char('.$column.')'); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | return parent::castColumn($column, $type); |