ZF2-503: getSqlStringForSqlObject() returns an invalid SQL statement with LIMIT and OFFSET clauses


The getSqlStringForSqlObject() function returns a SQL statement where the integers for the LIMIT and OFFSET clauses are quoted, which is not correct and MySQL returns an exception.

In the model/mapper

$adapter = $this->getDbAdapter();
$sql = new Sql($adapter);
$select = $sql->select();

$selectString = $sql->getSqlStringForSqlObject($select);

$selectString returns

SELECT `rules_questions`.* FROM `rules_questions` LIMIT '10'

That seems to be an incorrect SQL statement, there should be no quotations around the LIMIT integer

SELECT `rules_questions`.* FROM `rules_questions` LIMIT 10

So when executing the query

$results = $this->getDbAdapter()->query($selectString, $adapter::QUERY_MODE_EXECUTE);

MySQL returns this exception:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the right syntax to use
near ''10'' at line 1

The same thing happens when adding an OFFSET clause, the integer is incorrectly quoted.


i think ->execute() func can solve this

$statement = $sql->prepareStatementForSqlObject($select); $result = $statement->execute();

This issue has been closed on Jira and moved to GitHub for issue tracking. To continue following the resolution of this issues, please visit: