root/galaxy-central/eggs/SQLAlchemy-0.5.6_dev_r6498-py2.6.egg/sqlalchemy/databases/mxODBC.py

リビジョン 3, 1.7 KB (コミッタ: kohda, 14 年 前)

Install Unix tools  http://hannonlab.cshl.edu/galaxy_unix_tools/galaxy.html

行番号 
1# mxODBC.py
2# Copyright (C) 2007 Fisch Asset Management AG http://www.fam.ch
3# Coding: Alexander Houben alexander.houben@thor-solutions.ch
4#
5# This module is part of SQLAlchemy and is released under
6# the MIT License: http://www.opensource.org/licenses/mit-license.php
7
8"""
9A wrapper for a mx.ODBC.Windows DB-API connection.
10
11Makes sure the mx module is configured to return datetime objects instead
12of mx.DateTime.DateTime objects.
13"""
14
15from mx.ODBC.Windows import *
16
17
18class Cursor:
19    def __init__(self, cursor):
20        self.cursor = cursor
21
22    def __getattr__(self, attr):
23        res = getattr(self.cursor, attr)
24        return res
25
26    def execute(self, *args, **kwargs):
27        res = self.cursor.execute(*args, **kwargs)
28        return res
29
30
31class Connection:
32    def myErrorHandler(self, connection, cursor, errorclass, errorvalue):
33        err0, err1, err2, err3 = errorvalue
34        #print ", ".join(["Err%d: %s"%(x, errorvalue[x]) for x in range(4)])
35        if int(err1) == 109:
36            # Ignore "Null value eliminated in aggregate function", this is not an error
37            return
38        raise errorclass, errorvalue
39
40    def __init__(self, conn):
41        self.conn = conn
42        # install a mx ODBC error handler
43        self.conn.errorhandler = self.myErrorHandler
44
45    def __getattr__(self, attr):
46        res = getattr(self.conn, attr)
47        return res
48
49    def cursor(self, *args, **kwargs):
50        res = Cursor(self.conn.cursor(*args, **kwargs))
51        return res
52
53
54# override 'connect' call
55def connect(*args, **kwargs):
56    import mx.ODBC.Windows
57    conn = mx.ODBC.Windows.Connect(*args, **kwargs)
58    conn.datetimeformat = mx.ODBC.Windows.PYDATETIME_DATETIMEFORMAT
59    return Connection(conn)
60Connect = connect
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。