Skip to content
Merged
Changes from 1 commit
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
Next Next commit
Add a unit test to check for casting a IQueryFunction
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen authored and backportbot[bot] committed Sep 24, 2021
commit e4817972d817b75dc781b0a175e77c86395ba762
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();
}
}