This is more a python question than anything specific to the IBMi ...

Most of my experience is with VBA and ODBC. With those, I would access data by ...

Dim DBConn As New ADODB.Connection
DBConn.Open "<connection string here>"
SQL = "SELECT something FROM somewhere"
Set RS = DBConn.Execute(SQL)
someDBData = RS.Fields(0).Value

So, now I'm using Python with ODBC and trying to figure out how to do similar to above. However, there seems to be no equivalent to 'RS.Fields(0).Value?

Internet searching revealed this as the way to put it into a dictionary for easy access (this is the function I wrote to try it out and it does work) ...
def get_arinv_data(start_date, end_date):
#get data
sql = '''select <some stuff>
from <some file>
where somedate between '{0}' and '{1}' ''' .format(start_date.strftime('%Y-%m-%d'),end_date.strftime('%Y-%m-%d'))
cursor.execute(sql)

#place returned data in dictionary
arinv_columns = [column[0] for column in cursor.description]
arinv_data = []
for arinv_row in cursor.fetchall():
arinv_data.append(dict(zip(arinv_columns, arinv_row)))

return arinv_data

Is this really the way? Is there nothing as simple as just accessing the fields directly of a returned recordset?

--
Quintin

NOTICE – this email and any attached file (“Information”) may contain technical data subject to the U.S. International Traffic in Arms Regulation (“ITAR”) 22 CFR parts 120-130. The Information may not be shared with any Foreign Person, as that term is defined in ITAR. The Information is sent only for the use of the intended recipient and may contain legally privileged and/or confidential information. If you are not the intended recipient, you are notified that any dissemination or copying of the Information is prohibited. If you received the Information in error you must notify the sender immediately and destroy the Information without printing or saving it.

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

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

This mailing list archive is Copyright 1997-2022 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.