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