Answers for "access sqlite db python"

1

access sqlite db python

import sqlite3

#Connection to the DB
conn = sqlite3.connect('sqlite.db')

# Execute query on the sqlite DB
cur = conn.cursor()
cur.execute("SELECT * FROM tasks")

# Print everything from a table
rows = cur.fetchall()
for row in rows:
        print(row)
    
# Update field 
conn.execute("""UPDATE tasks SET name = \'jhon\'
 where id = 1""")

# close the DB connection 
conn.close()
Posted by: Guest on May-02-2022

Python Answers by Framework

Browse Popular Code Answers by Language