summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/databases/mxODBC.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2007-10-10 15:19:28 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2007-10-10 15:19:28 +0000
commitddf875dd0c554660d3a4f58e261b03e22a92a625 (patch)
tree445adadb0e31238d1e856ad09182cc9380951f70 /lib/sqlalchemy/databases/mxODBC.py
parent74064ce9fd8e08619fb376ac506311d96a7ba85e (diff)
downloadsqlalchemy-ddf875dd0c554660d3a4f58e261b03e22a92a625.tar.gz
- initial sybase support checkin, [ticket:785]
Diffstat (limited to 'lib/sqlalchemy/databases/mxODBC.py')
-rw-r--r--lib/sqlalchemy/databases/mxODBC.py68
1 files changed, 68 insertions, 0 deletions
diff --git a/lib/sqlalchemy/databases/mxODBC.py b/lib/sqlalchemy/databases/mxODBC.py
new file mode 100644
index 000000000..61649b9b3
--- /dev/null
+++ b/lib/sqlalchemy/databases/mxODBC.py
@@ -0,0 +1,68 @@
+# mxODBC.py
+# Copyright (C) 2007 Fisch Asset Management AG http://www.fam.ch
+# Coding: Alexander Houben alexander.houben@thor-solutions.ch
+#
+# This module is part of SQLAlchemy and is released under
+# the MIT License: http://www.opensource.org/licenses/mit-license.php
+
+'''
+A wrapper for a mx.ODBC.Windows DB-API connection.
+
+Makes sure the mx module is configured to return datetime objects instead of
+mx.DateTime.DateTime objects.
+'''
+
+from mx.ODBC.Windows import *
+
+
+
+'''
+Override the 'cursor' method.
+'''
+
+class Cursor:
+
+ def __init__(self, cursor):
+ self.cursor = cursor
+
+ def __getattr__(self, attr):
+ res = getattr(self.cursor, attr)
+ return res
+
+ def execute(self, *args, **kwargs):
+ res = self.cursor.execute(*args, **kwargs)
+ return res
+
+class Connection:
+
+ def myErrorHandler(self, connection, cursor, errorclass, errorvalue):
+ err0, err1, err2, err3 = errorvalue
+ #print ", ".join(["Err%d: %s"%(x, errorvalue[x]) for x in range(4)])
+ if int(err1) == 109:
+ # Ignore "Null value eliminated in aggregate function", this is not an error
+ return
+ raise errorclass, errorvalue
+
+ def __init__(self, conn):
+ self.conn = conn
+ # install a mx ODBC error handler
+ self.conn.errorhandler = self.myErrorHandler
+
+ def __getattr__(self, attr):
+ res = getattr(self.conn, attr)
+ return res
+
+ def cursor(self, *args, **kwargs):
+ res = Cursor(self.conn.cursor(*args, **kwargs))
+ return res
+
+# override 'connect' call
+def connect(*args, **kwargs):
+ import mx.ODBC.Windows
+ conn = mx.ODBC.Windows.Connect(*args, **kwargs)
+ conn.datetimeformat = mx.ODBC.Windows.PYDATETIME_DATETIMEFORMAT
+ return Connection(conn)
+
+# override 'Connect' call
+def Connect(*args, **kwargs):
+ return self.connect(*args, **kwargs)