Execute multiple SQL statements

A DataBlade® API statement-execution function can send more than one SQL statement to the database server at a time. In this case, the statement string contains several SQL statements, each terminated by a semicolon (;). When the statement string contains more than one SQL statement, the mi_get_result() function executes for each statement in the string.

Suppose you send the following statement string for execution:
"insert into tab1 (id) values (1); \
 insert into tab1 (id) values (2); \
 insert into tab1 (id) values (3); "

For the preceding statement string, the mi_get_result() function executes four times, three times returning an MI_DML status for each INSERT statement and once to return the final MI_NO_MORE_RESULTS status.

Keep in mind that the effects of one part of the statement string are not visible to other parts. If one SQL statement depends on an earlier one, do not put them both in the same statement string. For example, the following statement string causes an error:
mi_exec(myconn, "create table tab1(a int, b int); \
   insert into tab1 values (1,2);",
   MI_QUERY_NORMAL);
The preceding mi_exec() call generates an error because the INSERT statement cannot see the result of the CREATE TABLE statement. The solution is to call mi_exec() twice, as follows:
/* Execute CREATE TABLE statement in first mi_exec() call */
mi_exec(myconn, "create table tab1 (a integer, b integer);",
   MI_QUERY_NORMAL);
mi_query_finish(myconn);

/* Execute INSERT statement in second mi_exec() call */
mi_exec(myconn, "insert into tab1 values (1,2);",
   MI_QUERY_NORMAL);
mi_query_finish(myconn);