diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-09-18 11:44:48 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-09-18 11:44:48 -0400 |
commit | f82f6d55dc05daf2ba0881ded98f5715b70ae3e3 (patch) | |
tree | 0686f4a11aa825fdc1994c566da78382e7dcf071 /lib/sqlalchemy/sql/compiler.py | |
parent | e3f07f7206cf0d6a5f2ff9344a365f4657645338 (diff) | |
download | sqlalchemy-f82f6d55dc05daf2ba0881ded98f5715b70ae3e3.tar.gz |
- Added new method :meth:`.Select.with_statement_hint` and ORM
method :meth:`.Query.with_statement_hint` to support statement-level
hints that are not specific to a table.
fixes #3206
Diffstat (limited to 'lib/sqlalchemy/sql/compiler.py')
-rw-r--r-- | lib/sqlalchemy/sql/compiler.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 5149fa4fe..abda31358 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -1331,6 +1331,9 @@ class SQLCompiler(Compiled): def get_crud_hint_text(self, table, text): return None + def get_statement_hint_text(self, hint_texts): + return " ".join(hint_texts) + def _transform_select_for_nested_joins(self, select): """Rewrite any "a JOIN (b JOIN c)" expression as "a JOIN (select * from b JOIN c) AS anon", to support @@ -1609,6 +1612,15 @@ class SQLCompiler(Compiled): if select._for_update_arg is not None: text += self.for_update_clause(select, **kwargs) + if select._statement_hints: + per_dialect = [ + ht for (dialect_name, ht) + in select._statement_hints + if dialect_name in ('*', self.dialect.name) + ] + if per_dialect: + text += " " + self.get_statement_hint_text(per_dialect) + if self.ctes and \ compound_index == 0 and toplevel: text = self._render_cte_clause() + text |