Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Hotfix #355: Named params in subquery - limit and offset #357

Merged
merged 1 commit into from
Feb 20, 2019
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
4 changes: 2 additions & 2 deletions src/Sql/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ protected function processLimit(
if ($parameterContainer) {
$paramPrefix = $this->processInfo['paramPrefix'];
$parameterContainer->offsetSet($paramPrefix . 'limit', $this->limit, ParameterContainer::TYPE_INTEGER);
return [$driver->formatParameterName('limit')];
return [$driver->formatParameterName($paramPrefix . 'limit')];
}
return [$platform->quoteValue($this->limit)];
}
Expand All @@ -732,7 +732,7 @@ protected function processOffset(
if ($parameterContainer) {
$paramPrefix = $this->processInfo['paramPrefix'];
$parameterContainer->offsetSet($paramPrefix . 'offset', $this->offset, ParameterContainer::TYPE_INTEGER);
return [$driver->formatParameterName('offset')];
return [$driver->formatParameterName($paramPrefix . 'offset')];
}

return [$platform->quoteValue($this->offset)];
Expand Down
18 changes: 18 additions & 0 deletions test/unit/Sql/SelectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Zend\Db\Sql\Expression;
use Zend\Db\Sql\Having;
use Zend\Db\Sql\Predicate;
use Zend\Db\Sql\Predicate\In;
use Zend\Db\Sql\Select;
use Zend\Db\Sql\TableIdentifier;
use Zend\Db\Sql\Where;
Expand Down Expand Up @@ -1404,6 +1405,22 @@ public function providerData()
]],
];

$subSelect53 = new Select;
$subSelect53->from('bar')->columns(['id'])->limit(10)->offset(9);
$select53 = new Select;
$select53->from('foo')->where(new In('bar_id', $subSelect53))->limit(11)->offset(12);
$params53 = ['limit' => 11, 'offset' => 12, 'subselect1limit' => 10, 'subselect1offset' => 9];
// @codingStandardsIgnoreStart
$sqlPrep53 = 'SELECT "foo".* FROM "foo" WHERE "bar_id" IN (SELECT "bar"."id" AS "id" FROM "bar" LIMIT :subselect1limit OFFSET :subselect1offset) LIMIT :limit OFFSET :offset';
$sqlStr53 = 'SELECT "foo".* FROM "foo" WHERE "bar_id" IN (SELECT "bar"."id" AS "id" FROM "bar" LIMIT \'10\' OFFSET \'9\') LIMIT \'11\' OFFSET \'12\'';
// @codingStandardsIgnoreEnd
$internalTests53 = [
'processSelect' => [[['"foo".*']], '"foo"'],
'processWhere' => ['"bar_id" IN (SELECT "bar"."id" AS "id" FROM "bar" LIMIT ? OFFSET ?)'],
'processLimit' => ['?'],
'processOffset' => ['?'],
];

/**
* $select = the select object
* $sqlPrep = the sql as a result of preparation
Expand Down Expand Up @@ -1467,6 +1484,7 @@ public function providerData()
[$select50, $sqlPrep50, [], $sqlStr50, $internalTests50],
[$select51, $sqlPrep51, [], $sqlStr51, $internalTests51],
[$select52, $sqlPrep52, [], $sqlStr52, $internalTests52],
[$select53, $sqlPrep53, $params53, $sqlStr53, $internalTests53, true],
];
}
}