-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added description method for AsyncCursorWrapper. #20
base: main
Are you sure you want to change the base?
Conversation
Thank you for your PR. Can you briefly describe what you hope to achieve? Why the new add method is a subfunction under callproc, and why is this an async method, because it looks like it only runs synchronous logic. |
Hello. I am using this package in conjunction with pandas and need access to the column names from the database. The AsyncCursorWrapper seems to handle calls to the cx_Oracle cursor. The column names are accessed using the description property in the original cx_Oracle library. I am trying to expose this to get access to the column data. This is not intended to be a sub function to the callproc method, I do not know why it came out that way and can fix that. As for the async method, I was not sure of the timing of this call. I am still learning asyncio. Further testing of this shows that I can make this a property and then run the code similar to the original cx_Oracle library. After changing to a property I am able to run code such as the following to get a list of column names. I will push that change. |
I removed the async modifier so this may return the columns with a line like this:
|
Maybe you should consider adding the full code (minimal implementation) of your usage scenario, this makes it easier for me in code review to confirm that you have the correct patch. |
Try this. I am not able to get your example to work on my system so I tried to update my code to use your example. Hope this works for you. Thank you. import asyncio
import cx_Oracle_async
import pandas as pd
async def async_oracle_connect(user, password):
conn = await cx_Oracle_async.create_pool(
host='localhost',
port='1521',
user=user,
password=password,
service_name='orcl',
min=1,
max=4,
)
return conn
async def run_query(query, conn):
connection = await conn.acquire()
cur = await connection.cursor()
await cur.execute(query)
rows = await cur.fetchall()
headers = [row[0] for row in cur.description]
df = pd.DataFrame(rows)
df.columns = headers
return df
async def main():
conn = await async_oracle_connect('username', 'password')
queries = list()
sql = "SELECT * FROM V$SESSION"
queries.append(asyncio.create_task(run_query(sql, conn)))
results = await asyncio.gather(*queries)
await conn.close()
return pd.concat(results)
results = asyncio.run(main()) |
Let me know if you need any more information on this. |
No description provided.