3

i have a stored procedure that contains multiple statements simplified as below

create temp table...; 
update temp table...; 
....
select * from temp table; #last statement

I have below Python code to get return results from the SP. I need the column names so that I can convert the results into JSON format. However, cursor.description returns nothing I expect. Advise please!! Mysql5.7, mysql-python-connector 2.x by Oracle, python 3.5

cursor.callproc(proc, args)
columns = cursor.description
print(columns) #returns [('@_sp_get_toc_arg1', 8, None, None, None, None, 1, 128)]

for result in cursor.stored_results():
    return result.fetchall()
Dustin Sun
  • 4,776
  • 6
  • 45
  • 82

1 Answers1

2

The iterator returned by cursor.stored_results() yields cursors, you'll need to inspect the description of those to get the column names, not of the initial cursor:

for result in cursor.stored_results():
    print(result.description)
    return result.fetchall()
mata
  • 63,859
  • 10
  • 155
  • 155
  • hi, mata. what if i wanted to fetchall all results/data and not just column headers from pyodbc? https://stackoverflow.com/questions/72209641/how-do-i-read-sql-stored-procedure-data-through-pyodbc-and-get-results-into-a-da – Joe Tha May 12 '22 at 15:57