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>
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
25
from sqlalchemy.connectors import Connector
25
from . import Connector
27
28
class MxODBCConnector(Connector):
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
34
35
supports_native_decimal = True
47
48
elif platform == 'darwin':
48
49
from mx.ODBC import iODBC as module
50
raise ImportError, "Unrecognized platform for mxODBC import"
51
raise ImportError("Unrecognized platform for mxODBC import")
73
74
emit Python standard warnings.
75
76
from mx.ODBC.Error import Warning as MxOdbcWarning
76
78
def error_handler(connection, cursor, errorclass, errorvalue):
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)
133
def do_execute(self, cursor, statement, parameters, context=None):
134
def _get_direct(self, 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)
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
150
cursor.executedirect(statement, parameters)
144
def do_executemany(self, cursor, statement, parameters, context=None):
146
statement, parameters, direct=self._get_direct(context))
148
def do_execute(self, cursor, statement, parameters, context=None):
149
cursor.execute(statement, parameters, direct=self._get_direct(context))