How to return results from stored procedure using Python cursor?

How to return results from stored procedure using Python cursor?

Here is how these cases are handled by the principal MySQL Python connector packages – MySQL Connector, mysqlclient (MySQLdb) and PyMySQL. MySQL Connector returns a modified copy of the input sequence as the return value of cursor.callproc; the value is a tuple.

When to return data from a stored procedure?

When returned, the cursor position is set before the first row. For a forward-only cursor, if the cursor is positioned beyond the end of the last row when the procedure exits, an empty result set is returned to the calling batch, procedure, or trigger. Note. An empty result set is not the same as a null value.

When does a scrollable cursor return to the calling batch?

For a scrollable cursor, all the rows in the result set are returned to the calling batch, procedure, or trigger when the procedure exits. When returned, the cursor position is left at the position of the last fetch executed in the procedure.

When to use cursor for callproc in Python?

In practice, using the return value of cursor.callproc can only work if the procedure returns a single row, with the number of columns matching the number of INOUT and OUT parameters, so there is some variation in how the results are handled.

What is the return value of cursor in MySQL?

MySQL Connector returns a modified copy of the input sequence as the return value of cursor.callproc; the value is a tuple. mysqlclient and PyMySQL require that the database is queried for the output parameters, and the results then fetched via the cursor; the value is a tuple of tuples.

Why does MySQL not select the second cursor?

Your logic in the second cursor is also flawed since it will select any record which inludes the friend, not just the required friendship. If you wanted to fix it you could try giving the second cursor a differant name, but preferably start over.

How to return results from stored procedure in MySQL?

MySQL Connector exposes the result via the cursor’s stored_results method ( cursor.stored_results is not part of the DBAPI spec) mysqlclient and PyMySQL require that each result set be fetched via the cursor, while calling cursor.nextset to advance to the next result set.