I have a database hosted on Google Cloud SQL and a python script to query.
I am trying to call a stored procedure with an Out parameter. The SP was called successfully, but the value of the Out parameter is not like my python code.
For example, here is an example taken from here :
Multiple stored procedure definition:
CREATE PROCEDURE multiply(IN pFac1 INT, IN pFac2 INT, OUT pProd INT) BEGIN SET pProd := pFac1 * pFac2; END
If I call SP from the command line as follows:
CALL multiply(5, 5, @Result) SELECT @Result
I get the result correctly:
+---------+ | @Result | +---------+ | 25 | +---------+
But if I call it using python code using the MySQLdb package, for example:
args = (5, 5, 0)
then I don't get the out parameter in my result cortel:
(5, 5, 0)
So what am I doing wrong here?
UPDATE: Just found this warning in callproc code:
Compatibility warning: PEP-249 specifies that any modified parameters must be returned. This is currently impossible as they are only available by storing them in a server variable and then retrieved by a query. Since stored procedures return zero or more result sets, there is no reliable way to get at OUT or INOUT parameters via callproc. The server variables are named @_procname_n, where procname is the parameter above and n is the position of the parameter (from zero). Once all result sets generated by the procedure have been fetched, you can issue a SELECT @_procname_0, ... query using .execute() to get any OUT or INOUT values.
Also note that the callproc function simply returns the same input tuple. Therefore, the bottom line is not possible. Go back to the drawing board, then ...