python sqlite3插入仅在控制台中起作用

发布于 2025-02-03 07:03:59 字数 510 浏览 3 评论 0原文

我在sqlite3中有一个简单的插入语句,但是python版本不起作用,但同一语句在控制台中效果很好。 Python没有显示任何插入错误。关于如何在Python中修复此插入语句的任何建议吗?

插入语句:

插入设施(facitial_id,facity_name)值('239Sie39','大厅A');

表创建语句:

创建表格(如果不存在)(ID Integer主密钥自动启动唯一唯一唯一) ,facity_id,facity_name)

函数存储数据:

def store_data(table_name: str, rec: dict):
  keys = ','.join(rec.keys())
  values = tuple(rec.values())
  stmt = f"INSERT INTO {table_name} ({keys}) VALUES {values}"
  cur.execute(stmt)

I have a simple insert statement in sqlite3, but somehow the python version doesn't work, but the exact same statement works fine in console. And python doesn't show any insert error. Any suggestion on how to fix this insert statement in python?

Insert statement:

INSERT INTO facilities (facility_id,facility_name) VALUES ('239SIE39', 'Lobby A');

Table creation statement:

CREATE TABLE IF NOT EXISTS facilities (id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, facility_id, facility_name)

Function to store data:

def store_data(table_name: str, rec: dict):
  keys = ','.join(rec.keys())
  values = tuple(rec.values())
  stmt = f"INSERT INTO {table_name} ({keys}) VALUES {values}"
  cur.execute(stmt)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文