~ubuntu-branches/debian/jessie/sqlalchemy/jessie

« back to all changes in this revision

Viewing changes to lib/sqlalchemy/connectors/mxodbc.py

  • Committer: Package Import Robot
  • Author(s): Piotr Ożarowski, Jakub Wilk, Piotr Ożarowski
  • Date: 2013-07-06 20:53:52 UTC
  • mfrom: (1.4.23) (16.1.17 experimental)
  • Revision ID: package-import@ubuntu.com-20130706205352-ryppl1eto3illd79
Tags: 0.8.2-1
[ Jakub Wilk ]
* Use canonical URIs for Vcs-* fields.

[ Piotr Ożarowski ]
* New upstream release
* Upload to unstable
* Build depend on python3-all instead of -dev, extensions are not built for
  Python 3.X 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# connectors/mxodbc.py
2
 
# Copyright (C) 2005-2012 the SQLAlchemy authors and contributors <see AUTHORS file>
 
2
# Copyright (C) 2005-2013 the SQLAlchemy authors and contributors <see AUTHORS file>
3
3
#
4
4
# This module is part of SQLAlchemy and is released under
5
5
# the MIT License: http://www.opensource.org/licenses/mit-license.php
22
22
import re
23
23
import warnings
24
24
 
25
 
from sqlalchemy.connectors import Connector
 
25
from . import Connector
 
26
 
26
27
 
27
28
class MxODBCConnector(Connector):
28
 
    driver='mxodbc'
 
29
    driver = 'mxodbc'
29
30
 
30
31
    supports_sane_multi_rowcount = False
31
 
    supports_unicode_statements = False
32
 
    supports_unicode_binds = False
 
32
    supports_unicode_statements = True
 
33
    supports_unicode_binds = True
33
34
 
34
35
    supports_native_decimal = True
35
36
 
47
48
        elif platform == 'darwin':
48
49
            from mx.ODBC import iODBC as module
49
50
        else:
50
 
            raise ImportError, "Unrecognized platform for mxODBC import"
 
51
            raise ImportError("Unrecognized platform for mxODBC import")
51
52
        return module
52
53
 
53
54
    @classmethod
73
74
        emit Python standard warnings.
74
75
        """
75
76
        from mx.ODBC.Error import Warning as MxOdbcWarning
 
77
 
76
78
        def error_handler(connection, cursor, errorclass, errorvalue):
77
 
 
78
79
            if issubclass(errorclass, MxOdbcWarning):
79
80
                errorclass.__bases__ = (Warning,)
80
81
                warnings.warn(message=str(errorvalue),
130
131
                version.append(n)
131
132
        return tuple(version)
132
133
 
133
 
    def do_execute(self, cursor, statement, parameters, context=None):
 
134
    def _get_direct(self, context):
134
135
        if context:
135
136
            native_odbc_execute = context.execution_options.\
136
137
                                        get('native_odbc_execute', 'auto')
137
 
            if native_odbc_execute is True:
138
 
                # user specified native_odbc_execute=True
139
 
                cursor.execute(statement, parameters)
140
 
            elif native_odbc_execute is False:
141
 
                # user specified native_odbc_execute=False
142
 
                cursor.executedirect(statement, parameters)
143
 
            elif context.is_crud:
144
 
                # statement is UPDATE, DELETE, INSERT
145
 
                cursor.execute(statement, parameters)
146
 
            else:
147
 
                # all other statements
148
 
                cursor.executedirect(statement, parameters)
 
138
            # default to direct=True in all cases, is more generally
 
139
            # compatible especially with SQL Server
 
140
            return False if native_odbc_execute is True else True
149
141
        else:
150
 
            cursor.executedirect(statement, parameters)
 
142
            return True
 
143
 
 
144
    def do_executemany(self, cursor, statement, parameters, context=None):
 
145
        cursor.executemany(
 
146
            statement, parameters, direct=self._get_direct(context))
 
147
 
 
148
    def do_execute(self, cursor, statement, parameters, context=None):
 
149
        cursor.execute(statement, parameters, direct=self._get_direct(context))