Oracle 5.0 Reference Manual page 2247

Table of Contents

Advertisement

C API Support for Multiple Statement Execution
Otherwise, such procedures result in an error
can't return a result set in the given
CLIENT_MULTI_STATEMENTS
to execute statement strings containing multiple statements separated by semicolons.
This option also enables
of
CLIENT_MULTI_STATEMENTS
argument of
CLIENT_MULTI_STATEMENTS |
CLIENT_MULTI_STATEMENTS
result processing.
• After the connection to the server has been established, you can use the
mysql_set_server_option()
execution by passing it an argument of
MYSQL_OPTION_MULTI_STATEMENTS_OFF. Enabling multiple-statement execution with this
function also enables processing of "simple" results for a multiple-statement string where each
statement produces a single result, but is not sufficient to permit processing of stored procedures
that produce result sets.
The following procedure outlines a suggested strategy for handling multiple statements:
1. Pass
CLIENT_MULTI_STATEMENTS
statement execution and multiple-result processing.
2. After calling
mysql_query()
loop within which you process statement results.
3. For each iteration of the loop, handle the current statement result, retrieving either a result set or an
affected-rows count. If an error occurs, exit the loop.
4. At the end of the loop, call
initiate retrieval for it if so. If no more results are available, exit the loop.
One possible implementation of the preceding strategy is shown following. The final part of the loop
can be reduced to a simple test of whether
written distinguishes between no more results and an error, which enables a message to be printed for
the latter occurrence.
/* connect to server with the CLIENT_MULTI_STATEMENTS option */
if (mysql_real_connect (mysql, host_name, user_name, password,
db_name, port_num, socket_name, CLIENT_MULTI_STATEMENTS) == NULL)
{
printf("mysql_real_connect() failed\n");
mysql_close(mysql);
exit(1);
}
/* execute multiple statements */
status = mysql_query(mysql,
"DROP TABLE IF EXISTS test_table;\
if (status)
{
printf("Could not execute statement(s)");
mysql_close(mysql);
exit(0);
}
/* process each statement result */
do {
/* did current statement return data? */
result = mysql_store_result(mysql);
enables
mysql_query()
CLIENT_MULTI_RESULTS
to
mysql_real_connect()
is sufficient to enable multiple-statement execution and all multiple-
function to enable or disable multiple-statement
MYSQL_OPTION_MULTI_STATEMENTS_ON
to mysql_real_connect(), to fully enable multiple-
or
mysql_real_query()
mysql_next_result()
mysql_next_result()
CREATE TABLE test_table(id INT);\
INSERT INTO test_table VALUES(10);\
UPDATE test_table SET id=20 WHERE id=10;\
SELECT * FROM test_table;\
DROP TABLE test_table");
2227
Error 1312 (0A000): PROCEDURE proc_name
context.
and
mysql_real_query()
implicitly, so a
flags
is equivalent to an
CLIENT_MULTI_RESULTS. That is,
and verifying that it succeeds, enter a
to check whether another result exists and
returns nonzero. The code as
argument
or

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents