【发布时间】:2012-01-29 20:54:38
【问题描述】:
我正在尝试从Python 代码将新记录插入SQLite 数据库。
con = sqlite.connect(connectionString)
cur = con.cursor()
countOfNewItems = 0
for ...
try:
con.execute("insert or ignore into items ...")
countOfNewItems += cur.rowcount
except:
cur.close()
con.close()
print "Error when inserting item '%s' to database." % item
exit(1)
cur.close()
con.commit()
con.close()
print "%d new items have been inserted." % countOfNewItems
我的代码报告插入记录数为负数 (-5141)。
因为我的数据库是空的,所以我可以通过命令行查看插入了多少条记录
select count(*) from items;
4866
你能告诉我有什么问题吗?为什么这两个值不匹配,为什么是负数?
【问题讨论】:
标签: python sqlite insert rowcount