DDC-1564: MySQL Failure when using setFirstResult() and omitting setMaxResults() #1961

Closed
opened 2026-01-22 13:33:51 +01:00 by admin · 4 comments
Owner

Originally created by @doctrinebot on GitHub (Dec 25, 2011).

Originally assigned to: @Ocramius on GitHub.

Jira issue originally created by user felicitus:

When using setFirstResult() and omitting setMaxResults(), MySQL throws an error. This was very confusing for me until I dumped the SQL statements and found out the reason.

I know that MySQL doesn't directly support this, their manual says that you should set the second parameter to LIMIT to a very high number (18446744073709551615 in their example).

I'd recommend that either throwing an error in the specific platform driver or follow the MySQL example.

Originally created by @doctrinebot on GitHub (Dec 25, 2011). Originally assigned to: @Ocramius on GitHub. Jira issue originally created by user felicitus: When using setFirstResult() and omitting setMaxResults(), MySQL throws an error. This was very confusing for me until I dumped the SQL statements and found out the reason. I know that MySQL doesn't directly support this, their manual says that you should set the second parameter to LIMIT to a very high number (18446744073709551615 in their example). I'd recommend that either throwing an error in the specific platform driver or follow the MySQL example.
admin added the ImprovementInvalid labels 2026-01-22 13:33:51 +01:00
admin closed this issue 2026-01-22 13:33:53 +01:00
Author
Owner

@doctrinebot commented on GitHub (Dec 28, 2011):

Comment created by @beberlei:

Changed into improvement, i am not sure how this relates to other databases.

You can just use this workaround yourself so long.

@doctrinebot commented on GitHub (Dec 28, 2011): Comment created by @beberlei: Changed into improvement, i am not sure how this relates to other databases. You can just use this workaround yourself so long.
Author
Owner

@malukenho commented on GitHub (Jan 5, 2017):

@Ocramius @lcobucci It's related to DBAL.

    // class \Doctrine\DBAL\Platforms\MySqlPlatform
    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;
    }

I guessing it's not a real problem.

@malukenho commented on GitHub (Jan 5, 2017): @Ocramius @lcobucci It's related to `DBAL`. ```php // class \Doctrine\DBAL\Platforms\MySqlPlatform 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; } ``` I guessing it's not a *real* problem.
Author
Owner

@Ocramius commented on GitHub (Jan 5, 2017):

Probably good enough to use ``LIMIT ' . \PHP_INT_MAX`.

@malukenho can you please port the issue to DBAL, so we can close it here?

@Ocramius commented on GitHub (Jan 5, 2017): Probably good enough to use ``LIMIT ' . \PHP_INT_MAX`. @malukenho can you please port the issue to DBAL, so we can close it here?
Author
Owner

@Ocramius commented on GitHub (Jan 5, 2017):

NVM, it is indeed already fixed in DBAL: 8f0e497312/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php (L67)

@Ocramius commented on GitHub (Jan 5, 2017): NVM, it is indeed already fixed in DBAL: https://github.com/doctrine/dbal/blob/8f0e497312705fba80c666cfca9dac8b59d701c3/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php#L67
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1961