× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



I really shouldn't have brought it up. It is specifically asking as a beginner, and we should encourage the use of the two you list below. I meant the old ibm_db module. This works, but I would never use it. Last line should be indented. I went looking for an example, and even all my old test programs have been converted to dbi. As you say below, one of the two reasonable choices.

#!/usr/bin/env python3

import ibm_db as db2

query = "select cusnum, lstnam as Last_Name, init, cdtlmt, qc.* from qiws.qcustcdt qc where cdtlmt > 100"

conn = db2.connect("*LOCAL","validusername","validpassword");
statement = db2.prepare(conn,query)
db2.execute(statement)
cols = db2.num_fields(statement)
for i in range(0,cols):
print(db2.field_name(statement,i))

On Mon, 2021-12-06 at 12:02 -0500, John Yeung wrote:
On Mon, Dec 6, 2021 at 8:31 AM Kevin Bucknum <Kevin@xxxxxxxxxxxxxxxxxxx<mailto:Kevin@xxxxxxxxxxxxxxxxxxx>> wrote:

Here is another way if you use the dbi connector. I think there is something similar for the db2 one.

Not sure which one you mean when you say "the db2 one". There are
basically two reasonable choices for connecting to the built-in
database on the IBM i (that is, the QSYS.LIB stuff) from Python. One
is ibm_db_dbi, which is a module within the ibm_db package. The other
is pyodbc. Both ibm_db_dbi and pyodbc provide an interface conforming
to PEP 249:

https://www.python.org/dev/peps/pep-0249/

conn = db2.connect()
cur = conn.cursor()
cur.execute(query)

for column_variable in cur.description:
column_name = column_variable[0]
print(column_name)

The `description` attribute of the cursor object is one of the things
specified by PEP 249; it's not specific to ibm_db_dbi.

It's a good thing to be aware of, because if you just need the column
name or simple type information, then `description` is probably the
easiest way to get it.

If, like OP, you want the DDS column headings, then you have to look elsewhere.

John Y.

[https://www.medtronsoftware.com/img/MedtronMinilogo.bmp]
Kevin Bucknum

Senior Programmer Analyst

MEDDATA / MEDTRON

120 Innwood Drive
Covington LA 70433
Local: 985-893-2550<tel:985-893-2550>
Toll Free: 877-893-2550<tel:877-893-2550>
https://www.medtronsoftware.com


CONFIDENTIALITY NOTICE

This document and any accompanying this email transmission contain confidential information, belonging to the sender that is legally privileged. This information is intended only for the use of the individual or entity named above. The authorized recipient of this information is prohibited from disclosing this information to any other party and is required to destroy the information after its stated need has been fulfilled. If you are not the intended recipient, or the employee of agent responsible to deliver it to the intended recipient, you are hereby notified that any disclosure, copying, distribution or action taken in reliance on the contents of these documents is STRICTLY PROHIBITED. If you have received this email in error, please notify the sender immediately to arrange for return or destruction of these documents.

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.