summaryrefslogtreecommitdiff
path: root/mysql-test/main/sp-vars.result
blob: a755f8e739f2ac84d0e77728fcb239caa249c8c5 (plain)
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
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
DROP PROCEDURE IF EXISTS sp_vars_check_dflt;
DROP PROCEDURE IF EXISTS sp_vars_check_assignment;
DROP FUNCTION IF EXISTS sp_vars_check_ret1;
DROP FUNCTION IF EXISTS sp_vars_check_ret2;
DROP FUNCTION IF EXISTS sp_vars_check_ret3;
DROP FUNCTION IF EXISTS sp_vars_check_ret4;
DROP FUNCTION IF EXISTS sp_vars_div_zero;
SET @@sql_mode = 'ansi';
CREATE PROCEDURE sp_vars_check_dflt()
BEGIN
DECLARE v1 TINYINT DEFAULT 1e200;
DECLARE v1u TINYINT UNSIGNED DEFAULT 1e200;
DECLARE v2 TINYINT DEFAULT -1e200;
DECLARE v2u TINYINT UNSIGNED DEFAULT -1e200;
DECLARE v3 TINYINT DEFAULT 300;
DECLARE v3u TINYINT UNSIGNED DEFAULT 300;
DECLARE v4 TINYINT DEFAULT -300;
DECLARE v4u TINYINT UNSIGNED DEFAULT -300;
DECLARE v5 TINYINT DEFAULT 10 * 10 * 10;
DECLARE v5u TINYINT UNSIGNED DEFAULT 10 * 10 * 10;
DECLARE v6 TINYINT DEFAULT -10 * 10 * 10;
DECLARE v6u TINYINT UNSIGNED DEFAULT -10 * 10 * 10;
DECLARE v7 TINYINT DEFAULT '10';
DECLARE v8 TINYINT DEFAULT '10 ';
DECLARE v9 TINYINT DEFAULT ' 10 ';
DECLARE v10 TINYINT DEFAULT 'String 10 ';
DECLARE v11 TINYINT DEFAULT 'String10';
DECLARE v12 TINYINT DEFAULT '10 String';
DECLARE v13 TINYINT DEFAULT '10String';
DECLARE v14 TINYINT DEFAULT concat('10', ' ');
DECLARE v15 TINYINT DEFAULT concat(' ', '10');
DECLARE v16 TINYINT DEFAULT concat('Hello, ', 'world');
DECLARE v17 DECIMAL(64, 2) DEFAULT 12;
DECLARE v18 DECIMAL(64, 2) DEFAULT 12.123;
DECLARE v19 DECIMAL(64, 2) DEFAULT 11 + 1;
DECLARE v20 DECIMAL(64, 2) DEFAULT 12 + 0.123;
SELECT v1, v1u, v2, v2u, v3, v3u, v4, v4u;
SELECT v5, v5u, v6, v6u;
SELECT v7, v8, v9, v10, v11, v12, v13, v14, v15, v16;
SELECT v17, v18, v19, v20;
END|
CREATE PROCEDURE sp_vars_check_assignment()
BEGIN
DECLARE i1, i2, i3, i4 TINYINT;
DECLARE u1, u2, u3, u4 TINYINT UNSIGNED;
DECLARE d1, d2, d3 DECIMAL(64, 2);
SET i1 = 1e200;
SET i2 = -1e200;
SET i3 = 300;
SET i4 = -300;
SELECT i1, i2, i3, i4;
SET i1 = 10 * 10 * 10;
SET i2 = -10 * 10 * 10;
SET i3 = sign(10 * 10) * 10 * 20;
SET i4 = sign(-10 * 10) * -10 * 20;
SELECT i1, i2, i3, i4;
SET u1 = 1e200;
SET u2 = -1e200;
SET u3 = 300;
SET u4 = -300;
SELECT u1, u2, u3, u4;
SET u1 = 10 * 10 * 10;
SET u2 = -10 * 10 * 10;
SET u3 = sign(10 * 10) * 10 * 20;
SET u4 = sign(-10 * 10) * -10 * 20;
SELECT u1, u2, u3, u4;
SET d1 = 1234;
SET d2 = 1234.12;
SET d3 = 1234.1234;
SELECT d1, d2, d3;
SET d1 = 12 * 100 + 34;
SET d2 = 12 * 100 + 34 + 0.12;
SET d3 = 12 * 100 + 34 + 0.1234;
SELECT d1, d2, d3;
END|
CREATE FUNCTION sp_vars_check_ret1() RETURNS TINYINT
BEGIN
RETURN 1e200;
END|
CREATE FUNCTION sp_vars_check_ret2() RETURNS TINYINT
BEGIN
RETURN 10 * 10 * 10;
END|
CREATE FUNCTION sp_vars_check_ret3() RETURNS TINYINT
BEGIN
RETURN 'Hello, world';
END|
CREATE FUNCTION sp_vars_check_ret4() RETURNS DECIMAL(64, 2)
BEGIN
RETURN 12 * 10 + 34 + 0.1234;
END|
CREATE FUNCTION sp_vars_div_zero() RETURNS INTEGER
BEGIN
DECLARE div_zero INTEGER;
SELECT 1/0 INTO div_zero;
RETURN div_zero;
END|

---------------------------------------------------------------
Calling the routines, created in ANSI mode.
---------------------------------------------------------------

CALL sp_vars_check_dflt();
v1	v1u	v2	v2u	v3	v3u	v4	v4u
127	255	-128	0	127	255	-128	0
v5	v5u	v6	v6u
127	255	-128	0
v7	v8	v9	v10	v11	v12	v13	v14	v15	v16
10	10	10	0	0	10	10	10	10	0
v17	v18	v19	v20
12.00	12.12	12.00	12.12
Warnings:
Note	1265	Data truncated for column 'v20' at row 1
CALL sp_vars_check_assignment();
i1	i2	i3	i4
127	-128	127	-128
i1	i2	i3	i4
127	-128	127	127
u1	u2	u3	u4
255	0	255	0
u1	u2	u3	u4
255	0	200	200
d1	d2	d3
1234.00	1234.12	1234.12
d1	d2	d3
1234.00	1234.12	1234.12
Warnings:
Note	1265	Data truncated for column 'd3' at row 1
SELECT sp_vars_check_ret1();
sp_vars_check_ret1()
127
Warnings:
Warning	1264	Out of range value for column 'sp_vars_check_ret1()' at row 1
SELECT sp_vars_check_ret2();
sp_vars_check_ret2()
127
Warnings:
Warning	1264	Out of range value for column 'sp_vars_check_ret2()' at row 1
SELECT sp_vars_check_ret3();
sp_vars_check_ret3()
0
Warnings:
Warning	1366	Incorrect integer value: 'Hello, world' for column ``.``.`sp_vars_check_ret3()` at row 1
SELECT sp_vars_check_ret4();
sp_vars_check_ret4()
154.12
Warnings:
Note	1265	Data truncated for column 'sp_vars_check_ret4()' at row 1
SELECT sp_vars_div_zero();
sp_vars_div_zero()
NULL
SET @@sql_mode = 'traditional';

---------------------------------------------------------------
Calling in TRADITIONAL mode the routines, created in ANSI mode.
---------------------------------------------------------------

