diff options
author | Julius Härtl <jus@bitgrid.net> | 2022-01-03 12:06:05 +0100 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2022-01-04 16:53:00 +0100 |
commit | a169ca306e28ce52b93209e01e9acf29073c1ebc (patch) | |
tree | ac68df84e5408a1dab823694600f785dbb108b8b /lib/private/DB/QueryBuilder/ExpressionBuilder | |
parent | 130d3bd8d33cef1bc61979157dff063427bc8c5b (diff) | |
download | nextcloud-server-a169ca306e28ce52b93209e01e9acf29073c1ebc.tar.gz nextcloud-server-a169ca306e28ce52b93209e01e9acf29073c1ebc.zip |
Explicitly cast char in the query builder
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'lib/private/DB/QueryBuilder/ExpressionBuilder')
3 files changed, 21 insertions, 0 deletions
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 { |