Select sqlite queries

From TRCCompSci - AQA Computer Science
Jump to: navigation, search

You need to ensure you have followed the tutorial to create a database connection.

Python Code

The 'create', 'update', 'insert', and 'delete' queries only require execution, however the 'select' query needs to return values. So add the following

def select_query(conn, sql):

    cur = conn.cursor()
    cur.execute(sql)
 
    rows = cur.fetchall()
 
    for row in rows:
        print(row)

you can therefore run:

select_query("Select * from table")