CALL sp_vars_check_dflt();
v1	v1u	v2	v2u	v3	v3u	v4	v4u
127	255	-128	0	127	255	-128	0
v5	v5u	v6	v6u
127	255	-128	0
v7	v8	v9	v10	v11	v12	v13	v14	v15	v16
10	10	10	0	0	10	10	10	10	0
v17	v18	v19	v20
12.00	12.12	12.00	12.12
Warnings:
Note	1265	Data truncated for column 'v20' at row 1
CALL sp_vars_check_assignment();
i1	i2	i3	i4
127	-128	127	-128
i1	i2	i3	i4
127	-128	127	127
u1	u2	u3	u4
255	0	255	0
u1	u2	u3	u4
255	0	200	200
d1	d2	d3
1234.00	1234.12	1234.12
d1	d2	d3
1234.00	1234.12	1234.12
Warnings:
Note	1265	Data truncated for column 'd3' at row 1
SELECT sp_vars_check_ret1();
sp_vars_check_ret1()
127
Warnings:
Warning	1264	Out of range value for column 'sp_vars_check_ret1()' at row 1
SELECT sp_vars_check_ret2();
sp_vars_check_ret2()
127
Warnings:
Warning	1264	Out of range value for column 'sp_vars_check_ret2()' at row 1
SELECT sp_vars_check_ret3();
sp_vars_check_ret3()
0
Warnings:
Warning	1366	Incorrect integer value: 'Hello, world' for column ``.``.`sp_vars_check_ret3()` at row 1
SELECT sp_vars_check_ret4();
sp_vars_check_ret4()
154.12
Warnings:
Note	1265	Data truncated for column 'sp_vars_check_ret4()' at row 1
SELECT sp_vars_div_zero();
sp_vars_div_zero()
NULL
DROP PROCEDURE sp_vars_check_dflt;
DROP PROCEDURE sp_vars_check_assignment;
DROP FUNCTION sp_vars_check_ret1;
DROP FUNCTION sp_vars_check_ret2;
DROP FUNCTION sp_vars_check_ret3;
DROP FUNCTION sp_vars_check_ret4;
DROP FUNCTION sp_vars_div_zero;
CREATE PROCEDURE sp_vars_check_dflt()
BEGIN
DECLARE v1 TINYINT DEFAULT 1e200;
DECLARE v1u TINYINT UNSIGNED DEFAULT 1e200;
DECLARE v2 TINYINT DEFAULT -1e200;
DECLARE v2u TINYINT UNSIGNED DEFAULT -1e200;
DECLARE v3 TINYINT DEFAULT 300;
DECLARE v3u TINYINT UNSIGNED DEFAULT 300;
DECLARE v4 TINYINT DEFAULT -300;
DECLARE v4u TINYINT UNSIGNED DEFAULT -300;
DECLARE v5 TINYINT DEFAULT 10 * 10 * 10;
DECLARE v5u TINYINT UNSIGNED DEFAULT 10 * 10 * 10;
DECLARE v6 TINYINT DEFAULT -10 * 10 * 10;
DECLARE v6u TINYINT UNSIGNED DEFAULT -10 * 10 * 10;
DECLARE v7 TINYINT DEFAULT '10';
DECLARE v8 TINYINT DEFAULT '10 ';
DECLARE v9 TINYINT DEFAULT ' 10 ';
DECLARE v10 TINYINT DEFAULT 'String 10 ';
DECLARE v11 TINYINT DEFAULT 'String10';
DECLARE v12 TINYINT DEFAULT '10 String';
DECLARE v13 TINYINT DEFAULT '10String';
DECLARE v14 TINYINT DEFAULT concat('10', ' ');
DECLARE v15 TINYINT DEFAULT concat(' ', '10');
DECLARE v16 TINYINT DEFAULT concat('Hello, ', 'world');
DECLARE v17 DECIMAL(64, 2) DEFAULT 12;
DECLARE v18 DECIMAL(64, 2) DEFAULT 12.123;
DECLARE v19 DECIMAL(64, 2) DEFAULT 11 + 1;
DECLARE v20 DECIMAL(64, 2) DEFAULT 12 + 0.123;
SELECT v1, v1u, v2, v2u, v3, v3u, v4, v4u;
SELECT v5, v5u, v6, v6u;
SELECT v7, v8, v9, v10, v11, v12, v13, v14, v15, v16;
SELECT v17, v18, v19, v20;
END|
CREATE PROCEDURE sp_vars_check_assignment()
BEGIN
DECLARE i1, i2, i3, i4 TINYINT;
DECLARE u1, u2, u3, u4 TINYINT UNSIGNED;
DECLARE d1, d2, d3 DECIMAL(64, 2);
SET i1 = 1e200;
SET i2 = -1e200;
SET i3 = 300;
SET i4 = -300;
SELECT i1, i2, i3, i4;
SET i1 = 10 * 10 * 10;
SET i2 = -10 * 10 * 10;
SET i3 = sign(10 * 10) * 10 * 20;
SET i4 = sign(-10 * 10) * -10 * 20;
SELECT i1, i2, i3, i4;
SET u1 = 1e200;
SET u2 = -1e200;
SET u3 = 300;
SET u4 = -300;
SELECT u1, u2, u3, u4;
SET u1 = 10 * 10 * 10;
SET u2 = -10 * 10 * 10;
SET u3 = sign(10 * 10) * 10 * 20;
SET u4 = sign(-10 * 10) * -10 * 20;
SELECT u1, u2, u3, u4;
SET d1 = 1234;
SET d2 = 1234.12;
SET d3 = 1234.1234;
SELECT d1, d2, d3;
SET d1 = 12 * 100 + 34;
SET d2 = 12 * 100 + 34 + 0.12;
SET d3 = 12 * 100 + 34 + 0.1234;
SELECT d1, d2, d3;
END|
CREATE FUNCTION sp_vars_check_ret1() RETURNS TINYINT
BEGIN
RETURN 1e200;
END|
CREATE FUNCTION sp_vars_check_ret2() RETURNS TINYINT
BEGIN
RETURN 10 * 10 * 10;
END|
CREATE FUNCTION sp_vars_check_ret3() RETURNS TINYINT
BEGIN
RETURN 'Hello, world';
END|
CREATE FUNCTION sp_vars_check_ret4() RETURNS DECIMAL(64, 2)
BEGIN
RETURN 12 * 10 + 34 + 0.1234;
END|
CREATE FUNCTION sp_vars_div_zero() RETURNS INTEGER
BEGIN
DECLARE div_zero INTEGER;
SELECT 1/0 INTO div_zero;
RETURN div_zero;
END|

---------------------------------------------------------------
Calling the routines, created in TRADITIONAL mode.
---------------------------------------------------------------

CALL sp_vars_check_dflt();
ERROR 22003: Out of range value for column 'v1' at row 1
CALL sp_vars_check_assignment();
ERROR 22003: Out of range value for column 'i1' at row 1
SELECT sp_vars_check_ret1();
ERROR 22003: Out of range value for column 'sp_vars_check_ret1()' at row 1
SELECT sp_vars_check_ret2();
ERROR 22003: Out of range value for column 'sp_vars_check_ret2()' at row 1
SELECT sp_vars_check_ret3();
ERROR 22007: Incorrect integer value: 'Hello, world' for column ``.``.`sp_vars_check_ret3()` at row 1
SELECT sp_vars_check_ret4();
sp_vars_check_ret4()
154.12
Warnings:
Note	1265	Data truncated for column 'sp_vars_check_ret4()' at row 1
SELECT sp_vars_div_zero();
ERROR 22012: Division by 0
SET @@sql_mode = 'ansi';
DROP PROCEDURE sp_vars_check_dflt;
DROP PROCEDURE sp_vars_check_assignment;
DROP FUNCTION sp_vars_check_ret1;
DROP FUNCTION sp_vars_check_ret2;
DROP FUNCTION sp_vars_check_ret3;
DROP FUNCTION sp_vars_check_ret4;
DROP FUNCTION sp_vars_div_zero;

