MCPcopy Create free account
hub / github.com/PyMySQL/PyMySQL / callproc

Method callproc

pymysql/cursors.py:235–284  ·  view source on GitHub ↗

Execute stored procedure procname with args. :param procname: Name of procedure to execute on server. :type procname: str :param args: Sequence of parameters to use with procedure. :type args: tuple or list Returns the original args. Compatibility

(self, procname, args=())

Source from the content-addressed store, hash-verified

233 return rows
234
235 def callproc(self, procname, args=()):
236 """Execute stored procedure procname with args.
237
238 :param procname: Name of procedure to execute on server.
239 :type procname: str
240
241 :param args: Sequence of parameters to use with procedure.
242 :type args: tuple or list
243
244 Returns the original args.
245
246 Compatibility warning: PEP-249 specifies that any modified
247 parameters must be returned. This is currently impossible
248 as they are only available by storing them in a server
249 variable and then retrieved by a query. Since stored
250 procedures return zero or more result sets, there is no
251 reliable way to get at OUT or INOUT parameters via callproc.
252 The server variables are named @_procname_n, where procname
253 is the parameter above and n is the position of the parameter
254 (from zero). Once all result sets generated by the procedure
255 have been fetched, you can issue a SELECT @_procname_0, ...
256 query using .execute() to get any OUT or INOUT values.
257
258 Compatibility warning: The act of calling a stored procedure
259 itself creates an empty result set. This appears after any
260 result sets generated by the procedure. This is non-standard
261 behavior with respect to the DB-API. Be sure to use nextset()
262 to advance through all result sets; otherwise you may get
263 disconnected.
264 """
265 procname_escaped = _backquote_escape(procname)
266 conn = self._get_db()
267
268 if args:
269 fmt = f"@`_{procname_escaped}_%d`=%s"
270 self._query(
271 "SET %s"
272 % ",".join(
273 fmt % (index, conn.escape(arg)) for index, arg in enumerate(args)
274 )
275 )
276 self.nextset()
277
278 q = "CALL `{}`({})".format(
279 procname_escaped,
280 ",".join([f"@`_{procname_escaped}_{i}`" for i in range(len(args))]),
281 )
282 self._query(q)
283 self._executed = q
284 return args
285
286 def fetchone(self):
287 """Fetch the next row."""

Callers 1

test_issue_1206Method · 0.80

Calls 5

_get_dbMethod · 0.95
_queryMethod · 0.95
nextsetMethod · 0.95
_backquote_escapeFunction · 0.85
escapeMethod · 0.80

Tested by 1

test_issue_1206Method · 0.64