oracle / python-cx_Oracle

Python interface to Oracle Database now superseded by python-oracledb
https://oracle.github.io/python-cx_Oracle
Other
889 stars 361 forks source link

how does cursor.execute handle being given another select query to execute, if its currently running a query already? #658

Closed imthenalls closed 7 months ago

imthenalls commented 1 year ago
  1. What versions are you using? cx_oracle -> 8.3.0 python -> 3.10.11 oracle db 12c Enterprise

  2. Describe the problem

I'm wondering about what happens in my code snippet below. Several tasks are provided to the run_in_executor function, so it runs several instances of the run_oracle_query() function one after another all on a single connection. So multiple cursors are opened and execute queries one after another on the same connection.

Does cx_oracle queue up queries if they are executed while another query is already being executed on the same connection?

3.

async def oracle_query(oracle_conn, query):
  loop = asyncio.get_running_loop()
  await loop.run_in_executor(None, run_oracle_query, oracle_conn, query)

def run_oracle_query(conn, query):
  cursor = conn.cursor()
  cursor.execute(query)
  results = cursor.fetchall()
  cursor.close()
anthony-tuininga commented 1 year ago

Oracle Database (all drivers, not just cx_Oracle) only allows for one operation to be performed on a connection at a time. So if you execute statements concurrently they are simply queued and run one at a time.

imthenalls commented 1 year ago

Thank you so much for the prompt answer, its very much appreciated! I knew that only one operation can be performed, just wasn't clear about the queuing part! I couldn't find anything about it in the documentation.

Again thank you and appreciate the work everyone puts into this :)

anthony-tuininga commented 1 year ago

You're very welcome! @priyankanair8 may be able to point you to such a location in our documentation for python-oracledb (the new name for cx_Oracle) or, if it is missing, can add a section discussing this. I'll let her comment when she is able.

priyankanair8 commented 1 year ago

Our current documentation for python-oracledb does not have the queuing information. I will work on adding this information to the doc. Thanks for pointing that out @imthenalls.

cjbj commented 7 months ago

Closing.