pyodbc AccessDB TypeError: ('Params must be in a list, tuple, or Row', 'HY000')

本小妞迷上赌 提交于 2019-12-11 16:44:39

问题


Running Python 3.7.2 32 bit on Windows 7 and using pyodbc package 4.0.25-cp27 32bit

I have tried multiple ways of passing through the params and keep getting the above error:

TypeError: ('Params must be in a list, tuple, or Row', 'HY000')

my inputfile is a txt file containing this:

TEST ,EU ,Totals , 30, 0.61, 0.00000000,GOLD ,01/03/2019,   
TEST ,EU ,SubTotals , 40, 0.63, 0.00000000,GOLD ,01/03/2019,

A few versions:

qry = """INSERT INTO newtable ([Col1], [Col2], [Col3], [Col4], [Col5], [Col6], [Col7], [Col8]) VALUES (?,?,?,?,?,?,?,?);"""  

with open (inputfile, "r") as afile:  
    for line in afile:  
        params = tuple(line.split(','))  
        cursor.executemany(qry, params)  
conn.commit()  

for the params value also tried:

params = list(line.split(','))

Also tried inserting all values into the list one by one:

params = list(line.split(","))  
a = params[0]  
b = params[1]  
c = params[2]  
d = params[3]   
e = params[4]  
f = params[5]  
g = params[6]  
h = params[7]  
dbparams = [a,b,c,d,e,f,g,h]   
cursor.executemany(qry,dbparams) 

回答1:


cursor.execute(qry, params[0:8]) worked

The executemany was causing the error - params must be in list, tuple or row

and without the [0:8] the list was passing through a '\n' at the end of the list causing the error - the SQL contains 8 parameter markers, but 9 parameters were supplied

Winning answer was:

cursor.execute(qry, params[0:8]) worked

thanks to @gordthompson for his prompt



来源:https://stackoverflow.com/questions/55024559/pyodbc-accessdb-typeerror-params-must-be-in-a-list-tuple-or-row-hy000

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!