admin管理员组文章数量:1277899
I'm trying to migrate from cx_Oracle 8.1.0
to oracledb 2.5.1
library. Before such query was working:
update command_center set
E_ID = :1,
E_ASPECTS = :2,
E_CREATED_TIMESTAMP = :3
WHERE e_id = :1
def bulk_insert_or_update_data_to_targets(self, sql, target_data, id_index=0):
for target_connections, data in target_data:
for con in target_connections:
cursor = con.cursor()
cursor.executemany(sql, data, batcherrors=True)
if cursor.getbatcherrors():
self.logger.debug("data: " + str(data))
cursor.close()
but currently I have following exception:
oracledb.exceptions.DatabaseError: DPY-4009: 4 positional bind values are required but 3 were provided
Is there any chance this could work the same way it worked in cx_Oracle
before ... so I guess it retrieved the attribute by array index?
I'm trying to migrate from cx_Oracle 8.1.0
to oracledb 2.5.1
library. Before such query was working:
update command_center set
E_ID = :1,
E_ASPECTS = :2,
E_CREATED_TIMESTAMP = :3
WHERE e_id = :1
def bulk_insert_or_update_data_to_targets(self, sql, target_data, id_index=0):
for target_connections, data in target_data:
for con in target_connections:
cursor = con.cursor()
cursor.executemany(sql, data, batcherrors=True)
if cursor.getbatcherrors():
self.logger.debug("data: " + str(data))
cursor.close()
but currently I have following exception:
oracledb.exceptions.DatabaseError: DPY-4009: 4 positional bind values are required but 3 were provided
Is there any chance this could work the same way it worked in cx_Oracle
before ... so I guess it retrieved the attribute by array index?
2 Answers
Reset to default 1- Enable 'thick mode', see https://python-oracledb.readthedocs.io/en/latest/user_guide/initialization.html#enabling-python-oracledb-thick-mode
- Use named bind variables, instead of bind-by-position.
The latter is preferred because it doesn't run into the kind of issue you see. Even Thick mode has some variances with bind-by-position that depend if you are using SQL or PL/SQL statements.
I think the problem may be due to using :1
twice in the query.
You don't need E_ID = :1
in the SET
clause, since you're setting the column to the same value it already has (because of WHERE E_ID = :1
). So remove that:
update command_center set
E_ID = :1,
E_ASPECTS = :2,
E_CREATED_TIMESTAMP = :3
WHERE e_id = :1
本文标签: pythonbind parameters by array indexStack Overflow
版权声明:本文标题:python - bind parameters by array index - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741255609a2366613.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论