From: Mike Bayer Date: Sat, 4 Mar 2006 18:53:35 +0000 (+0000) Subject: removed the dependency of ANSICompiler on SQLEngine. you can now make ANSICompilers... X-Git-Tag: rel_0_1_4~47 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7ad8cc9420f796dfcafbc84dc06453fc3eb51abe;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git removed the dependency of ANSICompiler on SQLEngine. you can now make ANSICompilers and compile SQL with no engine at all. --- 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'(?