代码之家  ›  专栏  ›  技术社区  ›  Matthieu M.

使用cx_Oracle更改架构

  •  5
  • Matthieu M.  · 技术社区  · 16 年前

    好吧,我希望这不是一个副本,搜索没有产生任何有用的东西。

    我一直在玩弄 cx_Oracle 在过去的几天里,安装和使用它。在我遇到当前问题之前,一切都很顺利:我想更改我的模式。如果我使用sqlplus,一个简单的'alter session set current_schema=to to;'就可以了,但是我不知道如何绕过它 cx_甲骨文 .

    我下载了最新的源代码版本:cx_oracle-5.0.2.tar.gz。

    根据 documentation 改变模式是一个简单的设置案例 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
    

    下面是关于OS和Python的信息:

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

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

    我也编译过 CXI甲骨文 对于64位,在同一台机器上。

    2 回复  |  直到 13 年前
        1
  •  8
  •   Matthieu M.    16 年前

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

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

    • WITH_UNICODE 激活 encoding nencoding 属性
    • ORACLE_10G 激活 action , module , clientinfo current_schema

    我查了一下,发现我已经编译了 cx_甲骨文 与Oracle客户端的版本9相比…所以我根据Oracle客户机的10.2.0.3版本重新编译,现在我可以访问这些属性了。

    遗憾的是文件中没有明确规定限制……我非常感谢源代码是可用的。

        2
  •  2
  •   fn.    16 年前

    尝试重新安装cx_Oracle。你的cx-oracle可能搞砸了。你的操作系统和python版本是什么?