From afe5b6dd8aa9a0eb761434231327e8daecb1d79e Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Tue, 11 Jan 2022 12:20:13 -0300 Subject: [PATCH] Prevent query error when use subquery Signed-off-by: Vitor Mattos --- build/psalm-baseline.xml | 4 ---- lib/private/DB/QueryBuilder/QueryBuilder.php | 4 ++-- lib/public/DB/QueryBuilder/IQueryBuilder.php | 4 ++-- tests/lib/DB/QueryBuilder/QueryBuilderTest.php | 9 ++++++++- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/build/psalm-baseline.xml b/build/psalm-baseline.xml index 485a3fe706c..f02a11ec7ea 100644 --- a/build/psalm-baseline.xml +++ b/build/psalm-baseline.xml @@ -4387,10 +4387,6 @@ - - $query->createFunction('(' . $subQuery->getSQL() . ')') - $subQuery->createFunction('(' . $subSubQuery->getSQL() . ')') - $this->userToNotify diff --git a/lib/private/DB/QueryBuilder/QueryBuilder.php b/lib/private/DB/QueryBuilder/QueryBuilder.php index a362ff8016e..de326a2a317 100644 --- a/lib/private/DB/QueryBuilder/QueryBuilder.php +++ b/lib/private/DB/QueryBuilder/QueryBuilder.php @@ -694,7 +694,7 @@ class QueryBuilder implements IQueryBuilder { * ->from('users', 'u') * * - * @param string $from The table. + * @param string|IQueryFunction $from The table. * @param string|null $alias The alias of the table. * * @return $this This QueryBuilder instance. @@ -1303,7 +1303,7 @@ class QueryBuilder implements IQueryBuilder { /** * Returns the table name quoted and with database prefix as needed by the implementation * - * @param string $table + * @param string|IQueryFunction $table * @return string */ public function getTableName($table) { diff --git a/lib/public/DB/QueryBuilder/IQueryBuilder.php b/lib/public/DB/QueryBuilder/IQueryBuilder.php index 7829696970c..669003246d9 100644 --- a/lib/public/DB/QueryBuilder/IQueryBuilder.php +++ b/lib/public/DB/QueryBuilder/IQueryBuilder.php @@ -470,7 +470,7 @@ interface IQueryBuilder { * ->from('users', 'u') * * - * @param string $from The table. + * @param string|IQueryFunction $from The table. * @param string|null $alias The alias of the table. * * @return $this This QueryBuilder instance. @@ -994,7 +994,7 @@ interface IQueryBuilder { /** * Returns the table name quoted and with database prefix as needed by the implementation * - * @param string $table + * @param string|IQueryFunction $table * @return string * @since 9.0.0 */ diff --git a/tests/lib/DB/QueryBuilder/QueryBuilderTest.php b/tests/lib/DB/QueryBuilder/QueryBuilderTest.php index 19278504707..d94fda4852c 100644 --- a/tests/lib/DB/QueryBuilder/QueryBuilderTest.php +++ b/tests/lib/DB/QueryBuilder/QueryBuilderTest.php @@ -1204,6 +1204,9 @@ class QueryBuilderTest extends \Test\TestCase { } public function dataGetTableName() { + $config = $this->createMock(SystemConfig::class); + $logger = $this->createMock(ILogger::class); + $qb = new QueryBuilder(\OC::$server->getDatabaseConnection(), $config, $logger); return [ ['*PREFIX*table', null, '`*PREFIX*table`'], ['*PREFIX*table', true, '`*PREFIX*table`'], @@ -1212,13 +1215,17 @@ class QueryBuilderTest extends \Test\TestCase { ['table', null, '`*PREFIX*table`'], ['table', true, '`*PREFIX*table`'], ['table', false, '`table`'], + + [$qb->createFunction('(' . $qb->select('*')->from('table')->getSQL() . ')'), null, '(SELECT * FROM `*PREFIX*table`)'], + [$qb->createFunction('(' . $qb->select('*')->from('table')->getSQL() . ')'), true, '(SELECT * FROM `*PREFIX*table`)'], + [$qb->createFunction('(' . $qb->select('*')->from('table')->getSQL() . ')'), false, '(SELECT * FROM `*PREFIX*table`)'], ]; } /** * @dataProvider dataGetTableName * - * @param string $tableName + * @param string|IQueryFunction $tableName * @param bool $automatic * @param string $expected */