From 6f3f85e48c7dca360f029c23231711036c66a95f Mon Sep 17 00:00:00 2001 From: Jason Kirtland Date: Wed, 26 Sep 2007 23:37:11 +0000 Subject: Changed MySQL dialect to use the older LIMIT , syntax instead of LIMIT OFFSET for folks using 3.23. ([ticket:794], thanks for the patch!) --- lib/sqlalchemy/databases/mysql.py | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'lib/sqlalchemy/databases/mysql.py') diff --git a/lib/sqlalchemy/databases/mysql.py b/lib/sqlalchemy/databases/mysql.py index 9eba2abdb..c0b1179a3 100644 --- a/lib/sqlalchemy/databases/mysql.py +++ b/lib/sqlalchemy/databases/mysql.py @@ -1812,16 +1812,28 @@ class MySQLCompiler(compiler.DefaultCompiler): return super(MySQLCompiler, self).for_update_clause(select) def limit_clause(self, select): - text = "" - if select._limit is not None: - text += " \n LIMIT " + str(select._limit) - if select._offset is not None: - if select._limit is None: - # straight from the MySQL docs, I kid you not - text += " \n LIMIT 18446744073709551615" - text += " OFFSET " + str(select._offset) - return text - + # MySQL supports: + # LIMIT + # LIMIT , + # and in server versions > 3.3: + # LIMIT OFFSET + # The latter is more readable for offsets but we're stuck with the + # former until we can refine dialects by server revision. + + limit, offset = select._limit, select._offset + + if (limit, offset) == (None, None): + return '' + elif offset is not None: + # As suggested by the MySQL docs, need to apply an + # artificial limit if one wasn't provided + if limit is None: + limit = 18446744073709551615 + return ' \n LIMIT %s, %s' % (offset, limit) + else: + # No offset provided, so just use the limit + return ' \n LIMIT %s' % (limit,) + # ug. "InnoDB needs indexes on foreign keys and referenced keys [...]. # Starting with MySQL 4.1.2, these indexes are created automatically. -- cgit v1.2.1