summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/databases
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy/databases')
-rw-r--r--lib/sqlalchemy/databases/mysql.py11
-rw-r--r--lib/sqlalchemy/databases/oracle.py22
-rw-r--r--lib/sqlalchemy/databases/postgres.py10
-rw-r--r--lib/sqlalchemy/databases/sqlite.py10
4 files changed, 52 insertions, 1 deletions
diff --git a/lib/sqlalchemy/databases/mysql.py b/lib/sqlalchemy/databases/mysql.py
index 9e3f677d1..1eef6facb 100644
--- a/lib/sqlalchemy/databases/mysql.py
+++ b/lib/sqlalchemy/databases/mysql.py
@@ -175,7 +175,16 @@ class MySQLTableImpl(sql.TableImpl):
rowid_column = property(lambda s: s._rowid_col())
class MySQLCompiler(ansisql.ANSICompiler):
- pass
+ 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:
+ # striaght from the MySQL docs, I kid you not
+ text += " \n LIMIT 18446744073709551615"
+ text += " OFFSET " + str(select.offset)
+ return text
class MySQLSchemaGenerator(ansisql.ANSISchemaGenerator):
def get_column_specification(self, column, override_pk=False, first_pk=False):
diff --git a/lib/sqlalchemy/databases/oracle.py b/lib/sqlalchemy/databases/oracle.py
index 58d533b10..93670729d 100644
--- a/lib/sqlalchemy/databases/oracle.py
+++ b/lib/sqlalchemy/databases/oracle.py
@@ -195,6 +195,28 @@ class OracleCompiler(ansisql.ANSICompiler):
self.bindparams[c.key] = None
return ansisql.ANSICompiler.visit_insert(self, insert)
+ def visit_select(self, select):
+ """looks for LIMIT and OFFSET in a select statement, and if so tries to wrap it in a
+ subquery with rownum criterion."""
+ if getattr(select, '_oracle_visit', False):
+ ansisql.ANSICompiler.visit_select(self, select)
+ return
+ if select.limit is not None or select.offset is not None:
+ select._oracle_visit = True
+ limitselect = select.select()
+ if select.limit is not None:
+ limitselect.append_whereclause("rownum<%d" % select.limit)
+ if select.offset is not None:
+ limitselect.append_whereclause("rownum>%d" % select.offset)
+ limitselect.accept_visitor(self)
+ self.strings[select] = self.strings[limitselect]
+ self.froms[select] = self.froms[limitselect]
+ else:
+ ansisql.ANSICompiler.visit_select(self, select)
+
+ def limit_clause(self, select):
+ return ""
+
class OracleSchemaGenerator(ansisql.ANSISchemaGenerator):
def get_column_specification(self, column, override_pk=False, **kwargs):
colspec = column.name
diff --git a/lib/sqlalchemy/databases/postgres.py b/lib/sqlalchemy/databases/postgres.py
index 5a3d6388a..531e8af03 100644
--- a/lib/sqlalchemy/databases/postgres.py
+++ b/lib/sqlalchemy/databases/postgres.py
@@ -240,6 +240,16 @@ class PGCompiler(ansisql.ANSICompiler):
if c.sequence is not None and not c.sequence.optional:
self.bindparams[c.key] = None
return ansisql.ANSICompiler.visit_insert(self, insert)
+
+ 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:
+ text += " \n LIMIT ALL"
+ text += " OFFSET " + str(select.offset)
+ return text
class PGSchemaGenerator(ansisql.ANSISchemaGenerator):
def get_column_specification(self, column, override_pk=False, **kwargs):
diff --git a/lib/sqlalchemy/databases/sqlite.py b/lib/sqlalchemy/databases/sqlite.py
index 23a9d0483..fc85d92ac 100644
--- a/lib/sqlalchemy/databases/sqlite.py
+++ b/lib/sqlalchemy/databases/sqlite.py
@@ -188,7 +188,17 @@ class SQLiteCompiler(ansisql.ANSICompiler):
def __init__(self, *args, **params):
params.setdefault('paramstyle', 'named')
ansisql.ANSICompiler.__init__(self, *args, **params)
+ 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:
+ text += " \n LIMIT -1"
+ text += " OFFSET " + str(select.offset)
+ return text
+
class SQLiteSchemaGenerator(ansisql.ANSISchemaGenerator):
def get_column_specification(self, column, override_pk=False, **kwargs):
colspec = column.name + " " + column.type.get_col_spec()