1
by brian
clean slate |
1 |
##============================================================================
|
2 |
## Notes |
|
3 |
##============================================================================
|
|
4 |
||
5 |
# Test case for Bug#11230 |
|
6 |
||
7 |
# The point of this test is to make sure that '#', '-- ' and '/* ... */' |
|
8 |
# comments, as well as empty lines, are sent from the client to the server. |
|
9 |
# This is to ensure better error reporting, and to keep comments in the code |
|
10 |
# for stored procedures / functions / triggers (Bug#11230). |
|
11 |
# As a result, be careful when editing comments in this script, they do |
|
12 |
# matter. |
|
13 |
#
|
|
14 |
# Also, note that this is a script for **mysql**, not mysqltest. |
|
15 |
# This is critical, as the mysqltest client interprets comments differently. |
|
16 |
||
17 |
##============================================================================
|
|
18 |
## Setup |
|
19 |
##============================================================================
|
|
20 |
||
21 |
## See mysql_comments.test for initial cleanup |
|
22 |
||
23 |
# Test tables |
|
24 |
#
|
|
25 |
# t1 is reused throughout the file, and dropped at the end. |
|
26 |
#
|
|
27 |
drop table if exists t1; |
|
28 |
create table t1 ( |
|
29 |
id char(16) not null default '', |
|
30 |
data int not null |
|
31 |
);
|
|
32 |
||
33 |
##============================================================================
|
|
34 |
## Comments outside statements |
|
35 |
##============================================================================
|
|
36 |
||
37 |
# Ignored 1a |
|
38 |
-- Ignored 1b
|
|
39 |
/*
|
|
40 |
Ignored 1c
|
|
41 |
*/
|
|
42 |
||
43 |
select 1; |
|
44 |
||
45 |
##============================================================================
|
|
46 |
## Comments inside statements |
|
47 |
##============================================================================
|
|
48 |
||
49 |
select # comment 1a |
|
50 |
# comment 2a |
|
51 |
-- comment 2b
|
|
52 |
/*
|
|
53 |
comment 2c
|
|
54 |
*/
|
|
55 |
2
|
|
56 |
; # not strictly inside, but on same line |
|
57 |
# ignored |
|
58 |
||
59 |
##============================================================================
|
|
60 |
## Comments inside functions |
|
61 |
##============================================================================
|
|
62 |
||
63 |
drop function if exists foofct ; |
|
64 |
||
65 |
create function foofct (x char(20)) |
|
66 |
returns char(20) |
|
67 |
/* not inside the body yet */
|
|
68 |
return
|
|
69 |
-- comment 1a
|
|
70 |
# comment 1b |
|
71 |
/* comment 1c */
|
|
72 |
x; # after body, on same line |
|
73 |
||
74 |
select foofct("call 1"); |
|
75 |
||
76 |
show create function foofct; |
|
77 |
drop function foofct; |
|
78 |
||
79 |
delimiter | |
|
80 |
||
81 |
create function foofct(x char(20)) |
|
82 |
returns char(20) |
|
83 |
begin
|
|
84 |
-- comment 1a
|
|
85 |
# comment 1b |
|
86 |
/*
|
|
87 |
comment 1c
|
|
88 |
*/
|
|
89 |
||
90 |
-- empty line below
|
|
91 |
||
92 |
-- empty line above
|
|
93 |
return x; |
|
94 |
end| |
|
95 |
||
96 |
delimiter ; |
|
97 |
||
98 |
select foofct("call 2"); |
|
99 |
||
100 |
show create function foofct; |
|
101 |
drop function foofct; |
|
102 |
||
103 |
##============================================================================
|
|
104 |
## Comments inside stored procedures |
|
105 |
##============================================================================
|
|
106 |
||
107 |
# Empty statement |
|
108 |
drop procedure if exists empty; |
|
109 |
create procedure empty() |
|
110 |
begin
|
|
111 |
end; |
|
112 |
||
113 |
call empty(); |
|
114 |
show create procedure empty; |
|
115 |
drop procedure empty; |
|
116 |
||
117 |
drop procedure if exists foosp; |
|
118 |
||
119 |
## These comments are before the create, and will be lost |
|
120 |
# Comment 1a |
|
121 |
-- Comment 1b
|
|
122 |
/*
|
|
123 |
Comment 1c
|
|
124 |
*/
|
|
125 |
create procedure foosp() |
|
126 |
/* Comment not quiet in the body yet */
|
|
127 |
insert into test.t1 |
|
128 |
## These comments are part of the procedure body, and should be kept. |
|
129 |
# Comment 2a |
|
130 |
-- Comment 2b
|
|
131 |
/* Comment 2c */
|
|
132 |
-- empty line below
|
|
133 |
||
134 |
-- empty line above
|
|
135 |
values ("foo", 42); # comment 3, still part of the body |
|
136 |
## After the ';', therefore not part of the body |
|
137 |
# comment 4a |
|
138 |
-- Comment 4b
|
|
139 |
/*
|
|
140 |
Comment 4c
|
|
141 |
*/
|
|
142 |
||
143 |
call foosp(); |
|
144 |
select * from t1; |
|
145 |
delete from t1; |
|
146 |
show create procedure foosp; |
|
147 |
drop procedure foosp; |
|
148 |
||
149 |
drop procedure if exists nicesp; |
|
150 |
||
151 |
delimiter | |
|
152 |
||
153 |
create procedure nicesp(a int) |
|
154 |
begin
|
|
155 |
-- declare some variables here
|
|
156 |
declare b int; |
|
157 |
declare c float; |
|
158 |
||
159 |
-- do more stuff here
|
|
160 |
-- commented nicely and so on
|
|
161 |
||
162 |
-- famous last words ...
|
|
163 |
end| |
|
164 |
||
165 |
delimiter ; |
|
166 |
||
167 |
show create procedure nicesp; |
|
168 |
drop procedure nicesp; |
|
169 |
||
170 |
##============================================================================
|
|
171 |
## Comments inside triggers |
|
172 |
##============================================================================
|
|
173 |
||
174 |
drop trigger if exists t1_empty; |
|
175 |
||
176 |
create trigger t1_empty after delete on t1 |
|
177 |
for each row |
|
178 |
begin
|
|
179 |
end; |
|
180 |
||
181 |
show create trigger t1_empty; |
|
182 |
||
183 |
drop trigger if exists t1_bi; |
|
184 |
||
185 |
delimiter | |
|
186 |
||
187 |
create trigger t1_bi before insert on t1 |
|
188 |
for each row |
|
189 |
begin
|
|
190 |
# comment 1a |
|
191 |
-- comment 1b
|
|
192 |
/*
|
|
193 |
comment 1c
|
|
194 |
*/
|
|
195 |
-- declare some variables here
|
|
196 |
declare b int; |
|
197 |
declare c float; |
|
198 |
||
199 |
-- do more stuff here
|
|
200 |
-- commented nicely and so on
|
|
201 |
||
202 |
-- famous last words ...
|
|
203 |
set NEW.data := 12; |
|
204 |
end| |
|
205 |
||
206 |
delimiter ; |
|
207 |
||
208 |
show create trigger t1_bi; |
|
209 |
||
210 |
# also make sure the trigger still works |
|
211 |
insert into t1(id) value ("trig"); |
|
212 |
select * from t1; |
|
213 |
||
214 |
##============================================================================
|
|
215 |
## Cleanup |
|
216 |
##============================================================================
|
|
217 |
||
218 |
drop table t1; |