Explicitly cast char in the query builder

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2022-01-03 12:06:05 +01:00
parent 130d3bd8d3
commit a169ca306e
No known key found for this signature in database
GPG key ID: 4C614C6ED2CDE6DF
4 changed files with 22 additions and 0 deletions

View file

@ -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);
}
}
}

View file

@ -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 {

View file

@ -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 {

View file

@ -433,6 +433,7 @@ interface IExpressionBuilder {
*
* @param string|IQueryFunction $column
* @param mixed $type One of IQueryBuilder::PARAM_*
* @psalm-param IQueryBuilder::PARAM_* $type
* @return IQueryFunction
* @since 9.0.0
*