Python cx_Oracle prepared statement with qmark

梦想的初衷 提交于 2019-12-25 08:59:53

问题


I am trying to work with cx_Oracle, but it seems to dislike what I know about db-api.

These statement work:

cur.execute('INSERT INTO "testdboz" ("id", "sessionid") VALUES (2, 123)')
cur.execute('INSERT INTO "testdboz" ("id", "sessionid") VALUES (:id, :sid)', 
            {'id':1, 'sid':13})
cur.execute('INSERT INTO "testdboz" ("id", "sessionid") VALUES (:1, :2)', [1123, 123])

However, this fails:

cur.execute('INSERT INTO "testdboz" ("id", "sessionid") VALUES (?, ?)', [1, 123])

The above fails with:

---------------------------------------------------------------------------
DatabaseError                             Traceback (most recent call last)
<ipython-input-17-4e9fe350f968> in <module>()
----> 1 cur.execute('INSERT INTO "testdboz" ("id", "sessionid") VALUES (?, ?)', [1, 123])

DatabaseError: ORA-01036: illegal variable name/number

Is there a way to correct this statement? Does cx_Oracle suppprt qmark?


回答1:


Sadly, I found an answer here...

You can't truly choose what paramstyle you would like to use. Oracle only natively supports named and numeric paramstyles and cx_Oracle supports both of those.



来源:https://stackoverflow.com/questions/23829828/python-cx-oracle-prepared-statement-with-qmark

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