Commit 4cb63e6b authored by patg@radha.local's avatar patg@radha.local

BUG #9056 Changes to patch #2 per Serg's review

parent 953dda06
...@@ -603,9 +603,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), ...@@ -603,9 +603,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
MYF(MY_WME)))) MYF(MY_WME))))
exit(1); exit(1);
break; break;
case 'R':
opt_routines= 1;
break;
case 'W': case 'W':
#ifdef __WIN__ #ifdef __WIN__
opt_protocol = MYSQL_PROTOCOL_PIPE; opt_protocol = MYSQL_PROTOCOL_PIPE;
...@@ -1196,15 +1193,13 @@ static void print_xml_row(FILE *xml_file, const char *row_name, ...@@ -1196,15 +1193,13 @@ static void print_xml_row(FILE *xml_file, const char *row_name,
static uint dump_routines_for_db (char *db) static uint dump_routines_for_db (char *db)
{ {
MYSQL_RES *routine_res= NULL;
MYSQL_RES *routine_list_res= NULL;
MYSQL_ROW row, routine_list_row;
char query_buff[512], routine_type[10]; char query_buff[512], routine_type[10];
char db_name_buff[NAME_LEN+3], name_buff[NAME_LEN+3]; char db_name_buff[NAME_LEN+3], name_buff[NAME_LEN+3];
char *routine_name;
char **routine_list;
int i; int i;
FILE *sql_file = md_result_file; FILE *sql_file = md_result_file;
MYSQL_RES *routine_res= NULL;
MYSQL_RES *routine_list_res= NULL;
MYSQL_ROW row, routine_list_row;
DBUG_ENTER("dump_routines_for_db"); DBUG_ENTER("dump_routines_for_db");
...@@ -1214,7 +1209,15 @@ static uint dump_routines_for_db (char *db) ...@@ -1214,7 +1209,15 @@ static uint dump_routines_for_db (char *db)
/* nice comments */ /* nice comments */
if (opt_comments) if (opt_comments)
fprintf(sql_file, "\n--\n-- Dumping routines for database '%s'\n--\n", db); fprintf(sql_file, "\n--\n-- Dumping routines for database '%s'\n--\n", db);
mysql_query(sock, "LOCK TABLES mysql.proc READ");
/*
not using "mysql_query_with_error_report" because of privileges
*/
if (opt_lock)
mysql_query(sock, "LOCK TABLES mysql.proc READ");
fprintf(sql_file, "\n/*!50003 SET @OLD_SQL_MODE=@@SQL_MODE*/;\n");
fprintf(sql_file, "DELIMITER //\n");
/* 0, retrieve and dump functions, 1, procedures */ /* 0, retrieve and dump functions, 1, procedures */
for (i=0; i <= 1; i++) for (i=0; i <= 1; i++)
...@@ -1225,15 +1228,12 @@ static uint dump_routines_for_db (char *db) ...@@ -1225,15 +1228,12 @@ static uint dump_routines_for_db (char *db)
my_snprintf(query_buff, sizeof(query_buff), my_snprintf(query_buff, sizeof(query_buff),
"SHOW %s STATUS WHERE Db = '%s'", "SHOW %s STATUS WHERE Db = '%s'",
routine_type, db_name_buff); routine_type, db_name_buff);
mysql_query(sock, query_buff);
if (!(routine_list_res= mysql_store_result(sock))) if (mysql_query_with_error_report(sock, &routine_list_res, query_buff))
DBUG_RETURN(1); DBUG_RETURN(1);
if (mysql_num_rows(routine_list_res)) if (mysql_num_rows(routine_list_res))
{ {
fprintf(sql_file, "\n/*!50003 SET @OLD_SQL_MODE=@@SQL_MODE*/;\n");
fprintf(sql_file, "DELIMITER //\n");
while((routine_list_row= mysql_fetch_row(routine_list_res))) while((routine_list_row= mysql_fetch_row(routine_list_res)))
{ {
...@@ -1244,12 +1244,7 @@ static uint dump_routines_for_db (char *db) ...@@ -1244,12 +1244,7 @@ static uint dump_routines_for_db (char *db)
routine_type, name_buff); routine_type, name_buff);
if (mysql_query_with_error_report(sock, &routine_res, query_buff)) if (mysql_query_with_error_report(sock, &routine_res, query_buff))
{
if (path)
my_fclose(sql_file, MYF(MY_WME));
safe_exit(EX_MYSQLERR);
DBUG_RETURN(1); DBUG_RETURN(1);
}
while ((row=mysql_fetch_row(routine_res))) while ((row=mysql_fetch_row(routine_res)))
{ {
...@@ -1272,21 +1267,23 @@ static uint dump_routines_for_db (char *db) ...@@ -1272,21 +1267,23 @@ static uint dump_routines_for_db (char *db)
can't be in comments can't be in comments
*/ */
/* create proc/func body */; /* create proc/func body */;
fprintf(sql_file, i == 0 ? "%s //\n" : "/*!50003 %s */ //\n", row[2]); fprintf(sql_file, "/*!50003 %s */ //\n", row[2]);
} }
} /* end of routine printing */ } /* end of routine printing */
} /* end of list of routines */ } /* end of list of routines */
/* set the delimiter back to ';' */
fprintf(sql_file, "DELIMITER ;\n");
fprintf(sql_file, "/*!50003 SET SESSION SQL_MODE=@OLD_SQL_MODE*/;\n");
mysql_free_result(routine_res); mysql_free_result(routine_res);
routine_res=NULL; routine_res=NULL;
} }
mysql_free_result(routine_list_res); mysql_free_result(routine_list_res);
routine_list_res=NULL; routine_list_res=NULL;
} /* end of for i (0 .. 1) */ } /* end of for i (0 .. 1) */
/* set the delimiter back to ';' */
fprintf(sql_file, "DELIMITER ;\n");
fprintf(sql_file, "/*!50003 SET SESSION SQL_MODE=@OLD_SQL_MODE*/;\n");
mysql_query(sock, "UNLOCK TABLES"); /* again, no error report due to permissions */
if (opt_lock)
mysql_query(sock, "UNLOCK TABLES");
DBUG_RETURN(0); DBUG_RETURN(0);
} }
......
...@@ -1897,37 +1897,65 @@ CREATE PROCEDURE bug9056_proc2(OUT a INT) ...@@ -1897,37 +1897,65 @@ CREATE PROCEDURE bug9056_proc2(OUT a INT)
BEGIN BEGIN
select sum(id) from t1 into a; select sum(id) from t1 into a;
END // END //
SELECT db, name, type, definer, param_list, body
FROM mysql.proc /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
WHERE db = 'test'; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
db name type definer param_list body /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
test bug9056_func1 FUNCTION root@localhost a INT, b INT RETURN a+b /*!40101 SET NAMES utf8 */;
test bug9056_func2 FUNCTION root@localhost f1 char binary begin /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
set f1= concat( 'hello', f1 ); /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
return f1; /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
end /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
test bug9056_proc1 PROCEDURE root@localhost IN a INT, IN b INT, OUT c INT BEGIN SELECT a+b INTO c; end
test bug9056_proc2 PROCEDURE root@localhost OUT a INT BEGIN CREATE DATABASE /*!32312 IF NOT EXISTS*/ `test` /*!40100 DEFAULT CHARACTER SET latin1 */;
select sum(id) from t1 into a;
END USE `test`;
DROP PROCEDURE IF EXISTS bug9056_func1; DROP TABLE IF EXISTS `t1`;
DROP PROCEDURE IF EXISTS bug9056_func2; CREATE TABLE `t1` (
DROP PROCEDURE IF EXISTS bug9056_proc1; `id` int(11) default NULL
DROP PROCEDURE IF EXISTS bug9056_proc2; ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
drop table t1;
SELECT db, name, type, definer, param_list, body
FROM mysql.proc /*!40000 ALTER TABLE `t1` DISABLE KEYS */;
WHERE db = 'test'; LOCK TABLES `t1` WRITE;
db name type definer param_list body INSERT INTO `t1` VALUES (1),(2),(3),(4),(5);
test bug9056_func1 FUNCTION root@localhost a INT, b INT RETURN a+b UNLOCK TABLES;
test bug9056_func2 FUNCTION root@localhost f1 char binary begin /*!40000 ALTER TABLE `t1` ENABLE KEYS */;
/*!50003 SET @OLD_SQL_MODE=@@SQL_MODE*/;
DELIMITER //
/*!50003 SET SESSION SQL_MODE=""*/ //
/*!50003 DROP FUNCTION IF EXISTS bug9056_func1 */ //
/*!50003 CREATE FUNCTION `bug9056_func1`(a INT, b INT) RETURNS int(11)
RETURN a+b */ //
/*!50003 SET SESSION SQL_MODE=""*/ //
/*!50003 DROP FUNCTION IF EXISTS bug9056_func2 */ //
/*!50003 CREATE FUNCTION `bug9056_func2`(f1 char binary) RETURNS char(1)
begin
set f1= concat( 'hello', f1 ); set f1= concat( 'hello', f1 );
return f1; return f1;
end end */ //
test bug9056_proc1 PROCEDURE root@localhost IN a INT, IN b INT, OUT c INT BEGIN SELECT a+b INTO c; end /*!50003 SET SESSION SQL_MODE=""*/ //
test bug9056_proc2 PROCEDURE root@localhost OUT a INT BEGIN /*!50003 DROP PROCEDURE IF EXISTS bug9056_proc1 */ //
/*!50003 CREATE PROCEDURE `bug9056_proc1`(IN a INT, IN b INT, OUT c INT)
BEGIN SELECT a+b INTO c; end */ //
/*!50003 SET SESSION SQL_MODE=""*/ //
/*!50003 DROP PROCEDURE IF EXISTS bug9056_proc2 */ //
/*!50003 CREATE PROCEDURE `bug9056_proc2`(OUT a INT)
BEGIN
select sum(id) from t1 into a; select sum(id) from t1 into a;
END END */ //
DELIMITER ;
/*!50003 SET SESSION SQL_MODE=@OLD_SQL_MODE*/;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
DROP PROCEDURE IF EXISTS bug9056_func1; DROP PROCEDURE IF EXISTS bug9056_func1;
DROP PROCEDURE IF EXISTS bug9056_func2; DROP PROCEDURE IF EXISTS bug9056_func2;
DROP PROCEDURE IF EXISTS bug9056_proc1; DROP PROCEDURE IF EXISTS bug9056_proc1;
......
...@@ -797,44 +797,10 @@ END // ...@@ -797,44 +797,10 @@ END //
DELIMITER ;// DELIMITER ;//
# just to see what you've created
# this will not work because of the timestamps!
# show procedure status;
#show create procedure bug9056_proc1;
#show create procedure bug9056_proc2;
#show function status;
#show create function bug9056_func1;
#show create function bug9056_func2;
SELECT db, name, type, definer, param_list, body
FROM mysql.proc
WHERE db = 'test';
# Dump the DB and ROUTINES # Dump the DB and ROUTINES
--exec $MYSQL_DUMP --skip-comments --routines --databases test > var/tmp/mysqldump.sql --exec $MYSQL_DUMP --skip-comments --routines --databases test
# ok, now blow it all away
--disable_warnings
DROP PROCEDURE IF EXISTS bug9056_func1;
DROP PROCEDURE IF EXISTS bug9056_func2;
DROP PROCEDURE IF EXISTS bug9056_proc1;
DROP PROCEDURE IF EXISTS bug9056_proc2;
drop table t1;
--enable-warnings
# Now, restore
--exec $MYSQL test < var/tmp/mysqldump.sql
# Check that the routines have been reloaded
# this will not work because of the timestamps!
#show procedure status;
#show create procedure bug9056_proc1;
#show create procedure bug9056_proc2;
#show function status;
#show create function bug9056_func1;
#show create function bug9056_func2;
SELECT db, name, type, definer, param_list, body
FROM mysql.proc
WHERE db = 'test';
# ok, now blow it all away
--disable_warnings --disable_warnings
DROP PROCEDURE IF EXISTS bug9056_func1; DROP PROCEDURE IF EXISTS bug9056_func1;
DROP PROCEDURE IF EXISTS bug9056_func2; DROP PROCEDURE IF EXISTS bug9056_func2;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment