MySQL 4.1 with multiline queries

MySQL 4.1 offers now multiline queries [1]:

/* Connect to server with option CLIENT_MULTI_QUERIES */
mysql_real_query(…, CLIENT_MULTI_QUERIES);

/* Now execute multiple queries */
mysql_query(mysql,\”DROP TABLE IF EXISTS test_table;\\
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\”;
while (mysql_more_results(mysql))
{
/* Process all results */
mysql_next_result(mysql);

printf(\”total affected rows: %lld\”, mysql_affected_rows(mysql));

if ((result= mysql_store_result(mysql))
{
/* Returned a result set, process it */
}
}

[1] http://www.mysql.com/doc/en/C_API_multiple_queries.html

Leave a Reply