diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-03-27 17:18:53 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-03-27 17:18:53 -0400 |
| commit | 36047e9bb28501477b1403059087cccc120be2b6 (patch) | |
| tree | 1438816820a5de5587cbf21a2d4ca89b173ef833 /lib/sqlalchemy/dialects | |
| parent | 3cd2c4661f1522353be983a309dc947c2a2a28bb (diff) | |
| download | sqlalchemy-36047e9bb28501477b1403059087cccc120be2b6.tar.gz | |
- Added with_hint() method to Query() construct. This calls
directly down to select().with_hint() and also accepts
entities as well as tables and aliases. See with_hint() in the
SQL section below. [ticket:921]
- Added with_hint() method to select() construct. Specify
a table/alias, hint text, and optional dialect name, and
"hints" will be rendered in the appropriate place in the
statement. Works for Oracle, Sybase, MySQL. [ticket:921]
Diffstat (limited to 'lib/sqlalchemy/dialects')
| -rw-r--r-- | lib/sqlalchemy/dialects/mysql/base.py | 11 | ||||
| -rw-r--r-- | lib/sqlalchemy/dialects/oracle/base.py | 23 | ||||
| -rw-r--r-- | lib/sqlalchemy/dialects/sybase/base.py | 3 |
3 files changed, 27 insertions, 10 deletions
diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py index 873dfd16c..f9bb48235 100644 --- a/lib/sqlalchemy/dialects/mysql/base.py +++ b/lib/sqlalchemy/dialects/mysql/base.py @@ -1154,7 +1154,10 @@ class MySQLCompiler(compiler.SQLCompiler): def visit_match_op(self, binary, **kw): return "MATCH (%s) AGAINST (%s IN BOOLEAN MODE)" % (self.process(binary.left), self.process(binary.right)) - + + def get_from_hint_text(self, table, text): + return text + def visit_typeclause(self, typeclause): type_ = typeclause.type.dialect_impl(self.dialect) if isinstance(type_, sqltypes.Integer): @@ -1204,11 +1207,11 @@ class MySQLCompiler(compiler.SQLCompiler): # support can be added, preferably after dialects are # refactored to be version-sensitive. return ''.join( - (self.process(join.left, asfrom=True), + (self.process(join.left, asfrom=True, **kwargs), (join.isouter and " LEFT OUTER JOIN " or " INNER JOIN "), - self.process(join.right, asfrom=True), + self.process(join.right, asfrom=True, **kwargs), " ON ", - self.process(join.onclause))) + self.process(join.onclause, **kwargs))) def for_update_clause(self, select): if select.for_update == 'read': diff --git a/lib/sqlalchemy/dialects/oracle/base.py b/lib/sqlalchemy/dialects/oracle/base.py index 332fa805d..475730988 100644 --- a/lib/sqlalchemy/dialects/oracle/base.py +++ b/lib/sqlalchemy/dialects/oracle/base.py @@ -342,6 +342,11 @@ class OracleCompiler(compiler.SQLCompiler): def visit_match_op(self, binary, **kw): return "CONTAINS (%s, %s)" % (self.process(binary.left), self.process(binary.right)) + def get_select_hint_text(self, byfroms): + return " ".join( + "/*+ %s */" % text for table, text in byfroms.items() + ) + def function_argspec(self, fn, **kw): if len(fn.clauses) > 0: return compiler.SQLCompiler.function_argspec(self, fn, **kw) @@ -360,7 +365,9 @@ class OracleCompiler(compiler.SQLCompiler): if self.dialect.use_ansi: return compiler.SQLCompiler.visit_join(self, join, **kwargs) else: - return self.process(join.left, asfrom=True) + ", " + self.process(join.right, asfrom=True) + kwargs['asfrom'] = True + return self.process(join.left, **kwargs) + \ + ", " + self.process(join.right, **kwargs) def _get_nonansi_join_whereclause(self, froms): clauses = [] @@ -392,14 +399,18 @@ class OracleCompiler(compiler.SQLCompiler): def visit_sequence(self, seq): return self.dialect.identifier_preparer.format_sequence(seq) + ".nextval" - def visit_alias(self, alias, asfrom=False, **kwargs): + def visit_alias(self, alias, asfrom=False, ashint=False, **kwargs): """Oracle doesn't like ``FROM table AS alias``. Is the AS standard SQL??""" - - if asfrom: + + if asfrom or ashint: alias_name = isinstance(alias.name, expression._generated_label) and \ self._truncated_identifier("alias", alias.name) or alias.name - - return self.process(alias.original, asfrom=asfrom, **kwargs) + " " + self.preparer.format_alias(alias, alias_name) + + if ashint: + return alias_name + elif asfrom: + return self.process(alias.original, asfrom=asfrom, **kwargs) + \ + " " + self.preparer.format_alias(alias, alias_name) else: return self.process(alias.original, **kwargs) diff --git a/lib/sqlalchemy/dialects/sybase/base.py b/lib/sqlalchemy/dialects/sybase/base.py index aaec7a504..79e32b968 100644 --- a/lib/sqlalchemy/dialects/sybase/base.py +++ b/lib/sqlalchemy/dialects/sybase/base.py @@ -277,6 +277,9 @@ class SybaseSQLCompiler(compiler.SQLCompiler): s += "START AT %s " % (select._offset+1,) return s + def get_from_hint_text(self, table, text): + return text + def limit_clause(self, select): # Limit in sybase is after the select keyword return "" |
