首页 > 解决方案 > 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 部分,它正在进行中)

标签: pythonsqldatabasesqlite

解决方案


男人,我觉得很愚蠢。我以前有一个用于将预告片输入数据库的 python 脚本,然后在一个单独的 .py 页面上工作以更新所述预告片,并使用我以前没有输入的一个数据条目。感谢所有的帮助。

答:代码有效,用户错误。必须更新已插入数据库的 ID。


推荐阅读