Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python SQLITE3 DB数据从同一表和同一行中的一个字段传输到另一个字段_Python_Sqlite - Fatal编程技术网

Python SQLITE3 DB数据从同一表和同一行中的一个字段传输到另一个字段

Python SQLITE3 DB数据从同一表和同一行中的一个字段传输到另一个字段,python,sqlite,Python,Sqlite,我试图将同一行中的数据从一个字段移动到另一个字段。 这是我的代码,但不适用于update语句: def update_ondemanddrama(Name): with sqlite3.connect("sky_ondemand.db") as db: cursor = db.cursor() sql = "update TVshowsDrama set SecLastEp=LastEp where Name=?" cursor.execu

我试图将同一行中的数据从一个字段移动到另一个字段。 这是我的代码,但不适用于update语句:

def update_ondemanddrama(Name):
    with sqlite3.connect("sky_ondemand.db") as db:
        cursor = db.cursor()
        sql = "update TVshowsDrama set SecLastEp=LastEp where Name=?"
        cursor.execute(sql, Name)
        db.commit()
作品 在python中运行此命令时出现的错误是:

Traceback (most recent call last):   File "C:\Users\ict\Downloads\skyondemandv1.py", line 65, in <module>
update_ondemanddrama(Name)   File "C:\Users\ict\Downloads\skyondemandv1.py", line 34, in
update_ondemanddrama cursor.execute(sql, Name) sqlite3.ProgrammingError: Incorrect number of bindings supplied. 
The current statement uses 1, and there are 5 supplied.
Traceback(最近一次调用):文件“C:\Users\ict\Downloads\skyondmandv1.py”,第65行,在
更新中第34行的“C:\Users\ict\Downloads\skyondemandv1.py”文件(名称)
更新命令游标。执行(sql,名称)sqlite3.ProgrammingError:提供的绑定数不正确。
当前语句使用1,提供了5个。

cursor.execute需要一个iterable。当您给它一个字符串时,execute将其视为一个5项可编辑(5个字符)。 将执行行更改为

cursor.execute(sql, (Name,))

非常感谢。这成功了!为什么它在一组额外的括号中与Name一起工作?我还是不太明白。带括号的参数是元组(名称),而不是字符串名称。当迭代第一个字符串时,得到一个字符串。当迭代第二个时,得到5个字符。现在我得到一个不同的错误,我确信程序的基础使用相同的逻辑。错误消息如下:回溯(最近一次调用):文件“”,第1行,在test()文件“G:/test.py”的第33行,在test update_temp3(value)name错误:未定义全局名称“value”。代码如下:导入sqlite3 def test():DayID=int(输入(“What's DayID?”)Day=input(“今天是几号?”)newTemp=input(“Enter temperature”)def update_temp3(value):使用sqlite3.connect(“temp.db”)作为db:cursor=db.cursor()sql=“更新表1 set temp3=Temp2,其中DayID=?”cursor.execute(sql,(value,))db.commit(),如果name=“main”:measure=(DayID,newTemp)更新\u temp3(值)更新\u temp2(值)插入\u数据(测量)
cursor.execute(sql, (Name,))