summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql
diff options
context:
space:
mode:
authorDobes Vandermeer <dvandermeer@roovy.com>2014-04-24 15:20:57 -0700
committerDobes Vandermeer <dvandermeer@roovy.com>2014-04-24 15:20:57 -0700
commit338ca8e48827840ad5db4ee4f677e4d3fcd315c9 (patch)
tree483e7092969c364fff255b6ed24d1845c2e45c5f /lib/sqlalchemy/sql
parent5016b581b6a0099b5d4babf885ae1f2c05a9589f (diff)
downloadsqlalchemy-338ca8e48827840ad5db4ee4f677e4d3fcd315c9.tar.gz
Proof-of-concept implementation of supporting bindparam for offset and limit on a query.
Diffstat (limited to 'lib/sqlalchemy/sql')
-rw-r--r--lib/sqlalchemy/sql/compiler.py5
-rw-r--r--lib/sqlalchemy/sql/selectable.py16
2 files changed, 15 insertions, 6 deletions
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,
diff --git a/lib/sqlalchemy/sql/selectable.py b/lib/sqlalchemy/sql/selectable.py
index afcf437e9..5995c1f8a 100644
--- a/lib/sqlalchemy/sql/selectable.py
+++ b/lib/sqlalchemy/sql/selectable.py
@@ -1562,9 +1562,9 @@ class GenerativeSelect(SelectBase):
self._execution_options.union(
{'autocommit': autocommit})
if limit is not None:
- self._limit = util.asint(limit)
+ self._limit = limit
if offset is not None:
- self._offset = util.asint(offset)
+ self._offset = offset
self._bind = bind
if order_by is not None:
@@ -1644,14 +1644,14 @@ class GenerativeSelect(SelectBase):
"""return a new selectable with the given LIMIT criterion
applied."""
- self._limit = util.asint(limit)
+ self._limit = limit
@_generative
def offset(self, offset):
"""return a new selectable with the given OFFSET criterion
applied."""
- self._offset = util.asint(offset)
+ self._offset = offset
@_generative
def order_by(self, *clauses):
@@ -1712,6 +1712,12 @@ class GenerativeSelect(SelectBase):
self._group_by_clause = ClauseList(*clauses)
+ def _copy_internals(self, clone=_clone, **kw):
+ if isinstance(self._limit, ClauseElement):
+ self._limit = clone(self._limit)
+ if isinstance(self._offset, ClauseElement):
+ self._offset = clone(self._offset)
+
class CompoundSelect(GenerativeSelect):
"""Forms the basis of ``UNION``, ``UNION ALL``, and other
SELECT-based set operations.
@@ -1930,6 +1936,7 @@ class CompoundSelect(GenerativeSelect):
"addition of columns to underlying selectables")
def _copy_internals(self, clone=_clone, **kw):
+ super(CompoundSelect, self)._copy_internals(clone, **kw)
self._reset_exported()
self.selects = [clone(s, **kw) for s in self.selects]
if hasattr(self, '_col_map'):
@@ -2380,6 +2387,7 @@ class Select(HasPrefixes, GenerativeSelect):
return False
def _copy_internals(self, clone=_clone, **kw):
+ super(Select, self)._copy_internals(clone, **kw)
# Select() object has been cloned and probably adapted by the
# given clone function. Apply the cloning function to internal