In MySQL 5.0 the protocol was extended to handle:
Multi-resultsets are sent up by stored procedures if more than one resultset was generated inside of it:
CREATE TEMPORARY TABLE ins ( id INT ); DROP PROCEDURE IF EXISTS multi; DELIMITER $$ CREATE PROCEDURE multi() BEGIN SELECT 1; SELECT 1; INSERT INTO ins VALUES (1); INSERT INTO ins VALUES (2); END$$ DELIMITER ; CALL multi(); DROP TABLE ins;
results in:
a resultset:
01 00 00 01 01 17 00 00 02 03 64 65 66 00 00 00 ..........def... 01 31 00 0c 3f 00 01 00 00 00 08 81 00 00 00 00 .1..?........... 05 00 00 03 fe 00 00 0a 00 02 00 00 04 01 31 05 ..............1. 00 00 05 fe 00 00 0a 00 ........
see the
EOF_Packet:
05 00 00 03 fe 00 00 0a
00 with its status-flag being
0a
the 2nd resultset:
01 00 00 06 01 17 00 00 07 03 64 65 66 00 00 00 ..........def... 01 31 00 0c 3f 00 01 00 00 00 08 81 00 00 00 00 .1..?........... 05 00 00 08 fe 00 00 0a 00 02 00 00 09 01 31 05 ..............1. 00 00 0a fe 00 00 0a 00 ........
see the
EOF_Packet:
05 00 00 0a fe 00 00 0a
00 with its status-flag being
0a
... and a closing empty resultset, a
OK_Packet:
07 00 00 0b 00 01 00 02 00 00 00 ...........
SERVER_MORE_RESULTS_EXISTS
is set to indicate that more resultsets will follow.
The trailing
OK_Packet
is the response to the CALL statement and contains the affected
rows of the last statement. In our case we INSERTed 2 rows, but
only the affected_rows of the last
INSERT statement is returned as part of the
OK_Packet.
If the last statement is a SELECT the affected rows is 0.
The client has to announce that it wants multi-resultsets by
either setting the
CLIENT_MULTI_RESULTS
or
CLIENT_PS_MULTI_RESULTS
capability.
Starting with MySQL 5.5.3 prepared statements can bind OUT
parameters of stored procedures. They are returned as an extra
resultset in the multi-resultset response. The client
announces it can handle OUT parameters by settting the
CLIENT_PS_MULTI_RESULTS
capability.
To distinguish a normal resultset from a OUT parameter set the
EOF_Packet
after its field definition has the
SERVER_PS_OUT_PARAMS
flags set.
The closing
EOF_Packet
does NOT have neither the
SERVER_PS_OUT_PARAMS
flag nor the
SERVER_MORE_RESULTS_EXISTS
flag set. Only the first
EOF_Packet
has.
A multi-statement is allowing COM_QUERY to send more than one query to the server, separated by a ';'.
The client has to announce that it wants multi-statements by
either setting the
CLIENT_MULTI_STATEMENTS
capability or by using
COM_SET_OPTION.
Allows to enable and disable:
for the current connection. The option operation is one of:
op |
constant name |
|---|---|
0 |
MYSQL_OPTION_MULTI_STATEMENTS_ON |
1 |
MYSQL_OPTION_MULTI_STATEMENTS_OFF |
On success it returns a
EOF_Packet
otherwise a
ERR_Packet.
