使用cx_Oracle更改模式

Mat*_* M. 5 python oracle cx-oracle

好吧,我希望这不是重复,搜索没有产生任何有用的东西.

cx_Oracle过去几天我一直在玩弄,安装和使用它.在我遇到当前问题之前,一切都很顺利:我想改变我的架构.如果我使用sqlplus一个简单的'alter session set current_schema = toto;' 会怎么做,但我不知道如何绕过它cx_Oracle.

我已经下载了最新的源代码:cx_Oracle-5.0.2.tar.gz.

根据文档更改架构是一个简单的设置Connection.current_schema,应该是一个读写属性...麻烦是我的Connection对象没有任何current_schema属性.

>>> 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']
Run Code Online (Sandbox Code Playgroud)

尝试使用设置属性

>>> c.current_schema = 'toto'
Run Code Online (Sandbox Code Playgroud)

导致错误... __setattr__显然已被覆盖以防止它.

那么......有谁知道怎么做?


这是我得到的错误.

>>> 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
Run Code Online (Sandbox Code Playgroud)

以下是有关OS和python的信息:

SUSE LINUX Enterprise Server 9 (x86_64)
VERSION = 9
PATCHLEVEL = 3
Run Code Online (Sandbox Code Playgroud)

我使用python 2.6.2(编译为64位)

我也在cx_Oracle同一台机器上编译了64位.

Mat*_* M. 9

好吧,经过多次尝试和错误后,我终于遵循了fn建议并调查了内部cx_Oracle以找出问题所在.

事实证明,许多参数和方法只能通过一些标志获得:

  • WITH_UNICODE激活encodingnencoding属性
  • ORACLE_10G激活action,module,clientinfocurrent_schema

我检查并发现我已经cx_Oracle针对oracle客户端的版本9进行了编译...所以我重新编译了oracle客户端的版本10.2.0.3,现在我可以访问这些属性了.

遗憾的是,文档中没有规定限制......我非常感谢源代码可用.