2016-12-08 5 views
1

プロシージャがsys_refcursorを返すときに作成されるカーソルを拡張しようとしています。解決方法How to extend OracleCursor class from cx_Oracleはconnection.cursor()では機能しますが、sys_refcursorでは機能しません。cx_oracleの拡張方法sys_refcursor Curorクラス

import cx_Oracle as cxo 

class MyCursor(cxo.Cursor): 
    def helloWorld(self): 
     print "helloWorld" 

class MyConnection(cxo.Connection): 
    def cursor(self): 
     return MyCursor(self) 



if __name__ == '__main__': 
    conStr = 'ants/<password>' 
    db = MyConnection(conStr) 
    c = db.cursor() 
    c.execute(""" 
     create or replace procedure cx_test_cursor(
      val4 out sys_refcursor 
     ) is 
     begin 
      open val4 for 
       select 1 a from dual union all 
       select 2 from dual; 
     end; 
    """) 

    result = c.callproc('ants.cx_test_cursor', [c.var(cxo.CURSOR)]) 
    c.execute('drop procedure cx_test_cursor') 
    print result 
    result[0].helloWorld() 

結果

[<cx_Oracle.Cursor on <__main__.MyConnection to user [email protected]>>] 
Traceback (most recent call last): 
    File "cx_test2.py", line 32, in <module> 
    result[0].helloWorld() 
AttributeError: 'cx_Oracle.Cursor' object has no attribute 'helloWorld' 

このカーソルを拡張する方法任意のアイデア?

+0

From https://github.com/oracle/python-cx_Oracle/issues/111#issuecomment-344175470:「helloWorld()ではなくhellowWorld()」のtypoveroがあります。 –

+0

入力ミスを修正しました。 –

答えて

1

これは、cx_Oracle 6以上でのみ可能です。

+0

それは素晴らしいだろう! – Ants

+0

これはcx_Oracle 6.xで可能になりました。あなたがこれについて知っておくことの遅れに対する謝罪! –

関連する問題