Installation guide
mxODBC - Python ODBC Database Interface
cursor.rowfactory = RowFactory.ListRowFactory
cursor.execute('select x, Y, z from mytable')
row = cursor.fetchone()
print (row[0], row[1], row[2], row.x, row.y, row.z)
row[0] = 10
row[1] = 'abc'
print (row[:2])
# will print [10, 'abc']
row.x = 20
row.y = 'def'
print (row[:2])
# will print [20, 'def']
The row objects are also usable as input for the cursor.execute*()
methods.
Example:
cursor.execute('insert into mytable values (x, Y, z)', row)
RowFactory.NamespaceRowFactory
The NamespaceRowFactory creates mx.Misc.Namespace.Namespace objects
as row objects. These provide a more complex namespace oriented API.
In addition to the sequence protocol, they also allow mapping access as well
as named attribute access based on the lower-cased column names read from
cursor.description.
Rows created by this factory are mutable.
Example:
from mx.ODBC.iODBC import RowFactory
cursor.rowfactory = RowFactory.NamespaceeRowFactory
cursor.execute('select x, Y, z from mytable')
row = cursor.fetchone()
print (row[0], row[1], row[2])
print (row.x, row.y, row.z)
print (row['x'], row['y'], row['z'])
row[0] = 10
row[1] = 'abc'
print (row[:2])
# will print [10, 'abc']
row.x = 20
row.y = 'def'
print (row[:2])
# will print [20, 'def']
row['x'] = 30
row['y'] = 'ghi'
print (row[0], row[1])
# will print [30, 'ghi']
The row objects are also usable as input for the cursor.execute*()
methods.
Example:
cursor.execute('insert into mytable values (x, Y, z)', row)
All factories create row classes on-the-fly, based on cursor.description.
84