1.4.16.6 Converter Objects

Converter objects contain methods to convert values between SQL and Python objects and to convert values returned by the database driver into the correct Python type. Converter objects are accessed through the converter attribute of the corresponding Column object.

Example: convert a list of values selected from a database to their SQL encoded equivalents

>>> cursor.select(columns=['table1.columnOne', 'table2.column2'], tables=['table1', 'table2'], execute=True)
>>> results = cursor.fetchall()
>>> record = results[0]
>>> newRecord = []
>>> for i in range(len(record)):
...     newRecord.append(cursor.info[i].converter.valueToSQL(record[i]))

class Converter

valueToSQL( value)
Convert a Python object to an SQL string
sqlToValue( value)
Convert the an SQL string to a Python object
databaseToValue( value)
Convert the value stored in the database to a Python object
valueToDatabase( value)
Convert a Python object to the format needed to store it in the database

type
A string representing the column type
sqlQuotes
True if the SQL representation should be quoted, False otherwise

Converter objects are also available as a dictionary with column types as the keys as the converters attribute of the Connection object.