---------------------------------------------------------------
BIT data type tests
---------------------------------------------------------------

DROP PROCEDURE IF EXISTS p1;
CREATE PROCEDURE p1()
BEGIN
DECLARE v1 BIT;
DECLARE v2 BIT(1);
DECLARE v3 BIT(3) DEFAULT b'101';
DECLARE v4 BIT(64) DEFAULT 0x5555555555555555;
DECLARE v5 BIT(3);
DECLARE v6 BIT(64);
DECLARE v7 BIT(8) DEFAULT 128;
DECLARE v8 BIT(8) DEFAULT '128';
DECLARE v9 BIT(8) DEFAULT ' 128';
DECLARE v10 BIT(8) DEFAULT 'x 128';
SET v1 = v4;
SET v2 = 0;
SET v5 = v4; # check overflow
SET v6 = v3; # check padding
SELECT HEX(v1);
SELECT HEX(v2);
SELECT HEX(v3);
SELECT HEX(v4);
SELECT HEX(v5);
SELECT HEX(v6);
SELECT HEX(v7);
SELECT HEX(v8);
SELECT HEX(v9);
SELECT HEX(v10);
END|
CALL p1();
HEX(v1)
1
HEX(v2)
0
HEX(v3)
5
HEX(v4)
5555555555555555
HEX(v5)
7
HEX(v6)
5
HEX(v7)
80
HEX(v8)
FF
HEX(v9)
FF
HEX(v10)
FF
Warnings:
Warning	1264	Out of range value for column 'v5' at row 1
DROP PROCEDURE p1;

---------------------------------------------------------------
CASE expression tests.
---------------------------------------------------------------

DROP PROCEDURE IF EXISTS p1;
Warnings:
Note	1305	PROCEDURE test.p1 does not exist
DROP PROCEDURE IF EXISTS p2;
Warnings:
Note	1305	PROCEDURE test.p2 does not exist
DROP TABLE IF EXISTS t1;
Warnings:
Note	1051	Unknown table 'test.t1'
CREATE TABLE t1(log_msg VARCHAR(1024));
CREATE PROCEDURE p1(arg VARCHAR(255))
BEGIN
INSERT INTO t1 VALUES('p1: step1');
CASE arg * 10
WHEN 10 * 10 THEN
INSERT INTO t1 VALUES('p1: case1: on 10');
WHEN 10 * 10 + 10 * 10 THEN
BEGIN
CASE arg / 10
WHEN 1 THEN
INSERT INTO t1 VALUES('p1: case1: case2: on 1');
WHEN 2 THEN
BEGIN
DECLARE i TINYINT DEFAULT 10;
WHILE i > 0 DO
INSERT INTO t1 VALUES(CONCAT('p1: case1: case2: loop: i: ', i));
CASE MOD(i, 2)
WHEN 0 THEN
INSERT INTO t1 VALUES('p1: case1: case2: loop: i is even');
WHEN 1 THEN
INSERT INTO t1 VALUES('p1: case1: case2: loop: i is odd');
ELSE
INSERT INTO t1 VALUES('p1: case1: case2: loop: ERROR');
END CASE;
SET i = i - 1;
END WHILE;
END;
ELSE
INSERT INTO t1 VALUES('p1: case1: case2: ERROR');
END CASE;
CASE arg
WHEN 10 THEN
INSERT INTO t1 VALUES('p1: case1: case3: on 10');
WHEN 20 THEN
INSERT INTO t1 VALUES('p1: case1: case3: on 20');
ELSE
INSERT INTO t1 VALUES('p1: case1: case3: ERROR');
END CASE;
END;
ELSE
INSERT INTO t1 VALUES('p1: case1: ERROR');
END CASE;
CASE arg * 10
WHEN 10 * 10 THEN
INSERT INTO t1 VALUES('p1: case4: on 10');
WHEN 10 * 10 + 10 * 10 THEN
BEGIN
CASE arg / 10
WHEN 1 THEN
INSERT INTO t1 VALUES('p1: case4: case5: on 1');
WHEN 2 THEN
BEGIN
DECLARE i TINYINT DEFAULT 10;
WHILE i > 0 DO
INSERT INTO t1 VALUES(CONCAT('p1: case4: case5: loop: i: ', i));
CASE MOD(i, 2)
WHEN 0 THEN
INSERT INTO t1 VALUES('p1: case4: case5: loop: i is even');
WHEN 1 THEN
INSERT INTO t1 VALUES('p1: case4: case5: loop: i is odd');
ELSE
INSERT INTO t1 VALUES('p1: case4: case5: loop: ERROR');
END CASE;
SET i = i - 1;
END WHILE;
END;
ELSE
INSERT INTO t1 VALUES('p1: case4: case5: ERROR');
END CASE;
CASE arg
WHEN 10 THEN
INSERT INTO t1 VALUES('p1: case4: case6: on 10');
WHEN 20 THEN
INSERT INTO t1 VALUES('p1: case4: case6: on 20');
ELSE
INSERT INTO t1 VALUES('p1: case4: case6: ERROR');
END CASE;
END;
ELSE
INSERT INTO t1 VALUES('p1: case4: ERROR');
END CASE;
END|
CREATE PROCEDURE p2()
BEGIN
DECLARE i TINYINT DEFAULT 3;
WHILE i > 0 DO
IF MOD(i, 2) = 0 THEN
SET @_test_session_var = 10;
ELSE
SET @_test_session_var = 'test';
END IF;
CASE @_test_session_var
WHEN 10 THEN
INSERT INTO t1 VALUES('p2: case: numerical type');
WHEN 'test' THEN
INSERT INTO t1 VALUES('p2: case: string type');
ELSE
INSERT INTO t1 VALUES('p2: case: ERROR');
END CASE;
SET i = i - 1;
END WHILE;
END|
CALL p1(10);
CALL p1(20);
CALL p2();
SELECT * FROM t1;
log_msg
p1: step1
p1: case1: on 10
p1: case4: on 10
p1: step1
p1: case1: case2: loop: i: 10
p1: case1: case2: loop: i is even
p1: case1: case2: loop: i: 9
p1: case1: case2: loop: i is odd
p1: case1: case2: loop: i: 8
p1: case1: case2: loop: i is even
p1: case1: case2: loop: i: 7
p1: case1: case2: loop: i is odd
p1: case1: case2: loop: i: 6
p1: case1: case2: loop: i is even
p1: case1: case2: loop: i: 5
p1: case1: case2: loop: i is odd
p1: case1: case2: loop: i: 4
p1: case1: case2: loop: i is even
p1: case1: case2: loop: i: 3
p1: case1: case2: loop: i is odd
p1: case1: case2: loop: i: 2
p1: case1: case2: loop: i is even
p1: case1: case2: loop: i: 1
p1: case1: case2: loop: i is odd
p1: case1: case3: on 20
p1: case4: case5: loop: i: 10
p1: case4: case5: loop: i is even
p1: case4: case5: loop: i: 9
p1: case4: case5: loop: i is odd
p1: case4: case5: loop: i: 8
p1: case4: case5: loop: i is even
p1: case4: case5: loop: i: 7
p1: case4: case5: loop: i is odd
p1: case4: case5: loop: i: 6
p1: case4: case5: loop: i is even
p1: case4: case5: loop: i: 5
p1: case4: case5: loop: i is odd
p1: case4: case5: loop: i: 4
p1: case4: case5: loop: i is even
p1: case4: case5: loop: i: 3
p1: case4: case5: loop: i is odd
p1: case4: case5: loop: i: 2
p1: case4: case5: loop: i is even
p1: case4: case5: loop: i: 1
p1: case4: case5: loop: i is odd
p1: case4: case6: on 20
p2: case: string type
p2: case: numerical type
p2: case: string type
DROP PROCEDURE p1;
DROP PROCEDURE p2;
DROP TABLE t1;

