python - Python/SQL 错误,错误未注册
问题描述
所以我同时在自学 sqlite3 和 python,我遇到了问题,但没有出错,所以我不知道我做错了什么。当我运行程序时,一切似乎都很好。它询问我的问题,接受输入,并结束与数据库的连接。
当我返回并检查表中的数据时,问题就来了,并且没有任何更新。我认为问题出在我的 UPDATE sql 执行上,但我找不到错误。
import sqlite3 #import the sqlite3 library
conn = sqlite3.connect('trailer.db') ##establish connection to the database
c = conn.cursor() ##set var c to connected cursor
def path():
user_selection = input("Are you changing a trailer status(1) or updating driver info(2)")
if user_selection == "1":
update_trailer()
else:
update_driver()
def update_trailer():
n = int ( input("Enter the trailer number: "))
l = input ("Where is the trailer located: ")
s = input ("What is the current trailer status: ")
updated_data = "UPDATE data SET location = ?, status = ? WHERE id = ?"
utd = (l, s, n)
c.execute(updated_data, utd)
conn.commit()
conn.close()
#def update_driver():
# n2 = int ( input ("Which trailer are we updating? "))
#c = input ("Where was the gas used or filled? ")
# d = input ("Which driver is picking up the trailer? ")
# des = input ("Where is the trailer destination? ")
path()
(忽略 update_driver 部分,它正在进行中)
解决方案
男人,我觉得很愚蠢。我以前有一个用于将预告片输入数据库的 python 脚本,然后在一个单独的 .py 页面上工作以更新所述预告片,并使用我以前没有输入的一个数据条目。感谢所有的帮助。
答:代码有效,用户错误。必须更新已插入数据库的 ID。
推荐阅读
- angular - Chatwindow 不会使用 signalr + angular + .net core 更新来自其他用户的回复消息
- python - tensorflow 2.0版本如何实现tensorflow 1.0的make_one_shot_iterator()函数?
- flutter - Flutter中如何将多个参数传递给调用SfCalender的onTap的函数?
- javascript - 在下一个路由调用中,在一个处理函数中的请求对象上设置的值丢失(未定义)
- python - 如何在 /accounts/register 处修复 UnboundLocalError
- php - 如何根据从另一个外键/ Laravel 6显示的外键显示表格
- python - Jupyter Notebook 500 内部服务器错误属性错误模块“打字”没有属性“AsyncGenerator”
- azure - 如何在 Azure Function 的 EventHubTrigger 连接字符串中为本地环境设置代理
- python - 用于在 python 中循环时匹配字母、数字和特殊章程的正则表达式
- python - 根据 df1 中的值在 df2 中保留一列