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

Fixes #5642 #5643

Closed
Closed

Conversation

samsonasik
Copy link
Contributor

Fixes #5642

@macnibblet
Copy link
Contributor

Adding a group annotation on the test with the issue id is never a bad idea

@samsonasik
Copy link
Contributor Author

@macnibblet a group annotation added ;)

@macnibblet
Copy link
Contributor

i think the annotation must be added to the method, but i could be wrong.

@samsonasik
Copy link
Contributor Author

@macnibblet I'm not sure if it placed on the method because so many tests on one method. should I reset last commit ( a group annotation addition ) ?

@YonmaN
Copy link

YonmaN commented Dec 25, 2013

Looks spot-on, many thanks

if ($this->offset === null) {
return null;
}
$this->limit = "18446744073709551615"; //maximum of unsigned BIGINT
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ralphschindler about platform specific, should it changed by :

if ($platform instanceof \Zend\Db\Sql\Platform\Mysql && $this->offset !== null) {
    $this->limit =  "18446744073709551615"; //maximum of unsigned BIGINT
}
return null;

is it better ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for MySql this will be overvritten by Zend\Db\Sql\Platform\Mysql\SelectDecorator
as i know - postgresql allow use offset withot limit
as i understand - this is MySql issue - and should be fixed in Zend\Db\Sql\Platform\Mysql\SelectDecorator::processLimit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@turrsis I think no, it won't be overwritten, for example :

$table = 'users';
$sampleTable = new TableGateway($table, $adapter, null,new HydratingResultSet());
$select = new Select($table);
$select->offset(10);
echo $select->getSqlString(new \Zend\Db\Adapter\Platform\Mysql);

it will get

SELECT `users`.* FROM `users` LIMIT 18446744073709551615 OFFSET 10

what case it will be overwritten with Zend\Db\Sql\Platform\Mysql\SelectDecorator ? or should I add the condition at SelectDecorator too ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

        $mockDriver = $this->getMock('Zend\Db\Adapter\Driver\DriverInterface');
        $mockConnection = $this->getMock('Zend\Db\Adapter\Driver\ConnectionInterface');
        $mockDriver->expects($this->any())->method('checkEnvironment')->will($this->returnValue(true));
        $mockDriver->expects($this->any())->method('getConnection')->will($this->returnValue($mockConnection));
        $mockPlatform = $this->getMock('Zend\Db\Adapter\Platform\PlatformInterface');
        $mockStatement = $this->getMock('Zend\Db\Adapter\Driver\StatementInterface');
        $mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue($mockStatement));

        $adapter = new \Zend\Db\Adapter\Adapter($mockDriver, $mockPlatform);

        $sql = new \Zend\Db\Sql\Sql($adapter);
        $sql->getSqlPlatform()->setTypeDecorator('Zend\Db\Sql\Select', new \Zend\Db\Sql\Platform\Mysql\SelectDecorator);
        $query = $sql->getSqlStringForSqlObject($select46, new TrustingSql92Platform());

this code (for unitTests) use Zend\Db\Sql\Platform\Mysql\SelectDecorator::processLimit

if you code not use decorators - this is the bug, see this #5306 - this fix for decorators, subqueries, etc.

@ralphschindler are you planing to merge #5306 ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if Decorator exist - you should use it and only it, otherwise it is a bug

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you plan to move this logic to the Mysql Select decorator?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the solution is to copy instead of move, because we can use new Select instead as I described above, is it ok ? @ralphschindler

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, paging in database adapters, across the board, is already a non-standard thing. Seeing as though this is strongly a mysqlism, I think it makes the most sense to do this in the MySQL decorator. For it to be in Select, there would have to be a VERY strong argument that this particular workflow applies to most of the other popular DB platforms: postgres, sqlite, SQL Server, Db2 and Oracle.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[update] I will try, but personally I don't agree to cast $limit with (int) because on some cases like this , we need big limit.... ( 18446744073709551615 ) which is not (int)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ralphschindler I have tried to move it to selectdecorator, and update SelectDecoratorTest.php, but it comes with error :

Attempting to quote a value in Zend\Db\Adapter\Platform\Mysql without extension/driver support can introduce security vulnerabilities in a production environment.

because "18446744073709551615" is quoted. because it using MysqlPlatform instead of TrustingSql92Platform, any idea ?

@weierophinney
Copy link
Member

@ralphschindler Please set a milestone.

@ralphschindler
Copy link
Member

@samsonasik please see #5940

@samsonasik samsonasik closed this Mar 10, 2014
weierophinney added a commit that referenced this pull request Mar 10, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Offset may be specified without a limit. Causes syntax error in mysql, sqlite and maybe others
6 participants