1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
|
SET sql_mode=ORACLE;
--echo #
--echo # MDEV-15620 Crash when using "SET @@NEW.a=expr" inside a trigger
--echo #
CREATE TABLE t1 (a INT);
--error ER_UNKNOWN_STRUCTURED_VARIABLE
CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW SET @@NEW.a=0;
DROP TABLE t1;
--echo #
--echo # MDEV-15615 Unexpected syntax error instead of "Unknown system variable" inside an SP
--echo #
DELIMITER $$;
--error ER_UNKNOWN_SYSTEM_VARIABLE
DECLARE
a INT;
BEGIN
SET GLOBAL a=10;
END;
$$
DELIMITER ;$$
--echo #
--echo # MDEV-16202 Latest changes made erroneously some keywords reserved in sql_mode=ORACLE
--echo #
DELIMITER $$;
CREATE PROCEDURE p1(name VARCHAR(64), pattern TEXT) AS
query TEXT DEFAULT REPLACE(pattern, 'name', name);
BEGIN
SELECT query AS '';
EXECUTE IMMEDIATE query;
EXCEPTION
WHEN OTHERS THEN
BEGIN
SHOW ERRORS;
END;
END;
$$
CREATE PROCEDURE p2(name VARCHAR(64)) AS
BEGIN
CALL p1(name, 'DECLARE name INT; BEGIN name:=10; SELECT name; END');
EXECUTE IMMEDIATE REPLACE('CREATE TABLE t1 (name INT)', 'name', name);
CALL p1(name, 'SELECT name FROM t1');
CALL p1(name, 'SELECT name ''alias'' FROM t1');
CALL p1(name, 'SELECT name()');
CALL p1(name, 'SELECT name.name()');
CALL p1(name, 'SELECT name DATE FROM t1');
CALL p1(name, 'SELECT name HISTORY FROM t1');
CALL p1(name, 'SELECT name NEXT FROM t1');
CALL p1(name, 'SELECT name PERIOD FROM t1');
CALL p1(name, 'SELECT name PREVIOUS FROM t1');
CALL p1(name, 'SELECT name SYSTEM FROM t1');
CALL p1(name, 'SELECT name SYSTEM_TIME FROM t1');
CALL p1(name, 'SELECT name TIME FROM t1');
CALL p1(name, 'SELECT name TIMESTAMP FROM t1');
CALL p1(name, 'SELECT name TRANSACTION FROM t1');
CALL p1(name, 'SELECT name VALUE FROM t1');
CALL p1(name, 'SELECT name VERSIONING FROM t1');
CALL p1(name, 'SELECT name WITHOUT FROM t1');
DROP TABLE t1;
END;
$$
DELIMITER ;$$
--disable_column_names
CALL p2('date');
CALL p2('history');
CALL p2('next');
CALL p2('period');
CALL p2('previous');
CALL p2('system');
CALL p2('system_time');
CALL p2('time');
CALL p2('timestamp');
CALL p2('transaction');
CALL p2('value');
CALL p2('versioning');
CALL p2('without');
--enable_column_names
DROP PROCEDURE p2;
DROP PROCEDURE p1;
--echo #
--echo # MDEV-16244 sql_mode=ORACLE: Some keywords do not work in variable declarations
--echo #
SET sql_mode=ORACLE;
DELIMITER /;
DECLARE
do INT;
BEGIN
SELECT do INTO do FROM DUAL;
END;
/
DECLARE
handler INT;
BEGIN
SELECT handler INTO handler FROM DUAL;
END;
/
DECLARE
repair INT;
BEGIN
SELECT repair INTO repair FROM DUAL;
END;
/
DECLARE
shutdown INT;
BEGIN
SELECT shutdown INTO shutdown FROM DUAL;
END;
/
DECLARE
truncate INT;
BEGIN
SELECT truncate INTO truncate FROM DUAL;
END;
/
DECLARE
close INT;
BEGIN
SELECT close INTO close FROM DUAL;
END;
/
DECLARE
commit INT;
BEGIN
SELECT commit INTO commit FROM DUAL;
END;
/
DECLARE
open INT;
BEGIN
SELECT open INTO open FROM DUAL;
END;
/
DECLARE
rollback INT;
BEGIN
SELECT rollback INTO rollback FROM DUAL;
END;
/
DECLARE
savepoint INT;
BEGIN
SELECT savepoint INTO savepoint FROM DUAL;
END;
/
DECLARE
contains INT;
BEGIN
SELECT contains INTO contains FROM DUAL;
END;
/
DECLARE
language INT;
BEGIN
SELECT language INTO language FROM DUAL;
END;
/
DECLARE
no INT;
BEGIN
SELECT no INTO no FROM DUAL;
END;
/
DECLARE
charset INT;
BEGIN
SELECT charset INTO charset FROM DUAL;
END;
/
DECLARE
follows INT;
BEGIN
SELECT follows INTO follows FROM DUAL;
END;
/
DECLARE
precedes INT;
BEGIN
SELECT precedes INTO precedes FROM DUAL;
END;
/
DELIMITER ;/
--echo #
--echo # MDEV-16464 Oracle Comp.: Sql-Error on "SELECT name, comment FROM mysql.proc"
--echo #
SET sql_mode=ORACLE;
SELECT name, comment FROM mysql.proc WHERE db='test';
CREATE TABLE comment (comment INT);
SELECT comment FROM comment;
SELECT comment comment FROM comment comment;
SELECT comment AS comment FROM comment AS comment;
DROP TABLE comment;
DELIMITER /;
DECLARE
comment INT;
BEGIN
SELECT comment INTO comment FROM DUAL;
END;
/
DELIMITER ;/
DELIMITER /;
CREATE PROCEDURE comment COMMENT 'test' AS
BEGIN
SELECT 1;
END;
/
BEGIN
comment;
END;
/
DELIMITER ;/
CALL comment();
CALL comment;
DROP PROCEDURE comment;
DELIMITER /;
CREATE FUNCTION comment RETURN INT COMMENT 'test' AS
BEGIN
RETURN 1;
END;
/
DELIMITER ;/
enable_prepare_warnings;
SELECT test.comment() FROM DUAL;
disable_prepare_warnings;
DROP FUNCTION comment;
--echo #
--echo # MDEV-17660 sql_mode=ORACLE: Some keywords do not work as label names: history, system, versioning, without
--echo #
DELIMITER /;
BEGIN
<<date_format>>
NULL;
END;
/
DELIMITER ;/
DELIMITER /;
BEGIN
<<decode>>
NULL;
END;
/
DELIMITER ;/
DELIMITER /;
BEGIN
<<history>>
NULL;
END;
/
DELIMITER ;/
DELIMITER /;
BEGIN
<<system>>
NULL;
END;
/
DELIMITER ;/
DELIMITER /;
BEGIN
<<versioning>>
NULL;
END;
/
DELIMITER ;/
DELIMITER /;
BEGIN
<<without>>
NULL;
END;
/
DELIMITER ;/
--echo #
--echo # MDEV-17666 sql_mode=ORACLE: Keyword ELSEIF should not be reserved
--echo #
DELIMITER /;
DECLARE
ELSEIF INT;
BEGIN
ELSEIF:=1;
END;
/
DELIMITER ;/
DELIMITER /;
BEGIN
<<ELSEIF>>
NULL;
END;
/
DELIMITER ;/
--echo #
--echo # MDEV-17693 Shift/reduce conflicts for NAMES,ROLE,PASSWORD in the option_value_no_option_type grammar
--echo #
CREATE TABLE names (names INT);
SELECT names FROM names AS names;
DROP TABLE names;
CREATE TABLE password (password INT);
SELECT password FROM password AS password;
DROP TABLE password;
CREATE TABLE role (role INT);
SELECT role FROM role AS role;
DROP TABLE role;
DELIMITER $$;
DECLARE
names VARCHAR(32) DEFAULT '[names]';
password VARCHAR(32) DEFAULT '[password]';
role VARCHAR(32) DEFAULT '[role]';
BEGIN
<<names>>
SELECT names;
<<password>>
SELECT password;
<<role>>
SELECT role;
END;
$$
DELIMITER ;$$
DELIMITER $$;
--error ER_SP_BAD_VAR_SHADOW
DECLARE
names VARCHAR(32);
BEGIN
SET names='[names]';
END;
$$
DELIMITER ;$$
DELIMITER $$;
--error ER_SP_BAD_VAR_SHADOW
DECLARE
password VARCHAR(32);
BEGIN
SET password='[password]';
END;
$$
DELIMITER ;$$
DELIMITER $$;
DECLARE
role VARCHAR(32);
BEGIN
SET role='[role]';
END;
$$
DELIMITER ;$$
--error ER_UNKNOWN_SYSTEM_VARIABLE
SELECT @@GLOBAL.names;
--error ER_UNKNOWN_SYSTEM_VARIABLE
SELECT @@GLOBAL.password;
--error ER_UNKNOWN_SYSTEM_VARIABLE
SELECT @@GLOBAL.role;
--echo #
--echo # MDEV-22822 sql_mode="oracle" cannot declare without variable errors
--echo #
--echo # It's OK to have no declarations between DECLARE and BEGIN.
--echo #
DELIMITER //;
BEGIN
DECLARE
BEGIN
NULL;
END;
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
//
DELIMITER ;//
DELIMITER //;
DECLARE
BEGIN
NULL;
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
//
DELIMITER ;//
DELIMITER //;
BEGIN
<<lab>>
DECLARE
BEGIN
NULL;
END;
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
//
DELIMITER ;//
--echo #
--echo # End of 10.3 tests
--echo #
--echo #
--echo # MDEV-21998: Server crashes in st_select_lex::add_table_to_list
--echo # upon mix of KILL and sequences
--echo #
--error ER_SUBQUERIES_NOT_SUPPORTED
KILL ( SELECT 1 ) + LASTVAL(s);
--error ER_SUBQUERIES_NOT_SUPPORTED
KILL LASTVAL(s);
--echo #
--echo # MDEV-23094: Multiple calls to a Stored Procedure from another
--echo # Stored Procedure crashes server
--echo #
create table t1 (id1 int primary key, data1 int);
create table t2 (id2 int primary key, data2 int);
delimiter //;
create procedure p1(id int,dt int) as
begin
if (exists(select * from t1 where id1 = id and data1 = dt) or
not exists (select * from t2 where id2 = id and data2 = dt))
then
select 1;
end if;
end //
delimiter ;//
call p1(1,2);
call p1(1,2);
drop procedure p1;
delimiter //;
create procedure p1(id int, dt int) as
begin
case (exists(select * from t1 where id1 = id and data1 = dt) or
not exists (select * from t2 where id2 = id and data2 = dt))
when 1 then
select 1;
else
select 0;
end case;
end //
delimiter ;//
call p1(1,2);
call p1(1,2);
drop procedure p1;
delimiter //;
create procedure p1(id int, dt int) as
begin
declare wcont int default 1;
begin
while (exists(select * from t1 where id1 = id and data1 = dt) or
not exists (select * from t2 where id2 = id and data2 = dt)) and wcont
loop
select 1;
set wcont=0;
end loop;
end;
end //
delimiter ;//
call p1(1,2);
call p1(1,2);
drop procedure p1;
delimiter //;
create procedure p1(id int, dt int) as
begin
declare count int default 1;
begin
repeat
select 1;
set count=count+1;
until (exists(select * from t1 where id1 = id and data1 = dt) or
not exists (select * from t2 where id2 = id and data2 = dt)) and
count < 3
end repeat;
end;
end //
delimiter ;//
call p1(1,2);
call p1(1,2);
drop procedure p1;
delimiter //;
create procedure p1(id int, dt int) as
begin
for i in 1..(exists(select * from t1 where id1 = id and data1 = dt) or
not exists (select * from t2 where id2 = id and data2 = dt))
loop
select 1;
end loop;
end //
delimiter ;//
call p1(1,2);
call p1(1,2);
drop procedure p1;
delimiter //;
set sql_mode=ORACLE;
create or replace procedure p1(id int, dt int) as
begin
while (1)
loop
exit when (exists(select * from t1 where id1 = id and data1 = dt) or
not exists (select * from t2 where id2 = id and data2 = dt));
end loop;
end;
//
delimiter ;//
call p1(1,2);
call p1(1,2);
drop procedure p1;
drop table t1,t2;
--echo # End of 10.4 tests
--echo #
--echo # Start of 10.5 tests
--echo #
--echo #
--echo # MDEV-20734 Allow reserved keywords as user defined type names
--echo #
--error ER_UNKNOWN_DATA_TYPE
CREATE TABLE t1 (a DUAL);
--error ER_UNKNOWN_DATA_TYPE
SELECT CAST(1 AS DUAL);
--echo #
--echo # MDEV-20735 Allow non-reserved keywords as user defined type names
--echo #
--error ER_UNKNOWN_DATA_TYPE
CREATE TABLE t1 (a ASCII);
--error ER_UNKNOWN_DATA_TYPE
SELECT CAST(1 AS ASCII);
--error ER_UNKNOWN_DATA_TYPE
CREATE TABLE t1 (a LANGUAGE);
--error ER_UNKNOWN_DATA_TYPE
SELECT CAST(1 AS LANGUAGE);
--error ER_UNKNOWN_DATA_TYPE
CREATE TABLE t1 (a CLOSE);
--error ER_UNKNOWN_DATA_TYPE
SELECT CAST(1 AS CLOSE);
--error ER_UNKNOWN_DATA_TYPE
CREATE TABLE t1 (a NAMES);
--error ER_UNKNOWN_DATA_TYPE
SELECT CAST(1 AS NAMES);
--error ER_UNKNOWN_DATA_TYPE
CREATE TABLE t1 (a END);
--error ER_UNKNOWN_DATA_TYPE
SELECT CAST(1 AS END);
--error ER_UNKNOWN_DATA_TYPE
CREATE TABLE t1 (a GLOBAL);
--error ER_UNKNOWN_DATA_TYPE
SELECT CAST(1 AS GLOBAL);
--error ER_UNKNOWN_DATA_TYPE
CREATE TABLE t1 (a ACTION);
--error ER_UNKNOWN_DATA_TYPE
SELECT CAST(1 AS ACTION);
--error ER_UNKNOWN_DATA_TYPE
CREATE TABLE t1 (a BEGIN);
--error ER_UNKNOWN_DATA_TYPE
SELECT CAST(1 AS BEGIN);
--echo #
--echo # End of 10.5 tests
--echo #
|