I'm trying to call a MySQL stored procedure from Twisted adbapi using the MySQLdb interface but cannot get it to work. I saw that there is a special way to call stored procedure in MySQLdb (callproc), so I was wondering if there was a special way to call it from the adbapi.
我正在尝试使用MySQLdb接口从Twisted adbapi调用MySQL存储过程但无法使其工作。我看到有一种特殊的方法来调用MySQLdb(callproc)中的存储过程,所以我想知道是否有一种特殊的方法可以从adbapi中调用它。
My stored procedure takes two fields A_PROCEDURE(field1 VARCHAR(20), field2 VARCHAR(25))
and I'm attempting to call it in my program in the way most obvious to me: dbpool.runOperation("CALL A_PROCEDURE(%s,%s)", arg1, arg2)
. This attempt called the errback. The procedure works fine if I just test it from my terminal connection to the database.
我的存储过程有两个字段A_PROCEDURE(field1 VARCHAR(20),field2 VARCHAR(25)),我试图以对我来说最明显的方式在我的程序中调用它:dbpool.runOperation(“CALL A_PROCEDURE(%s, %s)“,arg1,arg2)。这种尝试称为错误。如果我只是从终端连接到数据库测试它,该过程工作正常。
1 个解决方案
#1
3
You can use runInteraction
to do arbitrary database or adapter specific things like this:
您可以使用runInteraction执行任意数据库或适配器特定的事情,如下所示:
def aProcedure(cursor, arg1, arg2):
cursor.execute("CALL A_PROCEDURE(%s, %s)", (arg1, arg2))
return cursor.fetchall()
d = dbpool.runInteraction(aProcedure, arg1, arg2)
...
#1
3
You can use runInteraction
to do arbitrary database or adapter specific things like this:
您可以使用runInteraction执行任意数据库或适配器特定的事情,如下所示:
def aProcedure(cursor, arg1, arg2):
cursor.execute("CALL A_PROCEDURE(%s, %s)", (arg1, arg2))
return cursor.fetchall()
d = dbpool.runInteraction(aProcedure, arg1, arg2)
...