Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

bbaker1229
Copy link

No description provided.

@GoodManWEN
Copy link
Owner

GoodManWEN commented Aug 19, 2022

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.

@bbaker1229
Copy link
Author

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.
headers = [row[0] for row in await cur.description]

I will push that change.

@bbaker1229
Copy link
Author

I removed the async modifier so this may return the columns with a line like this:

headers = [row[0] for row in cur.description]

@GoodManWEN
Copy link
Owner

I removed the async modifier so this may return the columns with a line like this:

headers = [row[0] for row in cur.description]

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.

@bbaker1229
Copy link
Author

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())

@bbaker1229
Copy link
Author

Let me know if you need any more information on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants