Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix OFFSET without LIMIT cause MySQL syntax error. #261

Closed
wants to merge 7 commits into from

6 participants

@Everus

MySQL OFFSET require LIMIT.
So fixed it to use the biggest limit possible as it recommended in http://dev.mysql.com/doc/refman/5.0/en/select.html#id4651990

@doctrinebot
Collaborator

Hello,

thank you for positing this Pull Request. I have automatically opened an issue on our Jira Bug Tracker for you with the details of this Pull-Request. See the Link:

http://doctrine-project.org/jira/browse/DBAL-431

@Ocramius
Owner

@Everus what's the failing test case for this one?

@stof

This is wrong. It does not add the offset anymore when the limit is not null

@Everus

I can't see what wrong in it, maybe you can point me in right direction.

@stof

hmm, sorry.

However, as this fix is only for MySQL, I think it should be done in the MySQLPlatform only

@beberlei
Owner

Fixed in 3f220a1

@beberlei beberlei closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 1, 2013
  1. @Everus

    Updated doModifyLimitQuery in SQLServerPlatform to handle subqueries …

    Norbert Orzechowicz authored Everus committed
    …with Ordering
  2. @Everus

    Updated regular expressions in doModifyLimitQuery

    Norbert Orzechowicz authored Everus committed
  3. @pkruithof @Everus

    Set guid type to require SQL comment hint

    pkruithof authored Everus committed
  4. @pkruithof @Everus
  5. @Everus

    Fixed wrong class names in SQLAzureFederationsSynchronizer

    Benjamin Morel authored Everus committed
  6. @Everus
  7. @Everus
This page is out of date. Refresh to see the latest.
View
19 lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
@@ -36,6 +36,25 @@
*/
class MySqlPlatform extends AbstractPlatform
{
+
+ /**
+ * Adds MySQL-specific LIMIT clause to the query
+ * 18446744073709551615 is 2^64-1 maximum of unsigned BIGINT the biggest limit possible
+ */
+ protected function doModifyLimitQuery($query, $limit, $offset)
+ {
+ if ($limit !== null) {
+ $query .= ' LIMIT ' . $limit;
+ if ($offset !== null) {
+ $query .= ' OFFSET ' . $offset;
+ }
+ }elseif ($offset !== null) {
+ $query .= ' LIMIT 18446744073709551615 OFFSET ' . $offset;
+ }
+
+ return $query;
+ }
+
/**
* {@inheritDoc}
*/
View
6 tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php
@@ -16,6 +16,12 @@ public function createPlatform()
return new MysqlPlatform;
}
+ public function testdoModifyLimitQuery()
+ {
+ $sql=$this->_platform->doModifyLimitQuery('SELECT n FROM Foo', null , 10);
+ $this->assertEquals('SELECT n FROM Foo LIMIT 18446744073709551615 OFFSET 10',$sql);
+ }
+
public function testGenerateMixedCaseTableCreate()
{
$table = new Table("Foo");
Something went wrong with that request. Please try again.