From 338ca8e48827840ad5db4ee4f677e4d3fcd315c9 Mon Sep 17 00:00:00 2001 From: Dobes Vandermeer Date: Thu, 24 Apr 2014 15:20:57 -0700 Subject: Proof-of-concept implementation of supporting bindparam for offset and limit on a query. --- lib/sqlalchemy/sql/compiler.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib/sqlalchemy/sql/compiler.py') diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 31193ab17..b59e8a941 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -29,6 +29,7 @@ from .. import util, exc import decimal import itertools import operator +from sqlalchemy.sql.elements import _literal_as_binds RESERVED_WORDS = set([ 'all', 'analyse', 'analyze', 'and', 'any', 'array', @@ -1625,11 +1626,11 @@ class SQLCompiler(Compiled): def limit_clause(self, select): text = "" if select._limit is not None: - text += "\n LIMIT " + self.process(elements.literal(select._limit)) + text += "\n LIMIT " + self.process(_literal_as_binds(select._limit)) if select._offset is not None: if select._limit is None: text += "\n LIMIT -1" - text += " OFFSET " + self.process(elements.literal(select._offset)) + text += " OFFSET " + self.process(_literal_as_binds(select._offset)) return text def visit_table(self, table, asfrom=False, iscrud=False, ashint=False, -- cgit v1.2.1 From 4af172b644d90f1bcab3de2bd0501a9cf50dc1d5 Mon Sep 17 00:00:00 2001 From: Dobes Vandermeer Date: Fri, 25 Apr 2014 10:42:12 -0700 Subject: Use _offset_clause and _limit_clause, which are always Visitable and usually a BindParameter, instead of _offset and _limit in GenerativeSelect. --- lib/sqlalchemy/sql/compiler.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'lib/sqlalchemy/sql/compiler.py') diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index b59e8a941..557ab1531 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -774,7 +774,7 @@ class SQLCompiler(Compiled): text += " GROUP BY " + group_by text += self.order_by_clause(cs, **kwargs) - text += (cs._limit is not None or cs._offset is not None) and \ + text += (cs._limit_clause is not None or cs._offset_clause is not None) and \ self.limit_clause(cs) or "" if self.ctes and \ @@ -1557,7 +1557,7 @@ class SQLCompiler(Compiled): text += self.order_by_clause(select, order_by_select=order_by_select, **kwargs) - if select._limit is not None or select._offset is not None: + if select._limit_clause is not None or select._offset_clause is not None: text += self.limit_clause(select) if select._for_update_arg is not None: @@ -1625,12 +1625,12 @@ class SQLCompiler(Compiled): def limit_clause(self, select): text = "" - if select._limit is not None: - text += "\n LIMIT " + self.process(_literal_as_binds(select._limit)) - if select._offset is not None: - if select._limit is None: + if select._limit_clause is not None: + text += "\n LIMIT " + self.process(select._limit_clause) + if select._offset_clause is not None: + if select._limit_clause is None: text += "\n LIMIT -1" - text += " OFFSET " + self.process(_literal_as_binds(select._offset)) + text += " OFFSET " + self.process(select._offset_clause) return text def visit_table(self, table, asfrom=False, iscrud=False, ashint=False, -- cgit v1.2.1 From e9ada891d825e432775be0e67e39930dab60df50 Mon Sep 17 00:00:00 2001 From: Dobes Vandermeer Date: Fri, 25 Apr 2014 10:49:07 -0700 Subject: Remove unused import --- lib/sqlalchemy/sql/compiler.py | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/sqlalchemy/sql/compiler.py') diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 557ab1531..c95019ef6 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -29,7 +29,6 @@ from .. import util, exc import decimal import itertools import operator -from sqlalchemy.sql.elements import _literal_as_binds RESERVED_WORDS = set([ 'all', 'analyse', 'analyze', 'and', 'any', 'array', -- cgit v1.2.1