"スプール" コマンドは、SQL * Plusのに非常に固有のものであり、cx_Oracleまたはその他では使用できません。 OCI(Oracle Call Interface)を使用するアプリケーション。しかし、あまりにも厄介なことなしに、同様のことをすることができます。
cx_Oracle.Connectionからサブクラス化された独自のConnectionクラスと、cx_Oracle.Cursorからサブクラス化された独自のCursorクラスを作成し、ロギングを実行し、自由にオンとオフを切り替える特別なコマンド "spool"を作成できます。このようなもの:
class Connection(cx_Oracle.Connection):
def __init__(self, *args, **kwargs):
self.spoolFile = None
return super(Connection, self).__init__(*args, **kwargs)
def cursor(self):
return Cursor(self)
def spool(self, fileName):
self.spoolFile = open(fileName, "w")
class Cursor(cx_Oracle.Cursor):
def execute(self, statement, args):
result = super(Cursor, self).execute(statement, args)
if self.connection.spoolFile is not None:
self.connection.spoolFile.write("Headers for query\n")
self.connection.spoolFile.write("use cursor.description")
def fetchall(self):
rows = super(Cursor, self).fetchall()
if self.connection.spoolFile is not None:
for row in rows:
self.connection.spoolFile.write("row details")
これはどこに行けばいいか分かります。
ありがとうございました!それは本当に役立ちます!私はあなたがbitbucketのウェブサイトでいくつかのpacakgesを開発したのを見ました。それらは素晴らしかった!このような状況でパッケージを使用することはできますか?私はコーディングがあまりよくないので、自分で書くのは難しいかもしれません.... – Xiaoqing
よろしくお願いします。このパッケージは、使用しているSQLとバインド変数を記録します:https://bitbucket.org/anthony_tuininga/cx_pyoraclelib/src/dda6bfb0217bc48ea7c20cb763b3385e8fc9bfaa/cx_OracleEx.py?at=default&fileviewer=file-view-default –
これが出力されます。 SQL文としてのクエリの結果。うまくいけば、それらのうちのいくつかがあなたを助けるでしょう:https://bitbucket.org/anthony_tuininga/cx_oracletools/src/d0b454fa1a020620f43f88ea15bd4c37a6ec8e19/DumpData.py?at=default&fileviewer=file-view-default –