Installation guide
6. mxODBC Connection Objects
Cursors also support the context manager API, so the above could be simplified
even more to:
with connection:
with connection.cursor() as cursor:
cursor.execute('INSERT INTO table VALUES (?, ?)', (1, 2))
… other tasks …
6.6 Unicode/ANSI Connections
Starting with mxODBC 3.1, it is possible to tell the ODBC driver manager whether
to use the Unicode ODBC interface of a supporting ODBC driver or the ANSI (8-
bit string) ODBC interface at connection time.
6.6.1 Unicode ODBC Interface
If the ODBC driver supports the ODBC Unicode interface and you select the
Unicode interface by using a Unicode string as connection parameter, the ODBC
manager will subsequently convert all ANSI-parameters to Unicode and then call
the Unicode APIs of the ODBC driver. Unicode parameters are passed through as-
is to the ODBC driver.
For ODBC drivers that natively support the ODBC Unicode interface, connecting
using a Unicode connection string and subsequently using Unicode parameters
for all execution and catalog methods may result in better performance or
improved compatibility.
Example:
# Use the Unicode ODBC API of the driver by using a Unicode connection
# string
db = mx.ODBC.Windows.DriverConnect(u'DSN=mydb;UID=uid;PWD=pwd')
6.6.2 ANSI ODBC Interface
If the ODBC driver does not support the ODBC Unicode interface, or you connect
using an ANSI (8-bit string), the ODBC driver manager will subsequently convert
all Unicode parameters to the connection's ANSI code page before calling the
ANSI API on the ODBC driver. ANSI parameters are passed through as-is to the
ODBC driver.
For ODBC drivers that do not support the ODBC Unicode interface, connecting
using an ANSI connection string and subsequently using ANSI parameters for all
execution and catalog methods may result in better performance or improved
compatibility.
Example:
# Use the ANSI ODBC API of the driver by using an 8-bit connection
91