diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2022-01-20 14:32:56 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-20 14:32:56 +0100 |
commit | de9fe8fcc101106f1ac3d6113616c10f89c1601e (patch) | |
tree | 3c41d99e059ce332f58120d0323f151d682e991e /lib/private/DB/QueryBuilder | |
parent | a9b098eed59f594f9c6531c172617cd740de167a (diff) | |
parent | eebed2c43440c2774ea199fec17ee6667fd2455e (diff) | |
download | nextcloud-server-de9fe8fcc101106f1ac3d6113616c10f89c1601e.tar.gz nextcloud-server-de9fe8fcc101106f1ac3d6113616c10f89c1601e.zip |
Merge pull request #30471 from nextcloud/enh/cast-char-mysql
Explicitly cast char in the query builder
Diffstat (limited to 'lib/private/DB/QueryBuilder')
4 files changed, 22 insertions, 0 deletions
diff --git a/lib/private/DB/QueryBuilder/ExpressionBuilder/ExpressionBuilder.php b/lib/private/DB/QueryBuilder/ExpressionBuilder/ExpressionBuilder.php index 77a4a02128a..ae4f19f5d18 100644 --- a/lib/private/DB/QueryBuilder/ExpressionBuilder/ExpressionBuilder.php +++ b/lib/private/DB/QueryBuilder/ExpressionBuilder/ExpressionBuilder.php @@ -427,6 +427,7 @@ class ExpressionBuilder implements IExpressionBuilder { * * @param string|IQueryFunction $column * @param mixed $type One of IQueryBuilder::PARAM_* + * @psalm-param IQueryBuilder::PARAM_* $type * @return IQueryFunction */ public function castColumn($column, $type): IQueryFunction { diff --git a/lib/private/DB/QueryBuilder/ExpressionBuilder/MySqlExpressionBuilder.php b/lib/private/DB/QueryBuilder/ExpressionBuilder/MySqlExpressionBuilder.php index e917ad3ad3a..3bb54d4b26e 100644 --- a/lib/private/DB/QueryBuilder/ExpressionBuilder/MySqlExpressionBuilder.php +++ b/lib/private/DB/QueryBuilder/ExpressionBuilder/MySqlExpressionBuilder.php @@ -26,7 +26,9 @@ namespace OC\DB\QueryBuilder\ExpressionBuilder; use OC\DB\ConnectionAdapter; +use OC\DB\QueryBuilder\QueryFunction; use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\DB\QueryBuilder\IQueryFunction; class MySqlExpressionBuilder extends ExpressionBuilder { @@ -52,4 +54,21 @@ class MySqlExpressionBuilder extends ExpressionBuilder { $y = $this->helper->quoteColumnName($y); return $this->expressionBuilder->comparison($x, ' COLLATE ' . $this->collation . ' LIKE', $y); } + + /** + * Returns a IQueryFunction that casts the column to the given type + * + * @param string|IQueryFunction $column + * @param mixed $type One of IQueryBuilder::PARAM_* + * @psalm-param IQueryBuilder::PARAM_* $type + * @return IQueryFunction + */ + public function castColumn($column, $type): IQueryFunction { + switch ($type) { + case IQueryBuilder::PARAM_STR: + return new QueryFunction('CAST(' . $this->helper->quoteColumnName($column) . ' AS CHAR)'); + default: + return parent::castColumn($column, $type); + } + } } diff --git a/lib/private/DB/QueryBuilder/ExpressionBuilder/OCIExpressionBuilder.php b/lib/private/DB/QueryBuilder/ExpressionBuilder/OCIExpressionBuilder.php index 4cea234779e..f9b58d7d8ed 100644 --- a/lib/private/DB/QueryBuilder/ExpressionBuilder/OCIExpressionBuilder.php +++ b/lib/private/DB/QueryBuilder/ExpressionBuilder/OCIExpressionBuilder.php @@ -163,6 +163,7 @@ class OCIExpressionBuilder extends ExpressionBuilder { * * @param string|IQueryFunction $column * @param mixed $type One of IQueryBuilder::PARAM_* + * @psalm-param IQueryBuilder::PARAM_* $type * @return IQueryFunction */ public function castColumn($column, $type): IQueryFunction { diff --git a/lib/private/DB/QueryBuilder/ExpressionBuilder/PgSqlExpressionBuilder.php b/lib/private/DB/QueryBuilder/ExpressionBuilder/PgSqlExpressionBuilder.php index 4e0de5ef42b..0fba5363a28 100644 --- a/lib/private/DB/QueryBuilder/ExpressionBuilder/PgSqlExpressionBuilder.php +++ b/lib/private/DB/QueryBuilder/ExpressionBuilder/PgSqlExpressionBuilder.php @@ -35,6 +35,7 @@ class PgSqlExpressionBuilder extends ExpressionBuilder { * * @param string|IQueryFunction $column * @param mixed $type One of IQueryBuilder::PARAM_* + * @psalm-param IQueryBuilder::PARAM_* $type * @return IQueryFunction */ public function castColumn($column, $type): IQueryFunction { |