mariadb/mysql-test/main/mysql_comments.sql

219 lines
4.6 KiB
MySQL
Raw Normal View History

Fix for: bug #26215: mysql command line client should not strip comments from SQL statements and bug #11230: Keeping comments when storing stored procedures With the introduction of multiline comments support in the command line client (mysql) in MySQL 4.1, it became impossible to preserve client-side comments within single SQL statements or stored routines. This feature was useful for monitoring tools and maintenance. The patch adds a new option to the command line client ('--enable-comments', '-c') which allows to preserve SQL comments and send them to the server for single SQL statements, and to keep comments in the code for stored procedures / functions / triggers. The patch is a modification of the contributed patch from bug #11230 with the following changes: - code style changes to conform to the coding guidelines - changed is_prefix() to my_strnncoll() to detect the DELIMITER command, since the first one is case-sensitive and not charset-aware - renamed t/comments-51.* to t/mysql_comments.* - removed tests for comments in triggers since 5.0 does not have SHOW CREATE TRIGGER (those tests will be added back in 5.1). The test cases are only for bug #11230. No automated test case for bug #26215 is possible due to the test suite deficiencies (though the cases from the bug report were tested manually). client/mysql.cc: Applied the contributed patch from bug11230 with the following changes: - code style changes to conform to the coding guidelines - changed is_prefix() to my_strnncoll() to detect the DELIMITER command, since the first one is case-sensitive and not charset-aware The patch adds a new option to the command line client which allows to preserve SQL comments and send them to the server to ensure better error reporting and to, keep comments in the code for stored procedures / functions / triggers. mysql-test/r/mysql_comments.result: Added test cases for bug11230. mysql-test/t/mysql_comments.sql: Added test cases for bug11230. mysql-test/t/mysql_comments.test: Added test cases for bug11230.
2007-11-02 11:40:34 +01:00
##============================================================================
## Notes
##============================================================================
# Test case for Bug#11230
# The point of this test is to make sure that '#', '-- ' and '/* ... */'
# comments, as well as empty lines, are sent from the client to the server.
# This is to ensure better error reporting, and to keep comments in the code
# for stored procedures / functions / triggers (Bug#11230).
# As a result, be careful when editing comments in this script, they do
# matter.
#
# Also, note that this is a script for **mysql**, not mysqltest.
# This is critical, as the mysqltest client interprets comments differently.
##============================================================================
## Setup
##============================================================================
## See mysql_comments.test for initial cleanup
# Test tables
#
# t1 is reused throughout the file, and dropped at the end.
#
drop table if exists t1;
create table t1 (
id char(16) not null default '',
data int not null
);
##============================================================================
## Comments outside statements
##============================================================================
# Ignored 1a
-- Ignored 1b
/*
Ignored 1c
*/
select 1;
##============================================================================
## Comments inside statements
##============================================================================
select # comment 1a
# comment 2a
-- comment 2b
/*
comment 2c
*/
2
; # not strictly inside, but on same line
# ignored
##============================================================================
## Comments inside functions
##============================================================================
drop function if exists foofct ;
create function foofct (x char(20))
returns char(20)
/* not inside the body yet */
return
-- comment 1a
# comment 1b
/* comment 1c */
x; # after body, on same line
select foofct("call 1");
show create function foofct;
drop function foofct;
delimiter |
create function foofct(x char(20))
returns char(20)
begin
-- comment 1a
# comment 1b
/*
comment 1c
*/
-- empty line below
-- empty line above
return x;
end|
delimiter ;
select foofct("call 2");
show create function foofct;
drop function foofct;
##============================================================================
## Comments inside stored procedures
##============================================================================
# Empty statement
drop procedure if exists empty;
create procedure empty()
begin
end;
call empty();
show create procedure empty;
drop procedure empty;
drop procedure if exists foosp;
## These comments are before the create, and will be lost
# Comment 1a
-- Comment 1b
/*
Comment 1c
*/
create procedure foosp()
/* Comment not quiet in the body yet */
insert into test.t1
## These comments are part of the procedure body, and should be kept.
# Comment 2a
-- Comment 2b
/* Comment 2c */
-- empty line below
-- empty line above
values ("foo", 42); # comment 3, still part of the body
## After the ';', therefore not part of the body
# comment 4a
-- Comment 4b
/*
Comment 4c
*/
call foosp();
select * from t1;
delete from t1;
show create procedure foosp;
drop procedure foosp;
drop procedure if exists nicesp;
delimiter |
create procedure nicesp(a int)
begin
-- declare some variables here
declare b int;
declare c float;
-- do more stuff here
-- commented nicely and so on
-- famous last words ...
end|
delimiter ;
show create procedure nicesp;
drop procedure nicesp;
##============================================================================
## Comments inside triggers
##============================================================================
drop trigger if exists t1_empty;
create trigger t1_empty after delete on t1
for each row
begin
end;
show create trigger t1_empty;
drop trigger if exists t1_bi;
delimiter |
create trigger t1_bi before insert on t1
for each row
begin
# comment 1a
-- comment 1b
/*
comment 1c
*/
-- declare some variables here
declare b int;
declare c float;
-- do more stuff here
-- commented nicely and so on
-- famous last words ...
set NEW.data := 12;
end|
delimiter ;
show create trigger t1_bi;
# also make sure the trigger still works
insert into t1(id) value ("trig");
select * from t1;
Fix for: bug #26215: mysql command line client should not strip comments from SQL statements and bug #11230: Keeping comments when storing stored procedures With the introduction of multiline comments support in the command line client (mysql) in MySQL 4.1, it became impossible to preserve client-side comments within single SQL statements or stored routines. This feature was useful for monitoring tools and maintenance. The patch adds a new option to the command line client ('--enable-comments', '-c') which allows to preserve SQL comments and send them to the server for single SQL statements, and to keep comments in the code for stored procedures / functions / triggers. The patch is a modification of the contributed patch from bug #11230 with the following changes: - code style changes to conform to the coding guidelines - changed is_prefix() to my_strnncoll() to detect the DELIMITER command, since the first one is case-sensitive and not charset-aware - renamed t/comments-51.* to t/mysql_comments.* - removed tests for comments in triggers since 5.0 does not have SHOW CREATE TRIGGER (those tests will be added back in 5.1). The test cases are only for bug #11230. No automated test case for bug #26215 is possible due to the test suite deficiencies (though the cases from the bug report were tested manually). client/mysql.cc: Applied the contributed patch from bug11230 with the following changes: - code style changes to conform to the coding guidelines - changed is_prefix() to my_strnncoll() to detect the DELIMITER command, since the first one is case-sensitive and not charset-aware The patch adds a new option to the command line client which allows to preserve SQL comments and send them to the server to ensure better error reporting and to, keep comments in the code for stored procedures / functions / triggers. mysql-test/r/mysql_comments.result: Added test cases for bug11230. mysql-test/t/mysql_comments.sql: Added test cases for bug11230. mysql-test/t/mysql_comments.test: Added test cases for bug11230.
2007-11-02 11:40:34 +01:00
##============================================================================
## Cleanup
##============================================================================
drop table t1;