我正在插入2列数据的元组。我的插入没有收到任何错误,但是我看不到数据库中的数据。
我的数据
output = ((5153419, 5178566), (5153419, 5178568), (5153419, 5178565), (5153419, 5178562), (5153419, 5178567), (5153419, 5178563), (5153419, 5178561), (5153419, 5178564))
只需在一个表数据库中进行基本插入即可。
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")
如果我使用fetchall检查数据返回的数据。
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)
感到困惑的是,如果它从游标连接返回,为什么DB Browser for SQLITE或DBeaver无法在我的表中看到任何数据。 数据确实存在吗?或者连接“保持数据”是否存在。
答案 0 :(得分:0)
在代码末尾添加提交。
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()