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

Method callproc

pymysql/cursors.py:234–283  ·  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

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