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

Few limit issue #262

Open
autowp opened this issue Aug 1, 2017 · 1 comment
Open

Few limit issue #262

autowp opened this issue Aug 1, 2017 · 1 comment

Comments

@autowp
Copy link
Contributor

autowp commented Aug 1, 2017

Briefly: SQL queries fails when few limit statements is used (sub-select, maybe unions)

Context: PDO Mysql driver

Expected SQL (simplified):

SELECT (SELECT column FROM foo LIMIT 1) AS column 
FROM bar 
LIMIT 99

PHP code to build them

$subSelect = new Select('foo');
$subSelect->columns(['column'])->limit(1);

$select = new Select('bar');
$select->columns(['column' => $subSelect])->limit(99);

$statement = $sql->prepareStatementForSqlObject($select);
print_r($statement);

Output (simplified)

[sql] => SELECT (SELECT `foo`.`column` AS `column` FROM `foo` LIMIT :limit) AS `column` FROM `bar` LIMIT :limit
[parameterContainer] => Zend\Db\Adapter\ParameterContainer Object
        (
            [data] => Array
                (
                    [limit] => 99
                )

            [positions] => Array
                (
                    [0] => limit
                )
        )

Same value sent to mysql for both limit statements:

SELECT (SELECT column FROM foo LIMIT 99) AS column 
FROM bar 
LIMIT 99

Test: autowp@95efe84

The only workaround is to create sub-select with SQL-string

@michalbundyra
Copy link
Member

This repository has been closed and moved to laminas/laminas-db; a new issue has been opened at laminas/laminas-db#68.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants