Commit 9fe34ef9 authored by Jörn Friedrich Dreyer's avatar Jörn Friedrich Dreyer Committed by Thomas Müller
Browse files

use query builder (#26425)

* use query builder

* test no longer needs to mock the dbtype

* close cursor early
parent 00968e55
......@@ -28,6 +28,7 @@
*/
namespace OC;
use Doctrine\DBAL\Platforms\OraclePlatform;
use OC\Cache\CappedMemoryCache;
use OCP\IDBConnection;
use OCP\PreConditionNotMetException;
......@@ -410,23 +411,38 @@ class AllConfig implements \OCP\IConfig {
// TODO - FIXME
$this->fixDIInit();
$sql = 'SELECT `userid` FROM `*PREFIX*preferences` ' .
'WHERE `appid` = ? AND `configkey` = ? ';
if($this->getSystemValue('dbtype', 'sqlite') === 'oci') {
//oracle hack: need to explicitly cast CLOB to CHAR for comparison
$sql .= 'AND to_char(`configvalue`) = ?';
$queryBuilder = $this->connection->getQueryBuilder();
$queryBuilder->select('userid')
->from('preferences')
->where($queryBuilder->expr()->eq(
'appid', $queryBuilder->createNamedParameter($appName))
)
->andWhere($queryBuilder->expr()->eq(
'configkey', $queryBuilder->createNamedParameter($key))
)
->andWhere($queryBuilder->expr()->isNotNull('configvalue'));
if ($this->connection->getDatabasePlatform() instanceof OraclePlatform) {
//oracle can only compare the first 4000 bytes of a CLOB column
$queryBuilder->andWhere($queryBuilder->expr()->eq(
$queryBuilder->createFunction('dbms_lob.substr(`configvalue`, 4000, 1)'),
$queryBuilder->createNamedParameter($value))
);
} else {
$sql .= 'AND `configvalue` = ?';
$queryBuilder->andWhere($queryBuilder->expr()->eq(
'configvalue', $queryBuilder->createNamedParameter($value))
);
}
$result = $this->connection->executeQuery($sql, [$appName, $key, $value]);
$query = $queryBuilder->execute();
$userIDs = [];
while ($row = $result->fetch()) {
while ($row = $query->fetch()) {
$userIDs[] = $row['userid'];
}
$query->closeCursor();
return $userIDs;
}
}
......@@ -404,11 +404,6 @@ class AllConfigTest extends \Test\TestCase {
$systemConfig = $this->getMockBuilder('\OC\SystemConfig')
->disableOriginalConstructor()
->getMock();
$systemConfig->expects($this->once())
->method('getValue')
->with($this->equalTo('dbtype'),
$this->equalTo('sqlite'))
->will($this->returnValue(\OC::$server->getConfig()->getSystemValue('dbtype', 'sqlite')));
$config = $this->getConfig($systemConfig);
// preparation - add something to the database
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment