[英]Python error updating a SQL DB
I have some python code that looks like this 我有一些看起来像这样的python代码
import pypyodbc
import pandas as pd
home="c:/SQL/"
df = pd.read_sql_query(sql4, conn3
for y1 in range(0 , k):
ARCHIVE_SERNUM = (df['sernum']).iloc[y1]
KQL=len(KIC53_QUERY_LIST)
FOUND=False
for y2 in range(0,KQL):
if ARCHIVE_SERNUM == KIC53_QUERY_LIST[y2]:
FOUND=True
#do something then
break
if FOUND == False:
print(FOUND,ARCHIVE_SERNUM,"This is STIME : ",STIME)
CTIME=STIME
cursor = conn3.cursor()
cursor.execute("""
UPDATE ENCOMPASS_DIA
SET CTIME=%s
WHERE SERNUM=ARCHIVE_SERNUM
""", (STIME))
Its throwing an error and I cannot figure out what is going on. 它抛出一个错误,我无法弄清楚是怎么回事。 In this example both CTIME and STIME are equal to the same 17 character string.
在此示例中,CTIME和STIME都等于相同的17个字符串。
File "c:/SQL/ConnectionTest8.py", line 212, in <module>
""", (STIME))
TypeError: Params must be in a list, tuple, or Row
An easy enough mistake to make. 一个容易犯的错误。
cursor.execute("""
UPDATE ENCOMPASS_DIA
SET CTIME=%s
WHERE SERNUM=ARCHIVE_SERNUM
""", (STIME, ))
There should be a trailing ,
after the STIME
or (STIME) will be interpreted as a list instead of a tuple. 应该有一个结尾
,
后STIME
或(STIME)将被解释为一个列表,而不是一个元组。
在这种情况下,正确的Update语句是:
cursor.execute("""UPDATE ENCOMPASS_DIA SET CTIME=? WHERE SERNUM=?""", (SSTIME,ARCHIVE_SERNUM ))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.