好吧,我希望这不是重复的,搜索没有产生任何有用的结果。

我一直在玩弄 cx_Oracle 这几天,安装并使用了它。一切都很顺利,直到我遇到了当前的问题:我想改变我的架构。如果我使用sqlplus一个简单的“ alter会话集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']

尝试使用设置属性

>>> c.current_schema = 'toto'

结果出现错误... __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

以下是有关操作系统和 python 的信息:

SUSE LINUX Enterprise Server 9 (x86_64)
VERSION = 9
PATCHLEVEL = 3

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

我也编译了 cx_Oracle 对于 64 位,在同一台机器上。

有帮助吗?

解决方案

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

事实证明,许多参数和方法只能通过某些标志来使用:

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

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

遗憾的是文档中没有明确限制......我非常感谢源代码可用。

其他提示

尝试重新安装cx_Oracle。你cx_Oracle很可能搞砸。什么是你的操作系统和Python版本?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top