Description:
If i call the same stored procedure more than once MySql returns the following error message "Lost connection to MySQL server during query".
How to repeat:
test.sql
DROP DATABASE IF EXISTS `test`;
CREATE DATABASE `test`;
USE `test`;
CREATE TABLE `test_table` (
`id` int(10) unsigned NOT NULL auto_increment,
`data` varchar(50) NOT NULL default '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
INSERT INTO `test_table` VALUES (1,'Test one'),(2,'Test two');
DELIMITER $$
CREATE PROCEDURE `test`.`test_sp`()
BEGIN
SELECT count(*) FROM `test_table`;
END$$
DELIMITER ;
test.cpp
#include <stdlib.h>
#include <mysql.h>
#include <iostream>
int main()
{
MYSQL* mysql;
MYSQL_RES *res;
MYSQL_ROW row;
int stat;
mysql = mysql_init(NULL);
mysql_real_connect(mysql, "localhost", "pass", "pass","test", 0, NULL,
CLIENT_MULTI_STATEMENTS | CLIENT_MULTI_RESULTS);
std::cout << "Before calling query #1." << std::endl;
if (mysql_query(mysql,"CALL test_sp()") != 0){
std::cout << mysql_error(mysql) << std::endl;
return 0;
}
std::cout << "Before store_result #1." << std::endl;
res = mysql_store_result(mysql);
std::cout << "Before free_result #1." << std::endl;
if (res != NULL)
mysql_free_result(res);
std::cout << "Before calling query #2." << std::endl;
if (mysql_query(mysql,"CALL test_sp()") != 0){
std::cout << mysql_error(mysql) << std::endl;
return 0;
}
std::cout << "Before store_result #2." << std::endl;
res = mysql_store_result(mysql);
std::cout << "Before free_result #2." << std::endl;
if (res != NULL)
mysql_free_result(res);
mysql_close(mysql);
return 1;
}
gollum sql # mysql -p < test.sql
gollum sql # g++ sql_test.cpp -lmysqlclient -I/usr/include/mysql
gollum sql # ./a.out
Before calling query #1.
Before store_result #1.
Before free_result #1.
Before calling query #2.
Lost connection to MySQL server during query
Description: If i call the same stored procedure more than once MySql returns the following error message "Lost connection to MySQL server during query". How to repeat: test.sql DROP DATABASE IF EXISTS `test`; CREATE DATABASE `test`; USE `test`; CREATE TABLE `test_table` ( `id` int(10) unsigned NOT NULL auto_increment, `data` varchar(50) NOT NULL default '', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; INSERT INTO `test_table` VALUES (1,'Test one'),(2,'Test two'); DELIMITER $$ CREATE PROCEDURE `test`.`test_sp`() BEGIN SELECT count(*) FROM `test_table`; END$$ DELIMITER ; test.cpp #include <stdlib.h> #include <mysql.h> #include <iostream> int main() { MYSQL* mysql; MYSQL_RES *res; MYSQL_ROW row; int stat; mysql = mysql_init(NULL); mysql_real_connect(mysql, "localhost", "pass", "pass","test", 0, NULL, CLIENT_MULTI_STATEMENTS | CLIENT_MULTI_RESULTS); std::cout << "Before calling query #1." << std::endl; if (mysql_query(mysql,"CALL test_sp()") != 0){ std::cout << mysql_error(mysql) << std::endl; return 0; } std::cout << "Before store_result #1." << std::endl; res = mysql_store_result(mysql); std::cout << "Before free_result #1." << std::endl; if (res != NULL) mysql_free_result(res); std::cout << "Before calling query #2." << std::endl; if (mysql_query(mysql,"CALL test_sp()") != 0){ std::cout << mysql_error(mysql) << std::endl; return 0; } std::cout << "Before store_result #2." << std::endl; res = mysql_store_result(mysql); std::cout << "Before free_result #2." << std::endl; if (res != NULL) mysql_free_result(res); mysql_close(mysql); return 1; } gollum sql # mysql -p < test.sql gollum sql # g++ sql_test.cpp -lmysqlclient -I/usr/include/mysql gollum sql # ./a.out Before calling query #1. Before store_result #1. Before free_result #1. Before calling query #2. Lost connection to MySQL server during query