---------------------------------------------------------------
BUG#14161
---------------------------------------------------------------

DROP TABLE IF EXISTS t1;
DROP PROCEDURE IF EXISTS p1;
CREATE TABLE t1(col BIGINT UNSIGNED);
INSERT INTO t1 VALUE(18446744073709551614);
CREATE PROCEDURE p1(IN arg BIGINT UNSIGNED)
BEGIN
SELECT arg;
SELECT * FROM t1;
SELECT * FROM t1 WHERE col = arg;
END|
CALL p1(18446744073709551614);
arg
18446744073709551614
col
18446744073709551614
col
18446744073709551614
DROP TABLE t1;
DROP PROCEDURE p1;

---------------------------------------------------------------
BUG#13705
---------------------------------------------------------------

DROP PROCEDURE IF EXISTS p1;
CREATE PROCEDURE p1(x VARCHAR(10), y CHAR(3)) READS SQL DATA
BEGIN
SELECT x, y;
END|
CALL p1('alpha', 'abc');
x	y
alpha	abc
CALL p1('alpha', 'abcdef');
x	y
alpha	abc
Warnings:
Warning	1265	Data truncated for column 'y' at row 1
DROP PROCEDURE p1;

---------------------------------------------------------------
BUG#13675
---------------------------------------------------------------

DROP PROCEDURE IF EXISTS p1;
DROP TABLE IF EXISTS t1;
CREATE PROCEDURE p1(x DATETIME)
BEGIN
CREATE TABLE t1 SELECT x;
SHOW CREATE TABLE t1;
DROP TABLE t1;
END|
CALL p1(NOW());
Table	Create Table
t1	CREATE TABLE "t1" (
  "x" datetime DEFAULT NULL
)
CALL p1('test');
Table	Create Table
t1	CREATE TABLE "t1" (
  "x" datetime DEFAULT NULL
)
Warnings:
Warning	1265	Data truncated for column 'x' at row 1
DROP PROCEDURE p1;

---------------------------------------------------------------
BUG#12976
---------------------------------------------------------------

DROP TABLE IF EXISTS t1;
DROP PROCEDURE IF EXISTS p1;
DROP PROCEDURE IF EXISTS p2;
CREATE TABLE t1(b BIT(1));
INSERT INTO t1(b) VALUES(b'0'), (b'1');
CREATE PROCEDURE p1()
BEGIN
SELECT HEX(b),
b = 0,
b = FALSE,
b IS FALSE,
b = 1,
b = TRUE,
b IS TRUE
FROM t1;
END|
CREATE PROCEDURE p2()
BEGIN
DECLARE vb BIT(1);
SELECT b INTO vb FROM t1 WHERE b = 0;
SELECT HEX(vb),
vb = 0,
vb = FALSE,
vb IS FALSE,
vb = 1,
vb = TRUE,
vb IS TRUE;
SELECT b INTO vb FROM t1 WHERE b = 1;
SELECT HEX(vb),
vb = 0,
vb = FALSE,
vb IS FALSE,
vb = 1,
vb = TRUE,
vb IS TRUE;
END|
call p1();
HEX(b)	b = 0	b = FALSE	b IS FALSE	b = 1	b = TRUE	b IS TRUE
0	1	1	1	0	0	0
1	0	0	0	1	1	1
call p2();
HEX(vb)	vb = 0	vb = FALSE	vb IS FALSE	vb = 1	vb = TRUE	vb IS TRUE
0	1	1	1	0	0	0
HEX(vb)	vb = 0	vb = FALSE	vb IS FALSE	vb = 1	vb = TRUE	vb IS TRUE
1	0	0	0	1	1	1
DROP TABLE t1;
DROP PROCEDURE p1;
DROP PROCEDURE p2;
DROP TABLE IF EXISTS table_12976_a;
DROP TABLE IF EXISTS table_12976_b;
DROP PROCEDURE IF EXISTS proc_12976_a;
DROP PROCEDURE IF EXISTS proc_12976_b;
CREATE TABLE table_12976_a (val bit(1));
CREATE TABLE table_12976_b(
appname varchar(15),
emailperm bit not null default 1,
phoneperm bit not null default 0);
insert into table_12976_b values ('A', b'1', b'1'), ('B', b'0', b'0');
CREATE PROCEDURE proc_12976_a()
BEGIN
declare localvar bit(1);
SELECT val INTO localvar FROM table_12976_a;
SELECT coalesce(localvar, 1)+1, coalesce(val, 1)+1 FROM table_12976_a;
END||
CREATE PROCEDURE proc_12976_b(
name varchar(15),
out ep bit,
out msg varchar(10))
BEGIN
SELECT emailperm into ep FROM table_12976_b where (appname = name);
IF ep is true THEN
SET msg = 'True';
ELSE
SET msg = 'False';
END IF;
END||
INSERT table_12976_a VALUES (0);
call proc_12976_a();
coalesce(localvar, 1)+1	coalesce(val, 1)+1
1	1
UPDATE table_12976_a set val=1;
call proc_12976_a();
coalesce(localvar, 1)+1	coalesce(val, 1)+1
2	2
call proc_12976_b('A', @ep, @msg);
select @ep, @msg;
@ep	@msg
1	True
call proc_12976_b('B', @ep, @msg);
select @ep, @msg;
@ep	@msg
0	False
DROP TABLE table_12976_a;
DROP TABLE table_12976_b;
DROP PROCEDURE proc_12976_a;
DROP PROCEDURE proc_12976_b;

---------------------------------------------------------------
BUG#9572
---------------------------------------------------------------

