[英]SQLITE not inserting data on executemany
I am inserting a tuple of 2 column data.我正在插入一个 2 列数据的元组。 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.如果我用 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)
confused why if it returns from the cursor connection why DB Browser for SQLITE or DBeaver cannot see any data in my table.困惑为什么如果它从游标连接返回,为什么 DB Browser for SQLITE 或 DBeaver 看不到我的表中的任何数据。 Is the data really there or is the connection "holding data" somehow.数据是真的存在还是以某种方式“保存数据”的连接。
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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.