rajeshveerepalli / pyodbc

Automatically exported from code.google.com/p/pyodbc
MIT No Attribution
0 stars 0 forks source link

pyodbc db2 row object not showing colnames as fields #197

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
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

Original issue reported on code.google.com by locojay...@gmail.com on 11 Aug 2011 at 1:05

GoogleCodeExporter commented 8 years ago
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.

Original comment by mkleehammer on 11 Aug 2011 at 1:19

GoogleCodeExporter commented 8 years ago
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.

Original comment by locojay...@gmail.com on 11 Aug 2011 at 1:43

GoogleCodeExporter commented 8 years ago

Original comment by mkleehammer on 13 Sep 2011 at 11:15