aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/DB/QueryBuilder/ExpressionBuilder/MySqlExpressionBuilder.php
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2022-01-03 12:06:05 +0100
committerJulius Härtl <jus@bitgrid.net>2022-01-04 16:53:00 +0100
commita169ca306e28ce52b93209e01e9acf29073c1ebc (patch)
treeac68df84e5408a1dab823694600f785dbb108b8b /lib/private/DB/QueryBuilder/ExpressionBuilder/MySqlExpressionBuilder.php
parent130d3bd8d33cef1bc61979157dff063427bc8c5b (diff)
downloadnextcloud-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/MySqlExpressionBuilder.php')
-rw-r--r--lib/private/DB/QueryBuilder/ExpressionBuilder/MySqlExpressionBuilder.php19
1 files changed, 19 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);
+ }
+ }
}