SQLite: Difference between revisions

Jump to navigation Jump to search
Line 23: Line 23:
# to access an SQLite database
# to access an SQLite database
import sqlite3
import sqlite3
age = 34


# Connect to the database...
# Connect to the database...
dbase = sqlite3.connect("foo.sqlite")
dbase = sqlite3.connect("foo.sqlite")


# A parameterized query with a cursor for processing the output
dbase.execute("INSERT INTO employee(name,age) VALUES(\"John Smith\"," + str(age) + ");")
crs = dbase.cursor()
params = ("employees",)
crs.execute("SELECT * FROM ?;",params)
rows = crs.fetchall()
for r in rows:
    print(r)


# Close the database connection
# Close the database connection
Bureaucrats, cc_docs_admin, cc_staff
2,318

edits

Navigation menu