DROP PROCEDURE IF EXISTS p1;
DROP PROCEDURE IF EXISTS p2;
DROP PROCEDURE IF EXISTS p3;
DROP PROCEDURE IF EXISTS p4;
DROP PROCEDURE IF EXISTS p5;
DROP PROCEDURE IF EXISTS p6;
SET @@sql_mode = 'traditional';
CREATE PROCEDURE p1()
BEGIN
DECLARE v TINYINT DEFAULT 1e200;
SELECT v;
END|
CREATE PROCEDURE p2()
BEGIN
DECLARE v DECIMAL(5) DEFAULT 1e200;
SELECT v;
END|
CREATE PROCEDURE p3()
BEGIN
DECLARE v CHAR(5) DEFAULT 'abcdef';
SELECT v LIKE 'abc___';
END|
CREATE PROCEDURE p4(arg VARCHAR(2))
BEGIN
DECLARE var VARCHAR(1);
SET var := arg;
SELECT arg, var;
END|
CREATE PROCEDURE p5(arg CHAR(2))
BEGIN
DECLARE var CHAR(1);
SET var := arg;
SELECT arg, var;
END|
CREATE PROCEDURE p6(arg DECIMAL(2))
BEGIN
DECLARE var DECIMAL(1);
SET var := arg;
SELECT arg, var;
END|
CALL p1();
ERROR 22003: Out of range value for column 'v' at row 1
CALL p2();
ERROR 22003: Out of range value for column 'v' at row 1
CALL p3();
ERROR 22001: Data too long for column 'v' at row 1
CALL p4('aaa');
ERROR 22001: Data too long for column 'arg' at row 1
CALL p5('aa');
ERROR 22001: Data too long for column 'var' at row 1
CALL p6(10);
ERROR 22003: Out of range value for column 'var' at row 1
SET @@sql_mode = 'ansi';
DROP PROCEDURE p1;
DROP PROCEDURE p2;
DROP PROCEDURE p3;
DROP PROCEDURE p4;
DROP PROCEDURE p5;
DROP PROCEDURE p6;

---------------------------------------------------------------
BUG#9078
---------------------------------------------------------------

DROP PROCEDURE IF EXISTS p1;
CREATE PROCEDURE p1 (arg DECIMAL(64,2))
BEGIN
DECLARE var DECIMAL(64,2);
SET var = arg;
SELECT var;
END|
CALL p1(1929);
var
1929.00
CALL p1(1929.00);
var
1929.00
CALL p1(1929.003);
var
1929.00
Warnings:
Note	1265	Data truncated for column 'arg' at row 1
DROP PROCEDURE p1;

---------------------------------------------------------------
BUG#8768
---------------------------------------------------------------

DROP FUNCTION IF EXISTS f1;
CREATE FUNCTION f1(arg TINYINT UNSIGNED) RETURNS TINYINT
BEGIN
RETURN arg;
END|
SELECT f1(-2500);
f1(-2500)
0
Warnings:
Warning	1264	Out of range value for column 'arg' at row 1
SET @@sql_mode = 'traditional';
SELECT f1(-2500);
ERROR 22003: Out of range value for column 'arg' at row 1
DROP FUNCTION f1;
CREATE FUNCTION f1(arg TINYINT UNSIGNED) RETURNS TINYINT
BEGIN
RETURN arg;
END|
SELECT f1(-2500);
ERROR 22003: Out of range value for column 'arg' at row 1
SET @@sql_mode = 'ansi';
DROP FUNCTION f1;

---------------------------------------------------------------
BUG#8769
---------------------------------------------------------------

DROP FUNCTION IF EXISTS f1;
CREATE FUNCTION f1(arg MEDIUMINT) RETURNS MEDIUMINT
BEGIN
RETURN arg;
END|
SELECT f1(8388699);
f1(8388699)
8388607
Warnings:
Warning	1264	Out of range value for column 'arg' at row 1
SET @@sql_mode = 'traditional';
SELECT f1(8388699);
ERROR 22003: Out of range value for column 'arg' at row 1
DROP FUNCTION f1;
CREATE FUNCTION f1(arg MEDIUMINT) RETURNS MEDIUMINT
BEGIN
RETURN arg;
END|
SELECT f1(8388699);
ERROR 22003: Out of range value for column 'arg' at row 1
SET @@sql_mode = 'ansi';
DROP FUNCTION f1;

---------------------------------------------------------------
BUG#8702
---------------------------------------------------------------

DROP PROCEDURE IF EXISTS p1;
DROP TABLE IF EXISTS t1;
CREATE TABLE t1(col VARCHAR(255));
INSERT INTO t1(col) VALUES('Hello, world!');
CREATE PROCEDURE p1()
BEGIN
DECLARE sp_var INTEGER;
SELECT col INTO sp_var FROM t1 LIMIT 1;
SET @user_var = sp_var;
SELECT sp_var;
SELECT @user_var;
END|
CALL p1();
sp_var
0
@user_var
0
Warnings:
Warning	1366	Incorrect integer value: 'Hello, world!' for column ``.``.`sp_var` at row 1
DROP PROCEDURE p1;
DROP TABLE t1;

---------------------------------------------------------------
BUG#12903
---------------------------------------------------------------

DROP FUNCTION IF EXISTS f1;
DROP TABLE IF EXISTS t1;
CREATE TABLE t1(txt VARCHAR(255));
CREATE FUNCTION f1(arg VARCHAR(255)) RETURNS VARCHAR(255)
BEGIN
DECLARE v1 VARCHAR(255);
DECLARE v2 VARCHAR(255);
SET v1 = CONCAT(LOWER(arg), UPPER(arg));
SET v2 = CONCAT(LOWER(v1), UPPER(v1));
INSERT INTO t1 VALUES(v1), (v2);
RETURN CONCAT(LOWER(arg), UPPER(arg));
END|
SELECT f1('_aBcDe_');
f1('_aBcDe_')
_abcde__ABCDE_
SELECT * FROM t1;
txt
_abcde__ABCDE_
_abcde__abcde__ABCDE__ABCDE_
DROP FUNCTION f1;
DROP TABLE t1;

---------------------------------------------------------------
BUG#13808
---------------------------------------------------------------

DROP PROCEDURE IF EXISTS p1;
DROP PROCEDURE IF EXISTS p2;
DROP FUNCTION IF EXISTS f1;
CREATE PROCEDURE p1(arg ENUM('a', 'b'))
BEGIN
SELECT arg;
END|
CREATE PROCEDURE p2(arg ENUM('a', 'b'))
BEGIN
DECLARE var ENUM('c', 'd') DEFAULT arg;
SELECT arg, var;
END|
CREATE FUNCTION f1(arg ENUM('a', 'b')) RETURNS ENUM('c', 'd')
BEGIN
RETURN arg;
END|
CALL p1('c');
arg

Warnings:
Warning	1265	Data truncated for column 'arg' at row 1
CALL p2('a');
arg	var
a	
Warnings:
Warning	1265	Data truncated for column 'var' at row 1
SELECT f1('a');
f1('a')

Warnings:
Warning	1265	Data truncated for column 'f1('a')' at row 1
DROP PROCEDURE p1;
DROP PROCEDURE p2;
DROP FUNCTION f1;

---------------------------------------------------------------
BUG#13909
---------------------------------------------------------------

DROP PROCEDURE IF EXISTS p1;
DROP PROCEDURE IF EXISTS p2;
CREATE PROCEDURE p1(arg VARCHAR(255))
BEGIN
SELECT CHARSET(arg);
END|
CREATE PROCEDURE p2(arg VARCHAR(255) CHARACTER SET UTF8)
BEGIN
SELECT CHARSET(arg);
END|
CALL p1('t');
CHARSET(arg)
latin1
CALL p1(_UTF8 't');
CHARSET(arg)
latin1
CALL p2('t');
CHARSET(arg)
utf8mb3
CALL p2(_LATIN1 't');
CHARSET(arg)
utf8mb3
DROP PROCEDURE p1;
DROP PROCEDURE p2;

---------------------------------------------------------------
BUG#14188
---------------------------------------------------------------

