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

suggestion for container #182

Open
womtibo opened this issue Jan 19, 2023 · 0 comments
Open

suggestion for container #182

womtibo opened this issue Jan 19, 2023 · 0 comments

Comments

@womtibo
Copy link

womtibo commented Jan 19, 2023

Hi and first of all many thanks for these great modules. In earlier versions I have container support manually. Now it is included and I'm wondering if something like this might be generally helpful. The idea is to not rely on the incoming session to already be in the correct context, but change the container as necessary. For example, we always connect through service registered in PDB. But granting/creating common objects requires changing to root container, which does not have proper service name in our environment. Also, it would make things mor complicated when I need to change the servicename when I want to grant common things.

Long story short, this is the codeblock I added to almost all modules in the main function (sorry, not a pro-coder):

cdb_sql = 'select cdb from v$database'

try:
        cursor.execute(cdb_sql)
        result = (cursor.fetchone())
        if result[0] == 'NO':
            container=None
        if result[0] == 'YES' and container and container.upper() == 'ALL':
            sql = 'ALTER SESSION SET CONTAINER=CDB$ROOT'
            cursor.execute(sql)
        if result[0] == 'YES' and container and container.upper() not in ['ALL','CURRENT']:
            sql = 'ALTER SESSION SET CONTAINER=' + container
            cursor.execute(sql)
            container=None # Empty container param because we already changed context
except cx_Oracle.DatabaseError as exc:
        # Database is probably pre 12.1. Map no container clause and continue
        container=None
        pass
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

No branches or pull requests

1 participant