WL#3585: Implement mysql_stmt_next_result and mysql_stmt_more_results

Affects: Server-7.1   —   Status: Un-Assigned

The prepared statement API should be able to handle multiple resultsets returned
from a multi-statement SQL statement or a stored procedure returning multiple
resultsets. The need for this is obvious, the propared statement API is our
means of having several statements running at the same time (it is sort-of
possible using the mysql_store_result() also, but this has other disadvantages).
Another reason is that the prepared statement API and the "normal" API can't be
used at the same time, which means that if there is hust a single stored
procedure call, that might return multiple reultsets, or a single
multi-statement SQL, the prepared statement API cannot be used.

Initially, I see the need for two functions only, one to get to the next
resultset and one to check for more resultsets, just as with the support for
multiple-resultsets in the standard C API.

Binding parameters is reasonably straightforward as far as I can see, both in
the case of a stored procedure and a multi-statement SQL. The only issue is what
we are bining to when a multi-statement SQL is executing, the parameters of all
statements or one at the time. It is possible that we might want to extend this
with mysql_stmt_bind_param_current() or something like that, that will bind to
the current statement in a multi-statement SQL only, this then being
complemented by mysql_param_count_current() and mysql_param_metadata_current().

Binding result is going to be more difficult to get right if we want to keep
compatability with existing applications. There is a the option of breaking the
current bahviour and using a mysql_set_server_option() or a mysql_real_connect()
flag. The issue is that we will not know what we are getting back in each
resultset until we have fetched at least one row. Also, the resultset will be
different when moving from one resultset to the next, which might be an issue.

-- 

- int mysql_stmt_next_result(MYSQL_STMT *)
Move to the next resultset returned from the statement.
Returns:
0 - Success and there was a next resultset.
-1 - Success and the last resultset has been retrivied.
>0 - Error.

- int mysql_stmt_more_results(MYSQL_STMT *)
Check if there are more resultsets to fetch.
Returns:
1 - There are more resultsets.
0 - There are no more resultsets.
-1 - It is not known at this state of executing if there will be more resultsets,
>1 - Error.

- int mysql_stmt_param_count_current(MYSQL_STMT *)
Get the number of parameters in the current statement when executing a multi-SQL
statement.
Returns:
>=0 - The number of parameters in the current SQL statement.
-1 = An error occurred.

- MYSQL_RES *mysql_stmt_param_metadata_current(MYSQL_STMT *)
Get metadata for the parameters of the current SQL statement in a multi-SQL
execution.
Returns:
NULL - An error occurred.
Any other value - A pointer to a MYSQL_RES with the metadata for the current
statement in a multi-SQL execution.

- int mysql_stmt_bind_param_current(MYSQL_STMT *, MYSQL_BIND *)
Bind parameters to the currently executing statement in a multi-statement SQL
statement.
Returns:
0 - Success
-1 - An error occurred.
1 - Can't bind parameters at this point of execution (I'm nore this is needed).