I just started learning SQLite3 for python today, and I'm having trouble figuring out why this won't work.
import sqlite3, os
if not os.path.isfile("G:\\Python\\My first database.db"):
dtabse = sqlite3.connect("G:\\Python\\My first database.db")
cursr = dtabse.cursor()
cursr.execute("""CREATE TABLE Students
(first_name text,
surname text,
DOB text,
Form text)
""")
cursr.execute(""" INSERT INTO Students
VALUES ("Dave", "Edwards", "16", "11AB")""")
dtabse.commit()
dtabse.close()
else:
dtabse = sqlite3.connect("G:\\Python\\My first database.db")
cursr = dtabse.cursor()
print(cursr.fetchall())
In a powerpoint I was viewing, it said fetchall() should retrieve everything and display it. On the first go of this program it won't find a file in this directory, so the if area gets executed. When I next run the program the else area gets executed.
That much works, on the first go the program ends and begins. On the second go it prints an empty list, when I was expecting the table. I checked the database file and the data is there, so why can't I print it?