DROP PROCEDURE IF EXISTS p1;
CREATE PROCEDURE p1(arg1 BINARY(2), arg2 VARBINARY(2))
BEGIN
DECLARE var1 BINARY(2) DEFAULT 0x41;
DECLARE var2 VARBINARY(2) DEFAULT 0x42;
SELECT HEX(arg1), HEX(arg2);
SELECT HEX(var1), HEX(var2);
END|
CALL p1(0x41, 0x42);
HEX(arg1)	HEX(arg2)
4100	42
HEX(var1)	HEX(var2)
4100	42
DROP PROCEDURE p1;

---------------------------------------------------------------
BUG#15148
---------------------------------------------------------------

DROP PROCEDURE IF EXISTS p1;
DROP TABLE IF EXISTS t1;
CREATE TABLE t1(col1 TINYINT, col2 TINYINT);
INSERT INTO t1 VALUES(1, 2), (11, 12);
CREATE PROCEDURE p1(arg TINYINT)
BEGIN
SELECT arg;
END|
CALL p1((1, 2));
ERROR 21000: Operand should contain 1 column(s)
CALL p1((SELECT * FROM t1 LIMIT 1));
ERROR 21000: Operand should contain 1 column(s)
CALL p1((SELECT col1, col2 FROM t1 LIMIT 1));
ERROR 21000: Operand should contain 1 column(s)
DROP PROCEDURE p1;
DROP TABLE t1;

---------------------------------------------------------------
BUG#13613
---------------------------------------------------------------

DROP PROCEDURE IF EXISTS p1;
DROP FUNCTION IF EXISTS f1;
CREATE PROCEDURE p1(x VARCHAR(50))
BEGIN
SET x = SUBSTRING(x, 1, 3);
SELECT x;
END|
CREATE FUNCTION f1(x VARCHAR(50)) RETURNS VARCHAR(50)
BEGIN
RETURN SUBSTRING(x, 1, 3);
END|
CALL p1('abcdef');
x
abc
SELECT f1('ABCDEF');
f1('ABCDEF')
ABC
DROP PROCEDURE p1;
DROP FUNCTION f1;

---------------------------------------------------------------
BUG#13665
---------------------------------------------------------------

DROP FUNCTION IF EXISTS f1;
CREATE FUNCTION f1() RETURNS VARCHAR(20000)
BEGIN
DECLARE var VARCHAR(2000);
SET var = '';
SET var = CONCAT(var, 'abc');
SET var = CONCAT(var, '');
RETURN var;
END|
SELECT f1();
f1()
abc
DROP FUNCTION f1;
DROP PROCEDURE IF EXISTS p1;
CREATE PROCEDURE p1()
BEGIN
DECLARE v_char VARCHAR(255);
DECLARE v_text TEXT DEFAULT '';
SET v_char = 'abc';
SET v_text = v_char;
SET v_char = 'def';
SET v_text = concat(v_text, '|', v_char);
SELECT v_text;
END|
CALL p1();
v_text
abc|def
DROP PROCEDURE p1;
DROP PROCEDURE IF EXISTS bug27415_text_test|
DROP PROCEDURE IF EXISTS bug27415_text_test2|
CREATE PROCEDURE bug27415_text_test(entity_id_str_in text)
BEGIN
DECLARE str_remainder text;
SET str_remainder = entity_id_str_in;
select 'before substr', str_remainder;
SET str_remainder = SUBSTRING(str_remainder, 3);
select 'after substr', str_remainder;
END|
CREATE PROCEDURE bug27415_text_test2(entity_id_str_in text)
BEGIN
DECLARE str_remainder text;
DECLARE str_remainder2 text;
SET str_remainder2 = entity_id_str_in;
select 'before substr', str_remainder2;
SET str_remainder = SUBSTRING(str_remainder2, 3);
select 'after substr', str_remainder;
END|
CALL bug27415_text_test('a,b,c')|
before substr	str_remainder
before substr	a,b,c
after substr	str_remainder
after substr	b,c
CALL bug27415_text_test('a,b,c')|
before substr	str_remainder
before substr	a,b,c
after substr	str_remainder
after substr	b,c
CALL bug27415_text_test2('a,b,c')|
before substr	str_remainder2
before substr	a,b,c
after substr	str_remainder
after substr	b,c
CALL bug27415_text_test('a,b,c')|
before substr	str_remainder
before substr	a,b,c
after substr	str_remainder
after substr	b,c
DROP PROCEDURE bug27415_text_test|
DROP PROCEDURE bug27415_text_test2|
drop function if exists f1;
drop table if exists t1;
create function f1() returns int 
begin
if @a=1 then set @b='abc';
else set @b=1;
end if;
set @a=1;
return 0;
end|
create table t1 (a int)|
insert into t1 (a) values (1), (2)|
set @b=1|
set @a=0|
select f1(), @b from t1|
f1()	@b
0	1
0	0
set @b:='test'|
set @a=0|
select f1(), @b from t1|
f1()	@b
0	1
0	abc
drop function f1;
drop table t1;

---------------------------------------------------------------
BUG#28299
---------------------------------------------------------------

