我有一些执行到SQL服务器的python脚本。错误日志显示在这个sqlInsrt()函数中发生了一些事情。错误是:
pypyodbc.DatabaseError: ('07002', '[07002] [Microsoft][ODBC SQL Server Driver]COUNT field incorrect or syntax error')
有人能解释一下这里可能出了什么问题吗?我以前也遇到过类似的SQL错误,例如(#预期的参数,给定的参数)
功能如下
def sqlInsrt(headers, values):
#create string input of mylisth
strheaders = ','.join(str(i) for i in headers)
#create string input of %s corresponding to number of entries in mylisth
placestr = ','.join(str(i) for i in ['?' for i in headers])
#Setup and execute SQL query
replacestr = ', '.join(['{}=?'.format(h) for h in headers])
insert = ("INSERT INTO capacitors ({strheaders}) VALUES ({placestr}) \
ON DUPLICATE KEY UPDATE {replacestr}").format(
strheaders=strheaders, placestr=placestr, replacestr=replacestr)
cursor.execute(insert, values*2)
cnx.commit()
strheader和placestr的长度相同吗? 看来你选错栏目了。你知道吗
相关问题 更多 >
编程相关推荐