Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -425,11 +425,11 @@ public function literal($input, $type = null): ILiteral {
/**
* Returns a IQueryFunction that casts the column to the given type
*
* @param string $column
* @param string|IQueryFunction $column
* @param mixed $type One of IQueryBuilder::PARAM_*
* @return IQueryFunction
*/
public function castColumn(string $column, $type): IQueryFunction {
public function castColumn($column, $type): IQueryFunction {
return new QueryFunction(
$this->helper->quoteColumnName($column)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@ public function nonEmptyString($x): string {
/**
* Returns a IQueryFunction that casts the column to the given type
*
* @param string $column
* @param string|IQueryFunction $column
* @param mixed $type One of IQueryBuilder::PARAM_*
* @return IQueryFunction
*/
public function castColumn(string $column, $type): IQueryFunction {
public function castColumn($column, $type): IQueryFunction {
if ($type === IQueryBuilder::PARAM_STR) {
$column = $this->helper->quoteColumnName($column);
return new QueryFunction('to_char(' . $column . ')');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class PgSqlExpressionBuilder extends ExpressionBuilder {
/**
* Returns a IQueryFunction that casts the column to the given type
*
* @param string $column
* @param string|IQueryFunction $column
* @param mixed $type One of IQueryBuilder::PARAM_*
* @return IQueryFunction
*/
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 @@ -431,13 +431,13 @@ public function literal($input, $type = null): ILiteral;
/**
* Returns a IQueryFunction that casts the column to the given type
*
* @param string $column
* @param string|IQueryFunction $column
* @param mixed $type One of IQueryBuilder::PARAM_*
* @return IQueryFunction
* @since 9.0.0
*
* @psalm-taint-sink sql $column
* @psalm-taint-sink sql $type
*/
public function castColumn(string $column, $type): IQueryFunction;
public function castColumn($column, $type): IQueryFunction;
}
34 changes: 34 additions & 0 deletions tests/lib/DB/QueryBuilder/ExpressionBuilderDBTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
namespace Test\DB\QueryBuilder;

use OC\DB\QueryBuilder\Literal;
use OCP\DB\QueryBuilder\IQueryBuilder;
use Test\TestCase;

/**
Expand Down Expand Up @@ -109,4 +110,37 @@ public function testILike($param1, $param2, $match) {
$result->closeCursor();
$this->assertEquals($match, $column);
}

public function testCastColumn(): void {
$appId = $this->getUniqueID('testing');
$this->createConfig($appId, '1', '4');

$query = $this->connection->getQueryBuilder();
$query->update('appconfig')
->set('configvalue',
$query->expr()->castColumn(
$query->createFunction(
'(' . $query->expr()->castColumn('configvalue', IQueryBuilder::PARAM_INT)
. ' + 1)'
)
, IQueryBuilder::PARAM_STR
)
)
->where($query->expr()->eq('appid', $query->createNamedParameter($appId)))
->andWhere($query->expr()->eq('configkey', $query->createNamedParameter('1')));

$result = $query->executeStatement();
$this->assertEquals(1, $result);
}

protected function createConfig($appId, $key, $value) {
$query = $this->connection->getQueryBuilder();
$query->insert('appconfig')
->values([
'appid' => $query->createNamedParameter($appId),
'configkey' => $query->createNamedParameter((string) $key),
'configvalue' => $query->createNamedParameter((string) $value),
])
->execute();
}
}