使用 pyodbc 将 arraylist 作为参数传递给 INSERT 数据到 Ignite 缓存时出错

Error while passing arraylist as argument to INSERT data into Ignite cache using pyodbc

我编写了以下代码,使用 ODBC 驱动程序将数据从 python 插入到 Ingite 缓存中。在此想要传递字符串数组列表(id_list)作为参数。 我的列表包含可变数量的元素,这就是为什么我需要将其作为参数传递给查询的原因。

cursor = connection.cursor()
select_string= "INSERT INTO Person (_key, id,  firstName, lastName, salary) VALUES (322, ? , 'abcd', 'dhsagd', 1000)"

id_list = ['test1', 'test2', 'test3', 'test4']
cursor.execute(select_string, id_list)

但是当我将字符串列表作为参数传递给查询时,出现以下错误。

Traceback (most recent call last):
  File "pythonOdbclist.py", line 13, in <module>
    cursor.execute(select_string, id_list)
pyodbc.ProgrammingError: ('The SQL contains 0 parameter markers, but 4 parameters were supplied', 'HY000')

根据文档,参数应作为单个值或元组传递:https://github.com/mkleehammer/pyodbc/wiki/Cursor#executesql-parameters。在此示例中,您是否尝试 executemany 插入四行?

https://github.com/mkleehammer/pyodbc/wiki/Cursor#executemanysql-paras

cursor = connection.cursor()
select_string= "INSERT INTO Person (_key, id,  firstName, lastName, salary) VALUES (322, ? , 'abcd', 'dhsagd', 1000)"

id_list = [('test1',), ('test2',), ('test3',), ('test4',)]
cursor.executemany(select_string, id_list)