I am a little lost in something I am trying to do. Learning how to run sql within Python.
I have a db in in Python sqlite with three tables 1, 2, 3.
I then have a series of several queries I have written in a .sql file.
I have a loop created, but I am missing a step to read and execute the sql file.
# For each of the 3 tables, query the database and print the contents
for table in ['1', '2', '3']:
# Plug in the name of the table into SELECT * query
result = c.execute("SELECT * FROM %s;" % table);
# Get all rows.
rows = result.fetchall();
# \n represents an end-of-line
print "\n--- TABLE ", table, "\n"
My sql queries are written in a separate .sql file called queries.sql. Where do I put it in the loop?