From: Mike Bayer Date: Sat, 18 Feb 2006 22:37:22 +0000 (+0000) Subject: added hooks for engines to add stuff to SELECT, etc. X-Git-Tag: rel_0_1_1~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8c957a074732d3162b3e44ee49a430d35b2b5c4b;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git added hooks for engines to add stuff to SELECT, etc. --- diff --git a/lib/sqlalchemy/ansisql.py b/lib/sqlalchemy/ansisql.py index ed0f829fbc..a9c6bb2071 100644 --- a/lib/sqlalchemy/ansisql.py +++ b/lib/sqlalchemy/ansisql.py @@ -277,8 +277,7 @@ class ANSICompiler(sql.Compiled): collist = string.join([self.get_str(v) for v in inner_columns.values()], ', ') text = "SELECT " - if select.distinct: - text += "DISTINCT " + text += self.visit_select_precolumns(select) text += collist whereclause = select.whereclause @@ -330,18 +329,23 @@ class ANSICompiler(sql.Compiled): t = self.get_str(select.having) if t: text += " \nHAVING " + t - - if select.limit is not None or select.offset is not None: - # TODO: ok, so this is a simple limit/offset thing. - # need to make this DB neutral for mysql, oracle - text += self.limit_clause(select) - + + text += self.visit_select_postclauses(select) + if getattr(select, 'issubquery', False): self.strings[select] = "(" + text + ")" else: self.strings[select] = text self.froms[select] = "(" + text + ")" + def visit_select_precolumns(self, select): + """ called when building a SELECT statment, position is just before column list """ + return select.distinct and "DISTINCT " or "" + + def visit_select_postclauses(self, select): + """ called when building a SELECT statement, position is after all other SELECT clauses. Most DB syntaxes put LIMIT/OFFSET here """ + return (select.limit or select.offset) and self.limit_clause(select) or "" + def limit_clause(self, select): if select.limit is not None: return " \n LIMIT " + str(select.limit)