473,491 Members | 2,221 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Getting column names from a cursor using ODBC module?

Is there any way to retrieve column names from a cursor using the ODBC
module? Or must I, in advance, create a dictionary of column position
and column names for a particular table before I can access column
values by column names? I'd prefer sticking with the ODBC module for
now because it comes standard in Python.

I'm using Python 2.4 at the moment.

Thanks.
Jun 27 '08 #1
5 8283
On Jun 21, 11:58 pm, dana...@yahoo.com wrote:
Is there any way to retrieve column names from a cursor using the ODBC
module? Or must I, in advance, create a dictionary of column position
and column names for a particular table before I can access column
values by column names? I'd prefer sticking with the ODBC module for
now because it comes standard in Python.

I'm using Python 2.4 at the moment.

Thanks.
Jun 27 '08 #2
On Jun 21, 11:58 pm, dana...@yahoo.com wrote:
Is there any way to retrieve column names from a cursor using the ODBC
module? Or must I, in advance, create a dictionary of column position
and column names for a particular table before I can access column
values by column names? I'd prefer sticking with the ODBC module for
now because it comes standard in Python.

I'm using Python 2.4 at the moment.
Do you mean the odbc module? If so, it doesn't come standard in
Python; it's part of the win32 package.

I haven't used it for years -- my preference on Windows these days
would be mxODBC if the client would pay the licence fee, otherwise
pyodbc. Sorry I'm not answering your question ... perhaps you should
be asking a different question :)

Cheers,
John
Jun 27 '08 #3
On Jun 22, 12:19 am, John Machin <sjmac...@lexicon.netwrote:
On Jun 21, 11:58 pm, dana...@yahoo.com wrote:
Is there any way to retrieve column names from a cursor using the ODBC
module? Or must I, in advance, create a dictionary of column position
and column names for a particular table before I can access column
values by column names? I'd prefer sticking with the ODBC module for
now because it comes standard in Python.
I'm using Python 2.4 at the moment.

Do you mean the odbc module? If so, it doesn't come standard in
Python; it's part of the win32 package.

I haven't used it for years -- my preference on Windows these days
would be mxODBC if the client would pay the licence fee, otherwise
pyodbc. Sorry I'm not answering your question ... perhaps you should
be asking a different question :)

Cheers,
John
But to help you answer your question: if the module that you are using
supports the 2.0 version of the database API (see http://www.python.org/dev/peps/pep-0249/),
then it will support the cursor.description attribute, which gives you
not only the name but the type and 5 other bits of info about each
column. If it doesn't, I'd suggest moving on.

HTH,
John
Jun 27 '08 #4
On Jun 21, 3:58*pm, dana...@yahoo.com wrote:
Is there any way to retrieve column names from a cursor using the ODBC
module? Or must I, in advance, create a dictionary of column position
and column names for a particular table before I can access column
values by column names? I'd prefer sticking with the ODBC module for
now because it comes standard in Python.

I'm using Python 2.4 at the moment.

Thanks.
You should be able to do

column_names = [d[0] for d in cursor.description]
Jun 27 '08 #5
Thanks Chris and John. Chris, this worked perfectly with the ODBC
module that ships with Python Win32:
column_names = [d[0] for d in cursor.description]
John, I've never heard of pyodbc but I'll have to look into it.

Thanks again.

Dana

Jun 27 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2631
by: Robert Ferber | last post by:
Hi, I can't find any good documentation about the Python-database module, all I found was this rudimentary (no examples, no references) piece here: http://www.python.org/peps/pep-0249.html ...
15
3801
by: Philip Mette | last post by:
I am begginner at best so I hope someone that is better can help. I have a stored procedure that updates a view that I wrote using 2 cursors.(Kind of a Inner Loop) I wrote it this way Because I...
4
1857
by: s99999999s2003 | last post by:
hi the database "execute" function returns a list of logical results. Each logical result is a list of row tuples, as explained in the documents. everytime i use it to execute various...
2
23871
by: Joe | last post by:
Hi All, I am new to using the Access DB and I need some help if someone is able to give it to me. What I want to do is get the names of the columns of certain tables. Not the data in the table...
3
3137
by: ssb | last post by:
Hello, This may be very elementary, but, need help because I am new to access programming. (1) Say, I have a column EMPLOYEE_NAME. How do I fetch (maybe, cursor ?) the values one by one and...
1
1798
by: Larry Bird | last post by:
I've created a AlertDataClass below within the class I have tables and column that I've create. In the AlertDataAccess class I'm trying to insert data into my tables. AlertDataAccess is a Module...
0
2941
by: Mythran | last post by:
I wrote some code that is supposed to enumerate through the specified file's win32 resources and return a string-array of all icon names. When it runs, it returns a string-array with a bunch of...
6
17345
by: A.M | last post by:
Hi I use a code similar to this to retrieve data from Oracle database: import cx_Oracle
0
3962
by: jeoffh | last post by:
Background: I am trying to "merge" some attributes into an existing XML column in my MS SQL 2005 database. The general idea is that I have an XML column in a table and I would like to update/delete...
0
7154
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6858
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7360
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5451
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4881
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3086
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3076
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
633
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
280
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.