I am running a simple query and converting results to json. I would like to do this dynamically so I can use one function to handle all queries.
query = "INSERT INTO Tests (name, start, end) VALUES (?, ?, ?)"
params = (name, start, end)
conn = sqlite3.connect('settings.db')
cur = conn.cursor()
cur.execute(query, params)
conn.commit()
rows = cur.fetchall()
I am getting column names by using cursor.description but I also need the table names to achieve json structure like below:
{ status: 'success', tests: [ name: 'sample', 'start': '8484', 'end': '9054' ], [ name: 'sample2', 'start': '84842', 'end': '90542' ] }
Is there a reasonable way to achieve this?
Here is a method to get the table names from your database connection. I hope that it is useful for you.
for more info: https://sqlite.org/faq.html#q7