From: Rick Morrison Date: Fri, 16 Feb 2007 17:06:17 +0000 (+0000) Subject: Func rewrite for better unittest compatibility X-Git-Tag: rel_0_3_5~31 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c3e6960e037116156512bf3cd208aad437d12c09;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Func rewrite for better unittest compatibility Simplified transaction handling for pymssql --- diff --git a/lib/sqlalchemy/databases/mssql.py b/lib/sqlalchemy/databases/mssql.py index abdb670d68..f64feed93c 100644 --- a/lib/sqlalchemy/databases/mssql.py +++ b/lib/sqlalchemy/databases/mssql.py @@ -534,35 +534,37 @@ class MSSQLDialect(ansisql.ANSIDialect): class PyMSSQLDialect(MSSQLDialect): - def do_begin(self, connection): - """implementations might want to put logic here for turning autocommit on/off, etc.""" - pass + pass +## def do_begin(self, connection): +## """implementations might want to put logic here for turning autocommit on/off, etc.""" +## pass + +## def do_rollback(self, connection): +## """implementations might want to put logic here for turning autocommit on/off, etc.""" +## try: +## # connection.rollback() for pymmsql failed sometimes--the begin tran doesn't show up +## # this is a workaround that seems to be handle it. +## r = self.raw_connection(connection) +## r.query("if @@trancount > 0 rollback tran") +## r.fetch_array() +## r.query("begin tran") +## r.fetch_array() +## except: +## pass + +## def do_commit(self, connection): +## """implementations might want to put logic here for turning autocommit on/off, etc. +## do_commit is set for pymmsql connections--ADO seems to handle transactions without any issue +## """ +## # ADO Uses Implicit Transactions. +## # This is very pymssql specific. We use this instead of its commit, because it hangs on failed rollbacks. +## # By using the "if" we don't assume an open transaction--much better. +## r = self.raw_connection(connection) +## r.query("if @@trancount > 0 commit tran") +## r.fetch_array() +## r.query("begin tran") +## r.fetch_array() - def do_rollback(self, connection): - """implementations might want to put logic here for turning autocommit on/off, etc.""" - try: - # connection.rollback() for pymmsql failed sometimes--the begin tran doesn't show up - # this is a workaround that seems to be handle it. - r = self.raw_connection(connection) - r.query("if @@trancount > 0 rollback tran") - r.fetch_array() - r.query("begin tran") - r.fetch_array() - except: - pass - - def do_commit(self, connection): - """implementations might want to put logic here for turning autocommit on/off, etc. - do_commit is set for pymmsql connections--ADO seems to handle transactions without any issue - """ - # ADO Uses Implicit Transactions. - # This is very pymssql specific. We use this instead of its commit, because it hangs on failed rollbacks. - # By using the "if" we don't assume an open transaction--much better. - r = self.raw_connection(connection) - r.query("if @@trancount > 0 commit tran") - r.fetch_array() - r.query("begin tran") - r.fetch_array() class MSSQLCompiler(ansisql.ANSICompiler): def __init__(self, dialect, statement, parameters, **kwargs): @@ -617,6 +619,14 @@ class MSSQLCompiler(ansisql.ANSICompiler): binary.left, binary.right = binary.right, binary.left super(MSSQLCompiler, self).visit_binary(binary) + function_rewrites = \ + { + 'current_date': 'getdate', + 'length': 'len', + } + def visit_function(self, func): + func.name = self.function_rewrites.get(func.name, func.name) + super(MSSQLCompiler, self).visit_function(func) class MSSQLSchemaGenerator(ansisql.ANSISchemaGenerator): def get_column_specification(self, column, **kwargs):