I can't get OUT or INOUT parameters to work with stored procedures using callproc. IN parameters and result sets work fine (well once you set cursor._executed). Has anybody tried OUT parameters?
procname--string,nameofproceduretoexecuteonserverargs--SequenceofparameterstousewithprocedureReturnstheoriginalargs.Compatibilitywarning:PEP-249specifiesthatanymodifiedparametersmustbereturned.Thisiscurrentlyimpossibleastheyareonlyavailablebystoringtheminaservervariableandthenretrievedbyaquery.Sincestoredproceduresreturnzeroormoreresultsets,thereisnoreliablewaytogetatOUTorINOUTparametersviacallproc.Theservervariablesarenamed@_procname_n,whereprocnameistheparameteraboveandnisthepositionoftheparameter(fromzero).Onceallresultsetsgeneratedbytheprocedurehavebeenfetched,youcanissueaSELECT@_procname_0,...queryusing.execute()togetanyOUTorINOUTvalues.Compatibilitywarning:Theactofcallingastoredprocedureitselfcreatesanemptyresultset.Thisappearsafteranyresultsetsgeneratedbytheprocedure.Thisisnon-standardbehaviorwithrespecttotheDB-API.Besuretousenextset()toadvancethroughallresultsets; otherwise you may getdisconnected.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Both cx_Oracle and DB2 function according to PEP-249 (i.e. the return from callproc is a sequence of parameters -- the IN parameters are just copied, the OUT and INOUT parameters are the result values. If you want to implement it under the covers as you describe that is your perogative, but the user should program to the PEP specification so it works the same for all databases -- that's why we have a PEP.
But thanks for explaining what was going on (didn't realize there was built-in doc, thanks for that pointer).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If I could make it follow PEP-249, I would, but it's not technically possible. I didn't do it this way on a whim; it's the best I can do with MySQL's C API. Which is to say, there is not a specific API call for calling stored procedures. The OUT and INOUT variables aren't available until all the result sets are returned, and there's no way to know how many will be returned.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I can't get OUT or INOUT parameters to work with stored procedures using callproc. IN parameters and result sets work fine (well once you set cursor._executed). Has anybody tried OUT parameters?
Small example:
cursor = cx.cursor()
p1 = "K9-RT-01"
p2 = .1
values = [p1, p2]
print "with values:", values
result = cursor.callproc("CHEAPPET", values)
rows = cursor.fetchall()
cursor.close()
print "Query returned %d rows" % len(rows)
print "values =", values
print "result =", result
Produces:
Running: CHEAPPET
with values: ['K9-RT-01', 0.10000000000000001]
Query returned 27 rows
values = ['K9-RT-01', 0.10000000000000001]
result = ['K9-RT-01', 0.10000000000000001]
(the correct answer for result would be: ['K9-RT-01', 225.0])
Gotcha. Does make MySQL support look kind of wimpy though. Has there been any move to improve the C API?
I guess you didn't read the built-in documentation (use help() or pydoc):
Help on method callproc in MySQLdb.cursors.Cursor:
MySQLdb.cursors.Cursor.callproc = callproc(self, procname, args=()) unbound MySQ
Ldb.cursors.Cursor method
Execute stored procedure procname with args
Both cx_Oracle and DB2 function according to PEP-249 (i.e. the return from callproc is a sequence of parameters -- the IN parameters are just copied, the OUT and INOUT parameters are the result values. If you want to implement it under the covers as you describe that is your perogative, but the user should program to the PEP specification so it works the same for all databases -- that's why we have a PEP.
But thanks for explaining what was going on (didn't realize there was built-in doc, thanks for that pointer).
If I could make it follow PEP-249, I would, but it's not technically possible. I didn't do it this way on a whim; it's the best I can do with MySQL's C API. Which is to say, there is not a specific API call for calling stored procedures. The OUT and INOUT variables aren't available until all the result sets are returned, and there's no way to know how many will be returned.