Issue 197: pyodbc db2 row object not showing colnames as fields
Status:  NoFix
Owner: ----
Closed:  Sep 2011
Reported by locojay...@gmail.com, Aug 10, 2011
What steps will reproduce the problem?
1. import pyodbc
conn=pyodbc.connect('DSN=db;UID=xx;PWD=xxx')
cursor=conn.cursor()
cursor.execute('select id,name from test.test')
row = cursor.fetchone()
print row >> (211841, 'test')
print row.id or print row.name
'pyodbc.Row' object has no attribute 'id'

What is the expected output? What do you see instead?
wiki show's that Row object should have columnames as fields.

the only thing i can do is use
row.cursor_description
and create a Wraper which would generate a dict
What version of the product are you using? On what operating system?
pyodbc.version
 '2.1.9'
DB2 client under osx lion 10.7
did build against unixodbc ( would be great to have a better setup.py to detect that unixodbc is installed)
i prefer to use unixodbc as it is available via brew

Please provide any additional information below:

i switched to pyodbc since ibm_db python does not work on osx 10.7


Aug 10, 2011
Project Member #1 mkleehammer
I am pretty sure that this is working, but that the case isn't matching.  The library uses the column names that are returned from the database, so they may not match your input SQL exactly.  For example, you may use "select id, name ..." but the database may return the columns "ID" and "NAME".  The way to find out is to print cursor_description.

If they also show lowercase values, then please provide the results.  Also provide the results of this:
  print repr(cursor.description[0][0])

If they are upper or mixed case and you do not want that (I never do), set pyodbc.lowercase = True before you connect.  All connections created after that will force column names in results to lowercase.

I'll put this into Investigating state until I get more information.


Status: Investigating
Aug 10, 2011
#2 locojay...@gmail.com
my bad they where upper case.
pyodc.lowecase = True is the way to go.

just moved to pyodbc as ibm_db is not supported anymore under osx 10.7 .

I will have a look at distutils to detect unixodbc without adding include and compile flags manually and
do pull request on github.

Thanks.
Sep 13, 2011
Project Member #3 mkleehammer
(No comment was entered for this change.)
Status: NoFix