Installation guide
mxODBC - Python ODBC Database Interface
8.6.1 Converter Function Signatures
You can modify this mapping on-the-fly by defining a cursor converter function
which takes three arguments and has to return a 2-tuple:
def converter(position,sqltype,sqllen):
# modify sqltype and sqllen as appropriate
return sqltype,sqllen
# Now tell the cursor to use this converter:
cursor.setconverter(converter)
or 3-tuple:
def converter(position,sqltype,sqllen):
# modify sqltype and sqllen as appropriate, provide binddata as
# input (e.g. for file names which should be used for file
# binding)
return sqltype,sqllen,binddata
# Now tell the cursor to use this converter:
cursor.setconverter(converter)
The converter function is called for each output column prior to the first
.fetch*() operation executed on the cursor. The returned values are then
interpreted as defined in the table in section 8.3 Output Conversions and SQL
Type Input Binding.
The parameters have the following meanings:
position
identifies the 0-based position of the column in the result set.
sqltype
is usually one of the SQL data type constants, e.g. SQL.CHAR for string data,
but could also have database specific values. mxODBC only understands the
ones defined in the above table, so this gives you a chance to map user defined
types to ones that Python can process.
sqllen
is only used for string data and defines the maximum length of strings that can
be read in that column (mxODBC allocates a memory buffer of this size for the
data transfer).
Returning
0 as sqllen will result in mxODBC dynamically growing the data
transfer buffer when fetching the column data. This is sometimes handy in
case you want to fetch data that can vary in size.
binddata
is optional and only needed for some special sqltypes. It will be used in
future versions to e.g. allow binding output columns to files which some
ODBC drivers support (the column data is transferred directly to a file instead
of copied into memory).
152