CREATE PROCEDURE ctest()
BEGIN
DECLARE i CHAR(16);
DECLARE j INT;
SET i= 'string';
SET j= 1 + i;
END|
CALL ctest();
Warnings:
Warning	1292	Truncated incorrect DOUBLE value: 'string          '
DROP PROCEDURE ctest;
CREATE PROCEDURE vctest()
BEGIN
DECLARE i VARCHAR(16);
DECLARE j INT;
SET i= 'string';
SET j= 1 + i;
END|
CALL vctest();
Warnings:
Warning	1292	Truncated incorrect DOUBLE value: 'string'
DROP PROCEDURE vctest;
#
# Start of 10.3 tests
#
#
# MDEV-12876 Wrong data type for CREATE..SELECT sp_var
#
CREATE PROCEDURE p1()
BEGIN
DECLARE i8  TINYINT;
DECLARE i16 SMALLINT;
DECLARE i32 INT;
DECLARE i64 BIGINT;
DECLARE f   FLOAT;
DECLARE d   DOUBLE;
DECLARE b8  BIT(8);
DECLARE y   YEAR;
DECLARE t1  TINYTEXT;
DECLARE t2  TEXT;
DECLARE t3  MEDIUMTEXT;
DECLARE t4  LONGTEXT;
CREATE TABLE t1 AS SELECT i8, i16, i32, i64, f, d, b8, y, t1, t2, t3, t4;
END;
$$
CALL p1;
DESCRIBE t1;
Field	Type	Null	Key	Default	Extra
i8	tinyint(4)	YES		NULL	
i16	smallint(6)	YES		NULL	
i32	int(11)	YES		NULL	
i64	bigint(20)	YES		NULL	
f	float	YES		NULL	
d	double	YES		NULL	
b8	bit(8)	YES		NULL	
y	year(4)	YES		NULL	
t1	tinytext	YES		NULL	
t2	text	YES		NULL	
t3	mediumtext	YES		NULL	
t4	longtext	YES		NULL	
DROP TABLE t1;
DROP PROCEDURE p1;
#
# MDEV-12917 Wrong data type for CREATE..SELECT year_sp_variable
#
CREATE PROCEDURE p1()
BEGIN
DECLARE a YEAR;
CREATE OR REPLACE TABLE t1 AS SELECT a;
SHOW CREATE TABLE t1;
DROP TABLE t1;
END;
$$
CALL p1;
Table	Create Table
t1	CREATE TABLE "t1" (
  "a" year(4) DEFAULT NULL
)
DROP PROCEDURE p1;
#
# MDEV-15960 Wrong data type on CREATE..SELECT char_or_enum_or_text_spvar
#
BEGIN NOT ATOMIC
DECLARE var TINYTEXT CHARACTER SET utf8;
CREATE TABLE t1 AS SELECT var;
END;
$$
SHOW CREATE TABLE t1;
Table	Create Table
t1	CREATE TABLE "t1" (
  "var" tinytext CHARACTER SET utf8mb3 DEFAULT NULL
)
DROP TABLE t1;
BEGIN NOT ATOMIC
DECLARE var TEXT CHARACTER SET utf8;
CREATE TABLE t1 AS SELECT var;
END;
$$
SHOW CREATE TABLE t1;
Table	Create Table
t1	CREATE TABLE "t1" (
  "var" text CHARACTER SET utf8mb3 DEFAULT NULL
)
DROP TABLE t1;
BEGIN NOT ATOMIC
DECLARE var MEDIUMTEXT CHARACTER SET utf8;
CREATE TABLE t1 AS SELECT var;
END;
$$
SHOW CREATE TABLE t1;
Table	Create Table
t1	CREATE TABLE "t1" (
  "var" mediumtext CHARACTER SET utf8mb3 DEFAULT NULL
)
DROP TABLE t1;
BEGIN NOT ATOMIC
DECLARE var LONGTEXT CHARACTER SET utf8;
CREATE TABLE t1 AS SELECT var;
END;
$$
SHOW CREATE TABLE t1;
Table	Create Table
t1	CREATE TABLE "t1" (
  "var" longtext CHARACTER SET utf8mb3 DEFAULT NULL
)
DROP TABLE t1;
BEGIN NOT ATOMIC
DECLARE var CHAR(1);
CREATE TABLE t1 AS SELECT var;
END;
$$
SHOW CREATE TABLE t1;
Table	Create Table
t1	CREATE TABLE "t1" (
  "var" char(1) DEFAULT NULL
)
DROP TABLE t1;
BEGIN NOT ATOMIC
DECLARE var ENUM('a');
CREATE TABLE t1 AS SELECT var;
END;
$$
SHOW CREATE TABLE t1;
Table	Create Table
t1	CREATE TABLE "t1" (
  "var" char(1) DEFAULT NULL
)
DROP TABLE t1;
#
# MDEV-14347 CREATE PROCEDURE returns no error when using an unknown variable
#
#
# Simple cases (without subqueries) - the most typical problem:
# a typo in an SP variable name
#
CREATE PROCEDURE p1(a INT)
BEGIN
DECLARE res INT DEFAULT 0;
IF (a < 0) THEN
SET res= a_long_variable_name_with_a_typo;
END IF;
END;
$$
ERROR 42000: Undeclared variable: a_long_variable_name_with_a_typo
CREATE PROCEDURE p1(a INT)
BEGIN
DECLARE res INT DEFAULT 0;
IF (a < 0) THEN
SET res= 1 + a_long_variable_name_with_a_typo;
END IF;
END;
$$
ERROR 42000: Undeclared variable: a_long_variable_name_with_a_typo
#
# Complex cases with subqueries
#
#
# Maybe a table field identifier (there are some tables) - no error
#
CREATE PROCEDURE p1()
BEGIN
DECLARE res INT DEFAULT 0;
SET res=(SELECT * FROM t1 LEFT OUTER JOIN t2 USING (c1));
END;
$$
DROP PROCEDURE p1;
CREATE PROCEDURE p1()
BEGIN
DECLARE res INT DEFAULT 0;
SET res=(SELECT * FROM t1 LEFT OUTER JOIN t2 ON (c1=c2));
END;
$$
DROP PROCEDURE p1;
#
# One unknown identifier, no tables
#
CREATE PROCEDURE p1()
BEGIN
DECLARE a INT;
SET a=unknown_ident;
END;
$$
ERROR 42000: Undeclared variable: unknown_ident
CREATE PROCEDURE p1()
BEGIN
DECLARE a INT;
SET a=unknown_ident1.unknown_ident2;
END;
$$
ERROR 42000: Undeclared variable: unknown_ident1
CREATE PROCEDURE p1()
BEGIN
DECLARE a INT;
SET a=unknown_ident1.unknown_ident2.unknown_ident3;
END;
$$
ERROR 42000: Undeclared variable: unknown_ident1
CREATE PROCEDURE p1()
BEGIN
DECLARE a INT;
SET a=(SELECT unknown_ident);
END;
$$
ERROR 42000: Undeclared variable: unknown_ident
CREATE PROCEDURE p1()
BEGIN
DECLARE a INT;
SET a=(SELECT unknown_ident FROM dual);
END;
$$
ERROR 42000: Undeclared variable: unknown_ident
CREATE PROCEDURE p1()
BEGIN
DECLARE a INT;
SET a=(SELECT (SELECT unknown_ident));
END;
$$
ERROR 42000: Undeclared variable: unknown_ident
CREATE PROCEDURE p1()
BEGIN
DECLARE a INT;
SET a=(SELECT (SELECT unknown_ident FROM dual));
END;
$$
ERROR 42000: Undeclared variable: unknown_ident
CREATE PROCEDURE p1()
BEGIN
DECLARE a INT;
SET a=(SELECT 1 WHERE unknown_ident);
END;
$$
ERROR 42000: Undeclared variable: unknown_ident
CREATE PROCEDURE p1()
BEGIN
DECLARE a INT;
SET a=(SELECT 1 WHERE unknown_ident=1);
END;
$$
ERROR 42000: Undeclared variable: unknown_ident
CREATE PROCEDURE p1()
BEGIN
DECLARE a INT;
SET a=(SELECT 1 LIMIT unknown_ident);
END;
$$
ERROR 42000: Undeclared variable: unknown_ident
#
# GROUP, HAVING, ORDER are not tested yet for unknown identifiers
#
CREATE PROCEDURE p1()
BEGIN
DECLARE a INT;
SET a=(SELECT 1 GROUP BY unknown_ident);
END;
$$
DROP PROCEDURE p1;
CREATE PROCEDURE p1()
BEGIN
DECLARE res INT DEFAULT 0;
SET res=(SELECT 1 HAVING unknown_ident);
END;
$$
DROP PROCEDURE p1;
CREATE PROCEDURE p1()
BEGIN
DECLARE a INT;
SET a=(SELECT 1 ORDER BY unknown_ident);
END;
$$
DROP PROCEDURE p1;
#
# HAVING + aggregate_function(unknown_identifier) is a special case
#
CREATE PROCEDURE p1()
BEGIN
DECLARE res INT DEFAULT 0;
SET res=(SELECT 1 HAVING SUM(unknown_ident));
END;
$$
ERROR 42000: Undeclared variable: unknown_ident
#
# Known indentifier + unknown identifier, no tables
#
CREATE PROCEDURE p1()
BEGIN
DECLARE a INT;
SET a=a+unknown_ident;
END;
$$
ERROR 42000: Undeclared variable: unknown_ident
CREATE PROCEDURE p1()
BEGIN
DECLARE a INT;
SET a=a+(SELECT unknown_ident);
END;
$$
ERROR 42000: Undeclared variable: unknown_ident
CREATE PROCEDURE p1()
BEGIN
DECLARE a INT;
SET a=a+(SELECT unknown_ident FROM dual);
END;
$$
ERROR 42000: Undeclared variable: unknown_ident
CREATE PROCEDURE p1()
BEGIN
DECLARE a INT;
SET a=(SELECT (a+(SELECT unknown_ident)));
END;
$$
ERROR 42000: Undeclared variable: unknown_ident
CREATE PROCEDURE p1()
BEGIN
DECLARE a INT;
SET a=(SELECT (a+(SELECT unknown_ident FROM dual)));
END;
$$
ERROR 42000: Undeclared variable: unknown_ident
#
# Unknown indentifier + known identifier, no tables
#
CREATE PROCEDURE p1()
BEGIN
DECLARE a INT;
SET a=unknown_ident+a;
END;
$$
ERROR 42000: Undeclared variable: unknown_ident
CREATE PROCEDURE p1()
BEGIN
DECLARE a INT;
SET a=(SELECT unknown_ident)+a;
END;
$$
ERROR 42000: Undeclared variable: unknown_ident
CREATE PROCEDURE p1()
BEGIN
DECLARE a INT;
SET a=(SELECT unknown_ident FROM dual)+a;
END;
$$
ERROR 42000: Undeclared variable: unknown_ident
CREATE PROCEDURE p1()
BEGIN
DECLARE a INT;
SET a=(SELECT (SELECT unknown_ident)+a);
END;
$$
ERROR 42000: Undeclared variable: unknown_ident
CREATE PROCEDURE p1()
BEGIN
DECLARE a INT;
SET a=(SELECT (SELECT unknown_ident FROM dual)+a);
END;
$$
ERROR 42000: Undeclared variable: unknown_ident
#
# Maybe a table field indentifier + unknown identifier
#
CREATE PROCEDURE p1()
BEGIN
DECLARE a INT;
SET a=(SELECT c1 FROM t1)+unknown_ident;
END;
$$
ERROR 42000: Undeclared variable: unknown_ident
CREATE PROCEDURE p1()
BEGIN
DECLARE a INT;
SET a=(SELECT c1 FROM t1)+(SELECT unknown_ident);
END;
$$
ERROR 42000: Undeclared variable: unknown_ident
CREATE PROCEDURE p1()
BEGIN
DECLARE a INT;
SET a=(SELECT c1 FROM t1)+(SELECT unknown_ident FROM dual);
END;
$$
ERROR 42000: Undeclared variable: unknown_ident
CREATE PROCEDURE p1()
BEGIN
DECLARE a INT;
SET a=(SELECT ((SELECT c1 FROM t1)+(SELECT unknown_ident)));
END;
$$
ERROR 42000: Undeclared variable: unknown_ident
CREATE PROCEDURE p1()
BEGIN
DECLARE a INT;
SET a=(SELECT ((SELECT c1 FROM t1)+(SELECT unknown_ident FROM dual)));
END;
$$
ERROR 42000: Undeclared variable: unknown_ident
#
# Unknown indentifier + maybe a table field identifier
#
CREATE PROCEDURE p1()
BEGIN
DECLARE a INT;
SET a=unknown_ident+(SELECT c1 FROM t1);
END;
$$
ERROR 42000: Undeclared variable: unknown_ident
CREATE PROCEDURE p1()
BEGIN
DECLARE a INT;
SET a=(SELECT unknown_ident)+(SELECT c1 FROM t1);
END;
$$
ERROR 42000: Undeclared variable: unknown_ident
CREATE PROCEDURE p1()
BEGIN
DECLARE a INT;
SET a=(SELECT unknown_ident FROM dual)+(SELECT c1 FROM t1);
END;
$$
ERROR 42000: Undeclared variable: unknown_ident
CREATE PROCEDURE p1()
BEGIN
DECLARE a INT;
SET a=(SELECT (SELECT unknown_ident)+(SELECT c1 FROM t1));
END;
$$
ERROR 42000: Undeclared variable: unknown_ident
CREATE PROCEDURE p1()
BEGIN
DECLARE a INT;
SET a=(SELECT (SELECT unknown_ident FROM dual)+(SELECT c1 FROM t1));
END;
$$
ERROR 42000: Undeclared variable: unknown_ident
#
# Maybe a table field identifier + maybe a field table identifier
#
CREATE PROCEDURE p1()
BEGIN
DECLARE a INT;
-- c2 does not have a table on its level
-- but it can be a field of a table on the uppder level, i.e. t1
SET a=(SELECT c1+(SELECT c2) FROM t1);
END;
$$
DROP PROCEDURE p1;
#
# TVC - unknown identifier
#
CREATE PROCEDURE p1(a INT)
BEGIN
DECLARE res INT DEFAULT 0;
SET res=(VALUES(unknown_ident));
END;
$$
ERROR 42000: Undeclared variable: unknown_ident
CREATE PROCEDURE p1(a INT)
BEGIN
DECLARE res INT DEFAULT 0;
SET res=(VALUES(1),(unknown_ident));
END;
$$
ERROR 42000: Undeclared variable: unknown_ident
CREATE PROCEDURE p1(a INT)
BEGIN
DECLARE res INT DEFAULT 0;
SET res=(VALUES((SELECT unknown_ident)));
END;
$$
ERROR 42000: Undeclared variable: unknown_ident
CREATE PROCEDURE p1(a INT)
BEGIN
DECLARE res INT DEFAULT 0;
SET res=(VALUES(1),((SELECT unknown_ident)));
END;
$$
ERROR 42000: Undeclared variable: unknown_ident
CREATE PROCEDURE p1(a INT)
BEGIN
DECLARE res INT DEFAULT 0;
SET res=(VALUES(1) LIMIT unknown_ident);
END;
$$
ERROR 42000: Undeclared variable: unknown_ident
#
# TVC - ORDER BY - not tested yet for unknown identifiers
#
CREATE PROCEDURE p1(a INT)
BEGIN
DECLARE res INT DEFAULT 0;
SET res=(VALUES(1) ORDER BY unknown_ident);
END;
$$
DROP PROCEDURE p1;
#
# TVC - maybe a table field identifier - no error
#
CREATE PROCEDURE p1(a INT)
BEGIN
DECLARE res INT DEFAULT 0;
SET res=(VALUES((SELECT c1 FROM t1)));
END;
$$
DROP PROCEDURE p1;
CREATE PROCEDURE p1(a INT)
BEGIN
DECLARE res INT DEFAULT 0;
SET res=(VALUES(1),((SELECT c1 FROM t1)));
END;
$$
DROP PROCEDURE p1;
#
# Functions DEFAULT(x) and VALUE(x)
#
CREATE PROCEDURE p1()
BEGIN
DECLARE res INT DEFAULT 0;
SET res=DEFAULT(unknown_ident);
SELECT res;
END;
$$
ERROR 42000: Undeclared variable: unknown_ident
CREATE PROCEDURE p1()
BEGIN
DECLARE res INT DEFAULT 0;
SET res=VALUE(unknown_ident);
SELECT res;
END;
$$
ERROR 42000: Undeclared variable: unknown_ident
#
# End of MDEV-14347 CREATE PROCEDURE returns no error when using an unknown variable
#