Well, I hope this is not a duplicate, the search did not yield anything useful.
I have been toying with cx_Oracle for the past few days, installing and using it. Everything went fine until I reached my current problem: I'd like to change my schema. If I were using sqlplus a simple 'alter session set current_schema=toto;' would do, but I don't know how to get around it with cx_Oracle.
I've downloaded the latest source version: cx_Oracle-5.0.2.tar.gz.
According to the documentation changing of schema is a simple case of setting Connection.current_schema which should be a read-write attribute... the trouble is my Connection object does not have any current_schema attribute.
>>> c = cx_Oracle.connect(...)
>>> dir(c)
['__class__', '__delattr__', '__doc__', '__enter__', '__exit__', '__format__', 
'__getattribute__', '__hash__', '__init__', '__new__', '__reduce__',
'__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', 
'__subclasshook__', 'autocommit', 'begin', 'cancel', 'changepassword', 'close', 
'commit', 'cursor', 'dsn', 'encoding', 'inputtypehandler',
'maxBytesPerCharacter', 'nencoding', 'outputtypehandler', 'password', 'prepare', 
'register', 'rollback', 'stmtcachesize', 'tnsentry', 'unregister', 'username', 
'version']
Trying to set the attribute using
>>> c.current_schema = 'toto'
results in an error... __setattr__ has apparently been overridden to prevent it.
So... does anyone know how to ?
Here is the error I got.
>>> c.current_schema = 'toto'
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
AttributeError: 'cx_Oracle.Connection' object has no attribute 'current_schema'
>>> setattr(c, 'current_schema', 'toto')
# same error
And here are the information about OS and python:
SUSE LINUX Enterprise Server 9 (x86_64)
VERSION = 9
PATCHLEVEL = 3
And I use python 2.6.2 (compiled for 64bits)
I also compiled cx_Oracle for 64bits, on the very same machine.
The following statement sets the schema of the current session to the schema name specified in the statement. ALTER SESSION SET CURRENT_SCHEMA = < schema name > In subsequent SQL statements, Oracle Database uses this schema name as the schema qualifier when the qualifier is omitted.
In subsequent SQL statements, Oracle Database uses this schema name as the schema qualifier when the qualifier is omitted. In addition, the database uses the temporary tablespace of the specified schema for sorts, joins, and storage of temporary database objects.
You have the option of enabling industry-specific schemas in your Oracle CX Audience account. When you enable this option, CX Audience does the following: Create new tables for the schema. For the retail schema, these tables are Orders, Order line, and Product lookup. Learn more about The Retail predefined schema.
Schema Change Plans—A means of deploying specific changes from a development environment to one or more target databases. Data Comparison—A list of differences in row data between two databases.
Okay, I finally, after much trying and error, followed fn suggestion and investigated inside cx_Oracle to find what was wrong.
It turns out that a number of arguments and methods are only available through some flags:
WITH_UNICODE activates encoding and nencoding attributesORACLE_10G activates action, module, clientinfo and current_schema
I checked and found out that I had compiled cx_Oracle against the version 9 of the oracle client... so I recompiled against the version 10.2.0.3 of the oracle client and now I have access to these attributes.
Shame that the restriction was not precised in the documentation... and I am very thankful that the source code is available.
Try reinstalling cx_Oracle. Your cx_Oracle is probably messed up. What's your OS and python version?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With