Skip to content

Commit

Permalink
fixup! Type the experssionbuilders
Browse files Browse the repository at this point in the history
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
  • Loading branch information
rullzer committed Mar 1, 2021
1 parent 0013bd5 commit de56159
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -427,11 +427,11 @@ public function literal($input, $type = null): ILiteral {
*
* @param string $column
* @param mixed $type One of IQueryBuilder::PARAM_*
* @return string
* @return IQueryFunction
*/
public function castColumn(string $column, $type): string {
return (string)(new QueryFunction(
public function castColumn(string $column, $type): IQueryFunction {
return new QueryFunction(
$this->helper->quoteColumnName($column)
));
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,16 @@ public function nonEmptyString(string $x): string {
*
* @param string $column
* @param mixed $type One of IQueryBuilder::PARAM_*
* @return string
* @return IQueryFunction
*/
public function castColumn(string $column, $type): string {
public function castColumn(string $column, $type): IQueryFunction {
if ($type === IQueryBuilder::PARAM_STR) {
$column = $this->helper->quoteColumnName($column);
return (string)(new QueryFunction('to_char(' . $column . ')'));
return new QueryFunction('to_char(' . $column . ')');
}
if ($type === IQueryBuilder::PARAM_INT) {
$column = $this->helper->quoteColumnName($column);
return (string)(new QueryFunction('to_number(to_char(' . $column . '))'));
return new QueryFunction('to_number(to_char(' . $column . '))');
}

return parent::castColumn($column, $type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

use OC\DB\QueryBuilder\QueryFunction;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\DB\QueryBuilder\IQueryFunction;

class PgSqlExpressionBuilder extends ExpressionBuilder {

Expand All @@ -34,14 +35,14 @@ class PgSqlExpressionBuilder extends ExpressionBuilder {
*
* @param string $column
* @param mixed $type One of IQueryBuilder::PARAM_*
* @return string
* @return IQueryFunction
*/
public function castColumn($column, $type): string {
public function castColumn($column, $type): IQueryFunction {
switch ($type) {
case IQueryBuilder::PARAM_INT:
return (string)(new QueryFunction('CAST(' . $this->helper->quoteColumnName($column) . ' AS INT)'));
return new QueryFunction('CAST(' . $this->helper->quoteColumnName($column) . ' AS INT)');
case IQueryBuilder::PARAM_STR:
return (string)(new QueryFunction('CAST(' . $this->helper->quoteColumnName($column) . ' AS TEXT)'));
return new QueryFunction('CAST(' . $this->helper->quoteColumnName($column) . ' AS TEXT)');
default:
return parent::castColumn($column, $type);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/public/DB/QueryBuilder/IExpressionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -434,11 +434,11 @@ public function literal($input, $type = null): ILiteral;
*
* @param string $column
* @param mixed $type One of IQueryBuilder::PARAM_*
* @return string
* @return IQueryFunction
* @since 9.0.0
*
* @psalm-taint-sink sql $column
* @psalm-taint-sink sql $type
*/
public function castColumn(string $column, $type): string;
public function castColumn(string $column, $type): IQueryFunction;
}

0 comments on commit de56159

Please sign in to comment.