简体   繁体   中英

Python cx_Oracle prepared statement with qmark

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 ?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM