Reputation: 7048
I am inserting a tuple of 2 column data. I receive no errors from my insert however I cannot see data in my database.
My data
output = ((5153419, 5178566), (5153419, 5178568), (5153419, 5178565), (5153419, 5178562), (5153419, 5178567), (5153419, 5178563), (5153419, 5178561), (5153419, 5178564))
Just doing a basic insert into a one table database.
connection = sqlite3.connect("test_database.db")
c = connection.cursor()
c.execute("DROP TABLE IF EXISTS Meeting")
c.execute("CREATE TABLE Meeting(MeetingID INT, RaceID INT)")
c.executemany("INSERT INTO Meeting VALUES(?,?)", output)
c.execute("SELECT MeetingID, RaceID from Meeting")
If I check data with fetchall data returns.
for row in c.fetchall():
print(row)
## Output
[saythrenshaw@localhost racing]$ /usr/bin/python3 /home/saythrenshaw/racing/parse_nsw.py
(5153419, 5178566)
(5153419, 5178568)
(5153419, 5178565)
(5153419, 5178562)
(5153419, 5178567)
(5153419, 5178563)
(5153419, 5178561)
(5153419, 5178564)
confused why if it returns from the cursor connection why DB Browser for SQLITE or DBeaver cannot see any data in my table. Is the data really there or is the connection "holding data" somehow.
Upvotes: 1
Views: 1112
Reputation: 41
Add a commit at the end of your code.
connection = sqlite3.connect("test_database.db")
c = connection.cursor()
c.execute("DROP TABLE IF EXISTS Meeting")
c.execute("CREATE TABLE Meeting(MeetingID INT, RaceID INT)")
c.executemany("INSERT INTO Meeting VALUES(?,?)", output)
c.execute("SELECT MeetingID, RaceID from Meeting")
connection.commit()
Upvotes: 1