Answer is simple. Can't do that.
----- Original Message ----- From: <[EMAIL PROTECTED]>
To: <mysql@lists.mysql.com>
Sent: Friday, May 06, 2005 5:40 AM
Subject: C API : Problem using multi-statements
Hello,
I have some problems using multiple queries in a databased driven project, therefore I wrote a little testprogram which
causes the same problems.
I am using the C-API of MySQL 4.1.11 on a Gentoo Linux 3.3.2-r5, propolice-3.3-7 with 2.4.27 kernel.
I connect to the server (on localhost) with mysql_real_connect and the flag CLIENT_MULTI_STATEMENTS,
I submit multiple queries (two INSERTS seperated by ";") on the existing connection.
Executing the multistatement with mysql_query in a loop (i.e. 10 times),
I get a lot of "lost connection during query" errors, but sending a single INSERT query in a loop causes no errors !!!
Thanks in advance for help regards Tinosch Ganjineh
The following program operates on a simple table structure created with the following statement :
CREATE TABLE BIGTABLE (myoid char(40), mykey char(40), myval char(40), myint bigint) TYPE = InnoDB;
/********************************** mysqltest.cpp *************************************/
#include <iostream>
#include <mysql.h>
#include <sstream>
#include <string>
using namespace std;
string itos(long long i) { ostringstream sstream; sstream << i; return sstream.str(); }
int main(int argc, char** argv) {
MYSQL* conn;
if(conn = mysql_init(NULL)) {
if(mysql_real_connect(conn, "localhost", "root", "xxxxx", "test", 0, NULL, CLIENT_MULTI_STATEMENTS )) {
int loop=100;
for(int i=0; i<loop; ++i) {
int e=0;
string query;
query = string("INSERT INTO BIGTABLE VALUES (") + "'object-" +itos(i)+"', 'foo', 'bar', NULL);\
INSERT INTO BIGTABLE VALUES (" + "'object-" +itos(i+1000)+"', 'bar, 'foo', NULL)";
e = mysql_query(conn, query.c_str());
if(e) {
cerr << "*********Query failed*****: " << e << " - " << mysql_error(conn) << endl;
} else {
MYSQL_RES* result = mysql_store_result(conn);
if(result) {
// .. parse result set ...
} else {
//cerr << "Could not fetch Results from DB: " << mysql_error(conn);
}
mysql_free_result(result);
}
}
} else {
cerr << "Could not connect to MySQL database: " << mysql_error(conn) << endl;
}
} else {
cerr << "Could not initialize MySQL: " << mysql_error(conn) << endl;
}
}
/********************************** mysqltest.cpp *************************************/
-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]
-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]