From 7ad8cc9420f796dfcafbc84dc06453fc3eb51abe Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 4 Mar 2006 18:53:35 +0000 Subject: [PATCH] removed the dependency of ANSICompiler on SQLEngine. you can now make ANSICompilers and compile SQL with no engine at all. --- lib/sqlalchemy/ansisql.py | 54 ++++++++++++------- lib/sqlalchemy/databases/firebird.py | 2 +- .../databases/information_schema.py | 2 +- lib/sqlalchemy/databases/mysql.py | 2 +- lib/sqlalchemy/databases/oracle.py | 4 +- lib/sqlalchemy/databases/postgres.py | 2 +- lib/sqlalchemy/databases/sqlite.py | 2 +- lib/sqlalchemy/engine.py | 6 +-- lib/sqlalchemy/sql.py | 49 +++++++++-------- test/select.py | 7 +-- 10 files changed, 75 insertions(+), 55 deletions(-) diff --git a/lib/sqlalchemy/ansisql.py b/lib/sqlalchemy/ansisql.py index 1b600a4a84..7c0002aa58 100644 --- a/lib/sqlalchemy/ansisql.py +++ b/lib/sqlalchemy/ansisql.py @@ -27,7 +27,7 @@ class ANSISQLEngine(sqlalchemy.engine.SQLEngine): return ANSISchemaDropper(self, **params) def compiler(self, statement, parameters, **kwargs): - return ANSICompiler(self, statement, parameters, **kwargs) + return ANSICompiler(statement, parameters, engine=self, **kwargs) def connect_args(self): return ([],{}) @@ -37,7 +37,7 @@ class ANSISQLEngine(sqlalchemy.engine.SQLEngine): class ANSICompiler(sql.Compiled): """default implementation of Compiled, which compiles ClauseElements into ANSI-compliant SQL strings.""" - def __init__(self, engine, statement, parameters=None, typemap=None, **kwargs): + def __init__(self, statement, parameters=None, typemap=None, engine=None, positional=None, paramstyle=None, **kwargs): """constructs a new ANSICompiler object. engine - SQLEngine to compile against @@ -49,7 +49,7 @@ class ANSICompiler(sql.Compiled): key/value pairs when the Compiled is executed, and also may affect the actual compilation, as in the case of an INSERT where the actual columns inserted will correspond to the keys present in the parameters.""" - sql.Compiled.__init__(self, engine, statement, parameters) + sql.Compiled.__init__(self, statement, parameters, engine=engine) self.binds = {} self.froms = {} self.wheres = {} @@ -57,19 +57,31 @@ class ANSICompiler(sql.Compiled): self.select_stack = [] self.typemap = typemap or {} self.isinsert = False + self.bindtemplate = ":%s" + if engine is not None: + self.paramstyle = engine.paramstyle + self.positional = engine.positional + else: + self.positional = False + self.paramstyle = 'named' def after_compile(self): - if self.engine.positional: + # this re will search for params like :param + # it has a negative lookbehind for an extra ':' so that it doesnt match + # postgres '::text' tokens + match = r'(?