fix this code. Retrieve Text for the open inquiry query = """SELECT iat.id as id,…
- User
fix this code.
Retrieve Text for the open inquiry
query = """SELECT iat.id as id, inquiry_id, file_name, file_ext FROM inquiry_attach_tbl iat LEFT JOIN inquiry_tbl it ON iat.inquiry_id = it.id WHERE raw_text IS NULL AND it.received_date > '20220901';"""
try: with connection.connect(**mydbconfig) as mydb: mycursor = mydb.cursor()
codemycursor.execute(query) query = mycursor.fetchone()except connection.Error as err: print({ 'error': { 'message': 'An error occurred while processing the query.', 'details': str(err), 'code': 500 } })
except Exception as e: print({ 'error': { 'message': 'An unexpected error occurred.', 'details': str(e), 'code': 500 } })
this gives me one row of the query. i want all rows
- Assistant
To retrieve all rows of the query, you can modify the code as follows:
python# Retrieve Text for the open inquiry query = """SELECT iat.id as id, inquiry_id, file_name, file_ext FROM inquiry_attach_tbl iat LEFT JOIN inquiry_tbl it ON iat.inquiry_id = it.id WHERE raw_text IS NULL AND it.received_date > '20220901';""" try: with connection.connect(**mydbconfig) as mydb: mycursor = mydb.cursor() mycursor.execute(query) result = mycursor.fetchall() for row in result: print(row) except connection.Error as err: print({ 'error': { 'message': 'An error occurred while processing the query.', 'details': str(err), 'code': 500 } }) except Exception as e: print({ 'error': { 'message': 'An unexpected error occurred.', 'details': str(e), 'code': 500 } }) - User
[(19867, 71148, 'ThaoNguyenPEDDOC-MOA-JimDavis001_MW.pdf', None), (19871, 71148, 'ThaoNguyenFormPEDDOC-L-CC-002.pdf', None), to a df
- Assistant
To convert the query result to a pandas DataFrame, you can use the
fetchall()method to retrieve all the rows and then pass the results to theDataFrameconstructor. Here's the updated code:python