1use test; 2drop table if exists t1,t2,t3,t4; 3drop view if exists v1; 4drop procedure if exists p1; 5drop procedure if exists p2; 6drop function if exists f1; 7drop function if exists f2; 8create table t1 ( 9id char(16) not null default '', 10data int not null 11); 12create table t2 ( 13s char(16), 14i int, 15d double 16); 17drop procedure if exists foo42; 18create procedure foo42() 19insert into test.t1 values ("foo", 42); 20call foo42(); 21select * from t1; 22id data 23foo 42 24delete from t1; 25drop procedure foo42; 26drop procedure if exists bar; 27create procedure bar(x char(16), y int) 28insert into test.t1 values (x, y); 29call bar("bar", 666); 30select * from t1; 31id data 32bar 666 33delete from t1; 34drop procedure if exists empty| 35create procedure empty() 36begin 37end| 38call empty()| 39drop procedure empty| 40drop procedure if exists scope| 41create procedure scope(a int, b float) 42begin 43declare b int; 44declare c float; 45begin 46declare c int; 47end; 48end| 49drop procedure scope| 50drop procedure if exists two| 51create procedure two(x1 char(16), x2 char(16), y int) 52begin 53insert into test.t1 values (x1, y); 54insert into test.t1 values (x2, y); 55end| 56call two("one", "two", 3)| 57select * from t1| 58id data 59one 3 60two 3 61delete from t1| 62drop procedure two| 63drop procedure if exists locset| 64create procedure locset(x char(16), y int) 65begin 66declare z1, z2 int; 67set z1 = y; 68set z2 = z1+2; 69insert into test.t1 values (x, z2); 70end| 71call locset("locset", 19)| 72select * from t1| 73id data 74locset 21 75delete from t1| 76drop procedure locset| 77drop procedure if exists setcontext| 78create procedure setcontext() 79begin 80declare data int default 2; 81insert into t1 (id, data) values ("foo", 1); 82replace t1 set data = data, id = "bar"; 83update t1 set id = "kaka", data = 3 where t1.data = data; 84end| 85call setcontext()| 86select * from t1 order by data| 87id data 88foo 1 89kaka 3 90delete from t1| 91drop procedure setcontext| 92create table t3 ( d date, i int, f double, s varchar(32) )| 93drop procedure if exists nullset| 94create procedure nullset() 95begin 96declare ld date; 97declare li int; 98declare lf double; 99declare ls varchar(32); 100set ld = null, li = null, lf = null, ls = null; 101insert into t3 values (ld, li, lf, ls); 102insert into t3 (i, f, s) values ((ld is null), 1, "ld is null"), 103((li is null), 1, "li is null"), 104((li = 0), null, "li = 0"), 105((lf is null), 1, "lf is null"), 106((lf = 0), null, "lf = 0"), 107((ls is null), 1, "ls is null"); 108end| 109call nullset()| 110select * from t3| 111d i f s 112NULL NULL NULL NULL 113NULL 1 1 ld is null 114NULL 1 1 li is null 115NULL NULL NULL li = 0 116NULL 1 1 lf is null 117NULL NULL NULL lf = 0 118NULL 1 1 ls is null 119drop table t3| 120drop procedure nullset| 121drop procedure if exists mixset| 122create procedure mixset(x char(16), y int) 123begin 124declare z int; 125set @z = y, z = 666, max_join_size = 100; 126insert into test.t1 values (x, z); 127end| 128call mixset("mixset", 19)| 129show variables like 'max_join_size'| 130Variable_name Value 131max_join_size 100 132select id,data,@z from t1| 133id data @z 134mixset 666 19 135delete from t1| 136drop procedure mixset| 137drop procedure if exists zip| 138create procedure zip(x char(16), y int) 139begin 140declare z int; 141call zap(y, z); 142call bar(x, z); 143end| 144drop procedure if exists zap| 145create procedure zap(x int, out y int) 146begin 147declare z int; 148set z = x+1, y = z; 149end| 150call zip("zip", 99)| 151select * from t1| 152id data 153zip 100 154delete from t1| 155drop procedure zip| 156drop procedure bar| 157call zap(7, @zap)| 158select @zap| 159@zap 1608 161drop procedure zap| 162drop procedure if exists c1| 163create procedure c1(x int) 164call c2("c", x)| 165drop procedure if exists c2| 166create procedure c2(s char(16), x int) 167call c3(x, s)| 168drop procedure if exists c3| 169create procedure c3(x int, s char(16)) 170call c4("level", x, s)| 171drop procedure if exists c4| 172create procedure c4(l char(8), x int, s char(16)) 173insert into t1 values (concat(l,s), x)| 174call c1(42)| 175select * from t1| 176id data 177levelc 42 178delete from t1| 179drop procedure c1| 180drop procedure c2| 181drop procedure c3| 182drop procedure c4| 183drop procedure if exists iotest| 184create procedure iotest(x1 char(16), x2 char(16), y int) 185begin 186call inc2(x2, y); 187insert into test.t1 values (x1, y); 188end| 189drop procedure if exists inc2| 190create procedure inc2(x char(16), y int) 191begin 192call inc(y); 193insert into test.t1 values (x, y); 194end| 195drop procedure if exists inc| 196create procedure inc(inout io int) 197set io = io + 1| 198call iotest("io1", "io2", 1)| 199select * from t1 order by data desc| 200id data 201io2 2 202io1 1 203delete from t1| 204drop procedure iotest| 205drop procedure inc2| 206drop procedure if exists incr| 207create procedure incr(inout x int) 208call inc(x)| 209select @zap| 210@zap 2118 212call incr(@zap)| 213select @zap| 214@zap 2159 216drop procedure inc| 217drop procedure incr| 218drop procedure if exists cbv1| 219create procedure cbv1() 220begin 221declare y int default 3; 222call cbv2(y+1, y); 223insert into test.t1 values ("cbv1", y); 224end| 225drop procedure if exists cbv2| 226create procedure cbv2(y1 int, inout y2 int) 227begin 228set y2 = 4711; 229insert into test.t1 values ("cbv2", y1); 230end| 231call cbv1()| 232select * from t1 order by data| 233id data 234cbv2 4 235cbv1 4711 236delete from t1| 237drop procedure cbv1| 238drop procedure cbv2| 239insert into t2 values ("a", 1, 1.1), ("b", 2, 1.2), ("c", 3, 1.3)| 240drop procedure if exists sub1| 241create procedure sub1(id char(16), x int) 242insert into test.t1 values (id, x)| 243drop procedure if exists sub2| 244create procedure sub2(id char(16)) 245begin 246declare x int; 247set x = (select sum(t.i) from test.t2 t); 248insert into test.t1 values (id, x); 249end| 250drop procedure if exists sub3| 251create function sub3(i int) returns int deterministic 252return i+1| 253call sub1("sub1a", (select 7))| 254call sub1("sub1b", (select max(i) from t2))| 255call sub1("sub1c", (select i,d from t2 limit 1))| 256ERROR 21000: Operand should contain 1 column(s) 257call sub1("sub1d", (select 1 from (select 1) a))| 258call sub2("sub2")| 259select * from t1 order by id| 260id data 261sub1a 7 262sub1b 3 263sub1d 1 264sub2 6 265select sub3((select max(i) from t2))| 266sub3((select max(i) from t2)) 2674 268drop procedure sub1| 269drop procedure sub2| 270drop function sub3| 271delete from t1| 272delete from t2| 273drop procedure if exists a0| 274create procedure a0(x int) 275while x do 276set x = x-1; 277insert into test.t1 values ("a0", x); 278end while| 279call a0(3)| 280select * from t1 order by data desc| 281id data 282a0 2 283a0 1 284a0 0 285delete from t1| 286drop procedure a0| 287drop procedure if exists a| 288create procedure a(x int) 289while x > 0 do 290set x = x-1; 291insert into test.t1 values ("a", x); 292end while| 293call a(3)| 294select * from t1 order by data desc| 295id data 296a 2 297a 1 298a 0 299delete from t1| 300drop procedure a| 301drop procedure if exists b| 302create procedure b(x int) 303repeat 304insert into test.t1 values (repeat("b",3), x); 305set x = x-1; 306until x = 0 end repeat| 307call b(3)| 308select * from t1 order by data desc| 309id data 310bbb 3 311bbb 2 312bbb 1 313delete from t1| 314drop procedure b| 315drop procedure if exists b2| 316create procedure b2(x int) 317repeat(select 1 into outfile 'b2'); 318insert into test.t1 values (repeat("b2",3), x); 319set x = x-1; 320until x = 0 end repeat| 321drop procedure b2| 322drop procedure if exists c| 323create procedure c(x int) 324hmm: while x > 0 do 325insert into test.t1 values ("c", x); 326set x = x-1; 327iterate hmm; 328insert into test.t1 values ("x", x); 329end while hmm| 330call c(3)| 331select * from t1 order by data desc| 332id data 333c 3 334c 2 335c 1 336delete from t1| 337drop procedure c| 338drop procedure if exists d| 339create procedure d(x int) 340hmm: while x > 0 do 341insert into test.t1 values ("d", x); 342set x = x-1; 343leave hmm; 344insert into test.t1 values ("x", x); 345end while| 346call d(3)| 347select * from t1| 348id data 349d 3 350delete from t1| 351drop procedure d| 352drop procedure if exists e| 353create procedure e(x int) 354foo: loop 355if x = 0 then 356leave foo; 357end if; 358insert into test.t1 values ("e", x); 359set x = x-1; 360end loop foo| 361call e(3)| 362select * from t1 order by data desc| 363id data 364e 3 365e 2 366e 1 367delete from t1| 368drop procedure e| 369drop procedure if exists f| 370create procedure f(x int) 371if x < 0 then 372insert into test.t1 values ("f", 0); 373elseif x = 0 then 374insert into test.t1 values ("f", 1); 375else 376insert into test.t1 values ("f", 2); 377end if| 378call f(-2)| 379call f(0)| 380call f(4)| 381select * from t1 order by data| 382id data 383f 0 384f 1 385f 2 386delete from t1| 387drop procedure f| 388drop procedure if exists g| 389create procedure g(x int) 390case 391when x < 0 then 392insert into test.t1 values ("g", 0); 393when x = 0 then 394insert into test.t1 values ("g", 1); 395else 396insert into test.t1 values ("g", 2); 397end case| 398call g(-42)| 399call g(0)| 400call g(1)| 401select * from t1 order by data| 402id data 403g 0 404g 1 405g 2 406delete from t1| 407drop procedure g| 408drop procedure if exists h| 409create procedure h(x int) 410case x 411when 0 then 412insert into test.t1 values ("h0", x); 413when 1 then 414insert into test.t1 values ("h1", x); 415else 416insert into test.t1 values ("h?", x); 417end case| 418call h(0)| 419call h(1)| 420call h(17)| 421select * from t1 order by data| 422id data 423h0 0 424h1 1 425h? 17 426delete from t1| 427drop procedure h| 428drop procedure if exists i| 429create procedure i(x int) 430foo: 431begin 432if x = 0 then 433leave foo; 434end if; 435insert into test.t1 values ("i", x); 436end foo| 437call i(0)| 438call i(3)| 439select * from t1| 440id data 441i 3 442delete from t1| 443drop procedure i| 444insert into t1 values ("foo", 3), ("bar", 19)| 445insert into t2 values ("x", 9, 4.1), ("y", -1, 19.2), ("z", 3, 2.2)| 446drop procedure if exists sel1| 447create procedure sel1() 448begin 449select * from t1 order by data; 450end| 451call sel1()| 452id data 453foo 3 454bar 19 455drop procedure sel1| 456drop procedure if exists sel2| 457create procedure sel2() 458begin 459select * from t1 order by data; 460select * from t2 order by s; 461end| 462call sel2()| 463id data 464foo 3 465bar 19 466s i d 467x 9 4.1 468y -1 19.2 469z 3 2.2 470drop procedure sel2| 471delete from t1| 472delete from t2| 473drop procedure if exists into_test| 474create procedure into_test(x char(16), y int) 475begin 476insert into test.t1 values (x, y); 477select id,data into x,y from test.t1 limit 1; 478insert into test.t1 values (concat(x, "2"), y+2); 479end| 480call into_test("into", 100)| 481select * from t1 order by data| 482id data 483into 100 484into2 102 485delete from t1| 486drop procedure into_test| 487drop procedure if exists into_tes2| 488create procedure into_test2(x char(16), y int) 489begin 490insert into test.t1 values (x, y); 491select id,data into x,@z from test.t1 limit 1; 492insert into test.t1 values (concat(x, "2"), y+2); 493end| 494call into_test2("into", 100)| 495select id,data,@z from t1 order by data| 496id data @z 497into 100 100 498into2 102 100 499delete from t1| 500drop procedure into_test2| 501drop procedure if exists into_test3| 502create procedure into_test3() 503begin 504declare x char(16); 505declare y int; 506select * into x,y from test.t1 limit 1; 507insert into test.t2 values (x, y, 0.0); 508end| 509insert into t1 values ("into3", 19)| 510call into_test3()| 511call into_test3()| 512select * from t2| 513s i d 514into3 19 0 515into3 19 0 516delete from t1| 517delete from t2| 518drop procedure into_test3| 519drop procedure if exists into_test4| 520create procedure into_test4() 521begin 522declare x int; 523select data into x from test.t1 limit 1; 524insert into test.t3 values ("into4", x); 525end| 526delete from t1| 527create table t3 ( s char(16), d int)| 528call into_test4()| 529select * from t3| 530s d 531into4 NULL 532insert into t1 values ("i4", 77)| 533call into_test4()| 534select * from t3| 535s d 536into4 NULL 537into4 77 538delete from t1| 539drop table t3| 540drop procedure into_test4| 541drop procedure if exists into_outfile| 542create procedure into_outfile(x char(16), y int) 543begin 544insert into test.t1 values (x, y); 545select * into outfile "MYSQLTEST_VARDIR/tmp/spout" from test.t1; 546insert into test.t1 values (concat(x, "2"), y+2); 547end| 548call into_outfile("ofile", 1)| 549delete from t1| 550drop procedure into_outfile| 551drop procedure if exists into_dumpfile| 552create procedure into_dumpfile(x char(16), y int) 553begin 554insert into test.t1 values (x, y); 555select * into dumpfile "MYSQLTEST_VARDIR/tmp/spdump" from test.t1 limit 1; 556insert into test.t1 values (concat(x, "2"), y+2); 557end| 558call into_dumpfile("dfile", 1)| 559delete from t1| 560drop procedure into_dumpfile| 561drop procedure if exists create_select| 562create procedure create_select(x char(16), y int) 563begin 564insert into test.t1 values (x, y); 565create temporary table test.t3 select * from test.t1; 566insert into test.t3 values (concat(x, "2"), y+2); 567end| 568call create_select("cs", 90)| 569select * from t1, t3| 570id data id data 571cs 90 cs 90 572cs 90 cs2 92 573drop table t3| 574delete from t1| 575drop procedure create_select| 576drop function if exists e| 577create function e() returns double 578return 2.7182818284590452354| 579set @e = e()| 580select e(), @e| 581e() @e 5822.718281828459045 2.718281828459045 583drop function if exists inc| 584create function inc(i int) returns int 585return i+1| 586select inc(1), inc(99), inc(-71)| 587inc(1) inc(99) inc(-71) 5882 100 -70 589drop function if exists mul| 590create function mul(x int, y int) returns int 591return x*y| 592select mul(1,1), mul(3,5), mul(4711, 666)| 593mul(1,1) mul(3,5) mul(4711, 666) 5941 15 3137526 595drop function if exists append| 596create function append(s1 char(8), s2 char(8)) returns char(16) 597return concat(s1, s2)| 598select append("foo", "bar")| 599append("foo", "bar") 600foobar 601drop function if exists fac| 602create function fac(n int unsigned) returns bigint unsigned 603begin 604declare f bigint unsigned default 1; 605while n > 1 do 606set f = f * n; 607set n = n - 1; 608end while; 609return f; 610end| 611select fac(1), fac(2), fac(5), fac(10)| 612fac(1) fac(2) fac(5) fac(10) 6131 2 120 3628800 614drop function if exists fun| 615create function fun(d double, i int, u int unsigned) returns double 616return mul(inc(i), fac(u)) / e()| 617select fun(2.3, 3, 5)| 618fun(2.3, 3, 5) 619176.58213176229233 620insert into t2 values (append("xxx", "yyy"), mul(4,3), e())| 621insert into t2 values (append("a", "b"), mul(2,mul(3,4)), fun(1.7, 4, 6))| 622select * from t2 where s = append("a", "b")| 623s i d 624ab 24 1324.3659882171924 625select * from t2 where i = mul(4,3) or i = mul(mul(3,4),2) order by i| 626s i d 627xxxyyy 12 2.718281828459045 628ab 24 1324.3659882171924 629select * from t2 where d = e()| 630s i d 631xxxyyy 12 2.718281828459045 632select * from t2 order by i| 633s i d 634xxxyyy 12 2.718281828459045 635ab 24 1324.3659882171924 636delete from t2| 637drop function e| 638drop function inc| 639drop function mul| 640drop function append| 641drop function fun| 642drop procedure if exists hndlr1| 643create procedure hndlr1(val int) 644begin 645declare x int default 0; 646declare foo condition for 1136; 647declare bar condition for sqlstate '42S98'; # Just for testing syntax 648declare zip condition for sqlstate value '42S99'; # Just for testing syntax 649declare continue handler for foo set x = 1; 650insert into test.t1 values ("hndlr1", val, 2); # Too many values 651if (x) then 652insert into test.t1 values ("hndlr1", val); # This instead then 653end if; 654end| 655call hndlr1(42)| 656select * from t1| 657id data 658hndlr1 42 659delete from t1| 660drop procedure hndlr1| 661drop procedure if exists hndlr2| 662create procedure hndlr2(val int) 663begin 664declare x int default 0; 665begin 666declare exit handler for sqlstate '21S01' set x = 1; 667insert into test.t1 values ("hndlr2", val, 2); # Too many values 668end; 669insert into test.t1 values ("hndlr2", x); 670end| 671call hndlr2(42)| 672select * from t1| 673id data 674hndlr2 1 675delete from t1| 676drop procedure hndlr2| 677drop procedure if exists hndlr3| 678create procedure hndlr3(val int) 679begin 680declare x int default 0; 681declare continue handler for sqlexception # Any error 682begin 683declare z int; 684set z = 2 * val; 685set x = 1; 686end; 687if val < 10 then 688begin 689declare y int; 690set y = val + 10; 691insert into test.t1 values ("hndlr3", y, 2); # Too many values 692if x then 693insert into test.t1 values ("hndlr3", y); 694end if; 695end; 696end if; 697end| 698call hndlr3(3)| 699select * from t1| 700id data 701hndlr3 13 702delete from t1| 703drop procedure hndlr3| 704create table t3 ( id char(16), data int )| 705drop procedure if exists hndlr4| 706create procedure hndlr4() 707begin 708declare x int default 0; 709declare val int; # No default 710declare continue handler for sqlstate '02000' set x=1; 711select data into val from test.t3 where id='z' limit 1; # No hits 712insert into test.t3 values ('z', val); 713end| 714call hndlr4()| 715select * from t3| 716id data 717z NULL 718drop table t3| 719drop procedure hndlr4| 720drop procedure if exists cur1| 721create procedure cur1() 722begin 723declare a char(16); 724declare b int; 725declare c double; 726declare done int default 0; 727declare c cursor for select * from test.t2; 728declare continue handler for sqlstate '02000' set done = 1; 729open c; 730repeat 731fetch c into a, b, c; 732if not done then 733insert into test.t1 values (a, b+c); 734end if; 735until done end repeat; 736close c; 737end| 738insert into t2 values ("foo", 42, -1.9), ("bar", 3, 12.1), ("zap", 666, -3.14)| 739call cur1()| 740select * from t1| 741id data 742foo 40 743bar 15 744zap 663 745drop procedure cur1| 746create table t3 ( s char(16), i int )| 747drop procedure if exists cur2| 748create procedure cur2() 749begin 750declare done int default 0; 751declare c1 cursor for select id,data from test.t1 order by id,data; 752declare c2 cursor for select i from test.t2 order by i; 753declare continue handler for sqlstate '02000' set done = 1; 754open c1; 755open c2; 756repeat 757begin 758declare a char(16); 759declare b,c int; 760fetch from c1 into a, b; 761fetch next from c2 into c; 762if not done then 763if b < c then 764insert into test.t3 values (a, b); 765else 766insert into test.t3 values (a, c); 767end if; 768end if; 769end; 770until done end repeat; 771close c1; 772close c2; 773end| 774call cur2()| 775select * from t3 order by i,s| 776s i 777bar 3 778foo 40 779zap 663 780delete from t1| 781delete from t2| 782drop table t3| 783drop procedure cur2| 784drop procedure if exists chistics| 785create procedure chistics() 786language sql 787modifies sql data 788not deterministic 789sql security definer 790comment 'Characteristics procedure test' 791 insert into t1 values ("chistics", 1)| 792show create procedure chistics| 793Procedure sql_mode Create Procedure character_set_client collation_connection Database Collation 794chistics NO_ENGINE_SUBSTITUTION CREATE DEFINER=`root`@`localhost` PROCEDURE `chistics`() 795 MODIFIES SQL DATA 796 COMMENT 'Characteristics procedure test' 797insert into t1 values ("chistics", 1) latin1 latin1_swedish_ci latin1_swedish_ci 798call chistics()| 799select * from t1| 800id data 801chistics 1 802delete from t1| 803alter procedure chistics sql security invoker| 804show create procedure chistics| 805Procedure sql_mode Create Procedure character_set_client collation_connection Database Collation 806chistics NO_ENGINE_SUBSTITUTION CREATE DEFINER=`root`@`localhost` PROCEDURE `chistics`() 807 MODIFIES SQL DATA 808 SQL SECURITY INVOKER 809 COMMENT 'Characteristics procedure test' 810insert into t1 values ("chistics", 1) latin1 latin1_swedish_ci latin1_swedish_ci 811drop procedure chistics| 812drop function if exists chistics| 813create function chistics() returns int 814language sql 815deterministic 816sql security invoker 817comment 'Characteristics procedure test' 818 return 42| 819show create function chistics| 820Function sql_mode Create Function character_set_client collation_connection Database Collation 821chistics NO_ENGINE_SUBSTITUTION CREATE DEFINER=`root`@`localhost` FUNCTION `chistics`() RETURNS int(11) 822 DETERMINISTIC 823 SQL SECURITY INVOKER 824 COMMENT 'Characteristics procedure test' 825return 42 latin1 latin1_swedish_ci latin1_swedish_ci 826select chistics()| 827chistics() 82842 829alter function chistics 830no sql 831comment 'Characteristics function test'| 832show create function chistics| 833Function sql_mode Create Function character_set_client collation_connection Database Collation 834chistics NO_ENGINE_SUBSTITUTION CREATE DEFINER=`root`@`localhost` FUNCTION `chistics`() RETURNS int(11) 835 NO SQL 836 DETERMINISTIC 837 SQL SECURITY INVOKER 838 COMMENT 'Characteristics function test' 839return 42 latin1 latin1_swedish_ci latin1_swedish_ci 840drop function chistics| 841insert into t1 values ("foo", 1), ("bar", 2), ("zip", 3)| 842set @@sql_mode = 'ANSI'| 843drop procedure if exists modes$ 844create procedure modes(out c1 int, out c2 int) 845begin 846declare done int default 0; 847declare x int; 848declare c cursor for select data from t1; 849declare continue handler for sqlstate '02000' set done = 1; 850select 1 || 2 into c1; 851set c2 = 0; 852open c; 853repeat 854fetch c into x; 855if not done then 856set c2 = c2 + 1; 857end if; 858until done end repeat; 859close c; 860end$ 861set @@sql_mode = ''| 862set sql_select_limit = 1| 863call modes(@c1, @c2)| 864set sql_select_limit = default| 865select @c1, @c2| 866@c1 @c2 86712 3 868delete from t1| 869drop procedure modes| 870create database sp_db1| 871drop database sp_db1| 872create database sp_db2| 873use sp_db2| 874create table t3 ( s char(4), t int )| 875insert into t3 values ("abcd", 42), ("dcba", 666)| 876use test| 877drop database sp_db2| 878create database sp_db3| 879use sp_db3| 880drop procedure if exists dummy| 881create procedure dummy(out x int) 882set x = 42| 883use test| 884drop database sp_db3| 885select type,db,name from mysql.proc where db = 'sp_db3'| 886type db name 887drop procedure if exists rc| 888create procedure rc() 889begin 890delete from t1; 891insert into t1 values ("a", 1), ("b", 2), ("c", 3); 892end| 893call rc()| 894select row_count()| 895row_count() 8963 897update t1 set data=42 where id = "b"; 898select row_count()| 899row_count() 9001 901delete from t1| 902select row_count()| 903row_count() 9043 905delete from t1| 906select row_count()| 907row_count() 9080 909select * from t1| 910id data 911select row_count()| 912row_count() 913-1 914drop procedure rc| 915drop function if exists f0| 916drop function if exists f1| 917drop function if exists f2| 918drop function if exists f3| 919drop function if exists f4| 920drop function if exists f5| 921drop function if exists f6| 922drop function if exists f7| 923drop function if exists f8| 924drop function if exists f9| 925drop function if exists f10| 926drop function if exists f11| 927drop function if exists f12_1| 928drop function if exists f12_2| 929drop view if exists v0| 930drop view if exists v1| 931drop view if exists v2| 932delete from t1| 933delete from t2| 934insert into t1 values ("a", 1), ("b", 2) | 935insert into t2 values ("a", 1, 1.0), ("b", 2, 2.0), ("c", 3, 3.0) | 936create function f1() returns int 937return (select sum(data) from t1)| 938select f1()| 939f1() 9403 941select id, f1() from t1 order by id| 942id f1() 943a 3 944b 3 945create function f2() returns int 946return (select data from t1 where data <= (select sum(data) from t1) order by data limit 1)| 947select f2()| 948f2() 9491 950select id, f2() from t1 order by id| 951id f2() 952a 1 953b 1 954create function f3() returns int 955begin 956declare n int; 957declare m int; 958set n:= (select min(data) from t1); 959set m:= (select max(data) from t1); 960return n < m; 961end| 962select f3()| 963f3() 9641 965select id, f3() from t1 order by id| 966id f3() 967a 1 968b 1 969select f1(), f3()| 970f1() f3() 9713 1 972select id, f1(), f3() from t1 order by id| 973id f1() f3() 974a 3 1 975b 3 1 976create function f4() returns double 977return (select d from t1, t2 where t1.data = t2.i and t1.id= "b")| 978select f4()| 979f4() 9802 981select s, f4() from t2 order by s| 982s f4() 983a 2 984b 2 985c 2 986create function f5(i int) returns int 987begin 988if i <= 0 then 989return 0; 990elseif i = 1 then 991return (select count(*) from t1 where data = i); 992else 993return (select count(*) + f5( i - 1) from t1 where data = i); 994end if; 995end| 996select f5(1)| 997f5(1) 9981 999select f5(2)| 1000ERROR HY000: Recursive stored functions and triggers are not allowed. 1001select f5(3)| 1002ERROR HY000: Recursive stored functions and triggers are not allowed. 1003create function f6() returns int 1004begin 1005declare n int; 1006set n:= f1(); 1007return (select count(*) from t1 where data <= f7() and data <= n); 1008end| 1009create function f7() returns int 1010return (select sum(data) from t1 where data <= f1())| 1011select f6()| 1012f6() 10132 1014select id, f6() from t1 order by id| 1015id f6() 1016a 2 1017b 2 1018create view v1 (a) as select f1()| 1019select * from v1| 1020a 10213 1022select id, a from t1, v1 order by id| 1023id a 1024a 3 1025b 3 1026select * from v1, v1 as v| 1027a a 10283 3 1029create view v2 (a) as select a*10 from v1| 1030select * from v2| 1031a 103230 1033select id, a from t1, v2 order by id| 1034id a 1035a 30 1036b 30 1037select * from v1, v2| 1038a a 10393 30 1040create function f8 () returns int 1041return (select count(*) from v2)| 1042select *, f8() from v1| 1043a f8() 10443 1 1045drop function f1| 1046select * from v1| 1047ERROR HY000: View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them 1048create function f1() returns int 1049return (select sum(data) from t1) + (select sum(data) from v1)| 1050select f1()| 1051ERROR HY000: Recursive stored functions and triggers are not allowed. 1052select * from v1| 1053ERROR HY000: Recursive stored functions and triggers are not allowed. 1054select * from v2| 1055ERROR HY000: Recursive stored functions and triggers are not allowed. 1056drop function f1| 1057create function f1() returns int 1058return (select sum(data) from t1)| 1059create function f0() returns int 1060return (select * from (select 100) as r)| 1061select f0()| 1062f0() 1063100 1064select *, f0() from (select 1) as t| 10651 f0() 10661 100 1067create view v0 as select f0()| 1068select * from v0| 1069f0() 1070100 1071select *, f0() from v0| 1072f0() f0() 1073100 100 1074lock tables t1 read, t1 as t11 read| 1075select f3()| 1076f3() 10771 1078select id, f3() from t1 as t11 order by id| 1079id f3() 1080a 1 1081b 1 1082select f0()| 1083f0() 1084100 1085select * from v0| 1086ERROR HY000: Table 'v0' was not locked with LOCK TABLES 1087select *, f0() from v0, (select 123) as d1| 1088ERROR HY000: Table 'v0' was not locked with LOCK TABLES 1089select id, f3() from t1| 1090ERROR HY000: Table 't1' was not locked with LOCK TABLES 1091select f4()| 1092ERROR HY000: Table 't2' was not locked with LOCK TABLES 1093unlock tables| 1094lock tables v2 read, mysql.proc read| 1095select * from v2| 1096a 109730 1098select * from v1| 1099a 11003 1101select * from v1, t1| 1102ERROR HY000: Table 't1' was not locked with LOCK TABLES 1103select f4()| 1104ERROR HY000: Table 't2' was not locked with LOCK TABLES 1105unlock tables| 1106create function f9() returns int 1107begin 1108declare a, b int; 1109drop temporary table if exists t3; 1110create temporary table t3 (id int); 1111insert into t3 values (1), (2), (3); 1112set a:= (select count(*) from t3); 1113set b:= (select count(*) from t3 t3_alias); 1114return a + b; 1115end| 1116select f9()| 1117f9() 11186 1119select f9() from t1 limit 1| 1120f9() 11216 1122create function f10() returns int 1123begin 1124drop temporary table if exists t3; 1125create temporary table t3 (id int); 1126insert into t3 select id from t4; 1127return (select count(*) from t3); 1128end| 1129select f10()| 1130ERROR 42S02: Table 'test.t4' doesn't exist 1131create table t4 as select 1 as id| 1132select f10()| 1133f10() 11341 1135create function f11() returns int 1136begin 1137drop temporary table if exists t3; 1138create temporary table t3 (id int); 1139insert into t3 values (1), (2), (3); 1140return (select count(*) from t3 as a, t3 as b); 1141end| 1142select f11()| 1143ERROR HY000: Can't reopen table: 'a' 1144select f11() from t1| 1145ERROR HY000: Can't reopen table: 'a' 1146create function f12_1() returns int 1147begin 1148drop temporary table if exists t3; 1149create temporary table t3 (id int); 1150insert into t3 values (1), (2), (3); 1151return f12_2(); 1152end| 1153create function f12_2() returns int 1154return (select count(*) from t3)| 1155drop temporary table t3| 1156select f12_1()| 1157f12_1() 11583 1159select f12_1() from t1 limit 1| 1160f12_1() 11613 1162drop function f0| 1163drop function f1| 1164drop function f2| 1165drop function f3| 1166drop function f4| 1167drop function f5| 1168drop function f6| 1169drop function f7| 1170drop function f8| 1171drop function f9| 1172drop function f10| 1173drop function f11| 1174drop function f12_1| 1175drop function f12_2| 1176drop view v0| 1177drop view v1| 1178drop view v2| 1179truncate table t1 | 1180truncate table t2 | 1181drop table t4| 1182drop table if exists t3| 1183create table t3 (n int unsigned not null primary key, f bigint unsigned)| 1184drop procedure if exists ifac| 1185create procedure ifac(n int unsigned) 1186begin 1187declare i int unsigned default 1; 1188if n > 20 then 1189set n = 20; # bigint overflow otherwise 1190end if; 1191while i <= n do 1192begin 1193insert into test.t3 values (i, fac(i)); 1194set i = i + 1; 1195end; 1196end while; 1197end| 1198call ifac(20)| 1199select * from t3| 1200n f 12011 1 12022 2 12033 6 12044 24 12055 120 12066 720 12077 5040 12088 40320 12099 362880 121010 3628800 121111 39916800 121212 479001600 121313 6227020800 121414 87178291200 121515 1307674368000 121616 20922789888000 121717 355687428096000 121818 6402373705728000 121919 121645100408832000 122020 2432902008176640000 1221drop table t3| 1222show function status like '%f%'| 1223Db Name Type Definer Modified Created Security_type Comment character_set_client collation_connection Database Collation 1224test fac FUNCTION root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER latin1 latin1_swedish_ci latin1_swedish_ci 1225drop procedure ifac| 1226drop function fac| 1227show function status like '%f%'| 1228Db Name Type Definer Modified Created Security_type Comment character_set_client collation_connection Database Collation 1229drop table if exists t3| 1230create table t3 ( 1231i int unsigned not null primary key, 1232p bigint unsigned not null 1233)| 1234insert into t3 values 1235( 0, 3), ( 1, 5), ( 2, 7), ( 3, 11), ( 4, 13), 1236( 5, 17), ( 6, 19), ( 7, 23), ( 8, 29), ( 9, 31), 1237(10, 37), (11, 41), (12, 43), (13, 47), (14, 53), 1238(15, 59), (16, 61), (17, 67), (18, 71), (19, 73), 1239(20, 79), (21, 83), (22, 89), (23, 97), (24, 101), 1240(25, 103), (26, 107), (27, 109), (28, 113), (29, 127), 1241(30, 131), (31, 137), (32, 139), (33, 149), (34, 151), 1242(35, 157), (36, 163), (37, 167), (38, 173), (39, 179), 1243(40, 181), (41, 191), (42, 193), (43, 197), (44, 199)| 1244drop procedure if exists opp| 1245create procedure opp(n bigint unsigned, out pp bool) 1246begin 1247declare r double; 1248declare b, s bigint unsigned default 0; 1249set r = sqrt(n); 1250again: 1251loop 1252if s = 45 then 1253set b = b+200, s = 0; 1254else 1255begin 1256declare p bigint unsigned; 1257select t.p into p from test.t3 t where t.i = s; 1258if b+p > r then 1259set pp = 1; 1260leave again; 1261end if; 1262if mod(n, b+p) = 0 then 1263set pp = 0; 1264leave again; 1265end if; 1266set s = s+1; 1267end; 1268end if; 1269end loop; 1270end| 1271drop procedure if exists ip| 1272create procedure ip(m int unsigned) 1273begin 1274declare p bigint unsigned; 1275declare i int unsigned; 1276set i=45, p=201; 1277while i < m do 1278begin 1279declare pp bool default 0; 1280call opp(p, pp); 1281if pp then 1282insert into test.t3 values (i, p); 1283set i = i+1; 1284end if; 1285set p = p+2; 1286end; 1287end while; 1288end| 1289show create procedure opp| 1290Procedure sql_mode Create Procedure character_set_client collation_connection Database Collation 1291opp CREATE DEFINER=`root`@`localhost` PROCEDURE `opp`(n bigint unsigned, out pp bool) 1292begin 1293declare r double; 1294declare b, s bigint unsigned default 0; 1295set r = sqrt(n); 1296again: 1297loop 1298if s = 45 then 1299set b = b+200, s = 0; 1300else 1301begin 1302declare p bigint unsigned; 1303select t.p into p from test.t3 t where t.i = s; 1304if b+p > r then 1305set pp = 1; 1306leave again; 1307end if; 1308if mod(n, b+p) = 0 then 1309set pp = 0; 1310leave again; 1311end if; 1312set s = s+1; 1313end; 1314end if; 1315end loop; 1316end latin1 latin1_swedish_ci latin1_swedish_ci 1317show procedure status where name like '%p%' and db='test'| 1318Db Name Type Definer Modified Created Security_type Comment character_set_client collation_connection Database Collation 1319test ip PROCEDURE root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER latin1 latin1_swedish_ci latin1_swedish_ci 1320test opp PROCEDURE root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER latin1 latin1_swedish_ci latin1_swedish_ci 1321call ip(200)| 1322select * from t3 where i=45 or i=100 or i=199| 1323i p 132445 211 1325100 557 1326199 1229 1327drop table t3| 1328drop procedure opp| 1329drop procedure ip| 1330show procedure status where name like '%p%' and db='test'| 1331Db Name Type Definer Modified Created Security_type Comment character_set_client collation_connection Database Collation 1332drop procedure if exists bar| 1333create procedure bar(x char(16), y int) 1334comment "111111111111" sql security invoker 1335insert into test.t1 values (x, y)| 1336show procedure status like 'bar'| 1337Db Name Type Definer Modified Created Security_type Comment character_set_client collation_connection Database Collation 1338test bar PROCEDURE root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 INVOKER 111111111111 latin1 latin1_swedish_ci latin1_swedish_ci 1339alter procedure bar comment "2222222222" sql security definer| 1340alter procedure bar comment "3333333333"| 1341alter procedure bar| 1342show create procedure bar| 1343Procedure sql_mode Create Procedure character_set_client collation_connection Database Collation 1344bar CREATE DEFINER=`root`@`localhost` PROCEDURE `bar`(x char(16), y int) 1345 COMMENT '3333333333' 1346insert into test.t1 values (x, y) latin1 latin1_swedish_ci latin1_swedish_ci 1347show procedure status like 'bar'| 1348Db Name Type Definer Modified Created Security_type Comment character_set_client collation_connection Database Collation 1349test bar PROCEDURE root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER 3333333333 latin1 latin1_swedish_ci latin1_swedish_ci 1350drop procedure bar| 1351drop procedure if exists p1| 1352create procedure p1 () 1353select (select s1 from t3) from t3| 1354create table t3 (s1 int)| 1355call p1()| 1356(select s1 from t3) 1357insert into t3 values (1)| 1358call p1()| 1359(select s1 from t3) 13601 1361drop procedure p1| 1362drop table t3| 1363drop function if exists foo| 1364create function `foo` () returns int 1365return 5| 1366select `foo` ()| 1367`foo` () 13685 1369drop function `foo`| 1370drop function if exists t1max| 1371create function t1max() returns int 1372begin 1373declare x int; 1374select max(data) into x from t1; 1375return x; 1376end| 1377insert into t1 values ("foo", 3), ("bar", 2), ("zip", 5), ("zap", 1)| 1378select t1max()| 1379t1max() 13805 1381drop function t1max| 1382create table t3 ( 1383v char(16) not null primary key, 1384c int unsigned not null 1385)| 1386create function getcount(s char(16)) returns int 1387begin 1388declare x int; 1389select count(*) into x from t3 where v = s; 1390if x = 0 then 1391insert into t3 values (s, 1); 1392else 1393update t3 set c = c+1 where v = s; 1394end if; 1395return x; 1396end| 1397select * from t1 where data = getcount("bar")| 1398id data 1399zap 1 1400select * from t3| 1401v c 1402bar 4 1403select getcount("zip")| 1404getcount("zip") 14050 1406select getcount("zip")| 1407getcount("zip") 14081 1409select * from t3| 1410v c 1411bar 4 1412zip 2 1413select getcount(id) from t1 where data = 3| 1414getcount(id) 14150 1416select getcount(id) from t1 where data = 5| 1417getcount(id) 14181 1419select * from t3| 1420v c 1421bar 4 1422zip 3 1423foo 1 1424drop table t3| 1425drop function getcount| 1426drop table if exists t3| 1427drop procedure if exists h_ee| 1428drop procedure if exists h_es| 1429drop procedure if exists h_en| 1430drop procedure if exists h_ew| 1431drop procedure if exists h_ex| 1432drop procedure if exists h_se| 1433drop procedure if exists h_ss| 1434drop procedure if exists h_sn| 1435drop procedure if exists h_sw| 1436drop procedure if exists h_sx| 1437drop procedure if exists h_ne| 1438drop procedure if exists h_ns| 1439drop procedure if exists h_nn| 1440drop procedure if exists h_we| 1441drop procedure if exists h_ws| 1442drop procedure if exists h_ww| 1443drop procedure if exists h_xe| 1444drop procedure if exists h_xs| 1445drop procedure if exists h_xx| 1446create table t3 (a smallint primary key)| 1447insert into t3 (a) values (1)| 1448create procedure h_ee() 1449deterministic 1450begin 1451declare continue handler for 1062 -- ER_DUP_ENTRY 1452select 'Outer (bad)' as 'h_ee'; 1453begin 1454declare continue handler for 1062 -- ER_DUP_ENTRY 1455select 'Inner (good)' as 'h_ee'; 1456insert into t3 values (1); 1457end; 1458end| 1459create procedure h_es() 1460deterministic 1461begin 1462declare continue handler for 1062 -- ER_DUP_ENTRY 1463select 'Outer (bad)' as 'h_es'; 1464begin 1465-- integrity constraint violation 1466declare continue handler for sqlstate '23000' 1467 select 'Inner (good)' as 'h_es'; 1468insert into t3 values (1); 1469end; 1470end| 1471create procedure h_en() 1472deterministic 1473begin 1474declare continue handler for 1329 -- ER_SP_FETCH_NO_DATA 1475select 'Outer (bad)' as 'h_en'; 1476begin 1477declare x int; 1478declare continue handler for sqlstate '02000' -- no data 1479select 'Inner (good)' as 'h_en'; 1480select a into x from t3 where a = 42; 1481end; 1482end| 1483create procedure h_ew() 1484deterministic 1485begin 1486declare continue handler for 1264 -- ER_WARN_DATA_OUT_OF_RANGE 1487select 'Outer (bad)' as 'h_ew'; 1488begin 1489declare continue handler for sqlwarning 1490select 'Inner (good)' as 'h_ew'; 1491insert into t3 values (123456789012); 1492end; 1493delete from t3; 1494insert into t3 values (1); 1495end| 1496create procedure h_ex() 1497deterministic 1498begin 1499declare continue handler for 1062 -- ER_DUP_ENTRY 1500select 'Outer (bad)' as 'h_ex'; 1501begin 1502declare continue handler for sqlexception 1503select 'Inner (good)' as 'h_ex'; 1504insert into t3 values (1); 1505end; 1506end| 1507create procedure h_se() 1508deterministic 1509begin 1510-- integrity constraint violation 1511declare continue handler for sqlstate '23000' 1512select 'Outer (bad)' as 'h_se'; 1513begin 1514declare continue handler for 1062 -- ER_DUP_ENTRY 1515select 'Inner (good)' as 'h_se'; 1516insert into t3 values (1); 1517end; 1518end| 1519create procedure h_ss() 1520deterministic 1521begin 1522-- integrity constraint violation 1523declare continue handler for sqlstate '23000' 1524select 'Outer (bad)' as 'h_ss'; 1525begin 1526-- integrity constraint violation 1527declare continue handler for sqlstate '23000' 1528select 'Inner (good)' as 'h_ss'; 1529insert into t3 values (1); 1530end; 1531end| 1532create procedure h_sn() 1533deterministic 1534begin 1535-- Note: '02000' is more specific than NOT FOUND ; 1536-- there might be other not found states 1537declare continue handler for sqlstate '02000' -- no data 1538select 'Outer (bad)' as 'h_sn'; 1539begin 1540declare x int; 1541declare continue handler for not found 1542select 'Inner (good)' as 'h_sn'; 1543select a into x from t3 where a = 42; 1544end; 1545end| 1546create procedure h_sw() 1547deterministic 1548begin 1549-- data exception - numeric value out of range 1550declare continue handler for sqlstate '22003' 1551 select 'Outer (bad)' as 'h_sw'; 1552begin 1553declare continue handler for sqlwarning 1554select 'Inner (good)' as 'h_sw'; 1555insert into t3 values (123456789012); 1556end; 1557delete from t3; 1558insert into t3 values (1); 1559end| 1560create procedure h_sx() 1561deterministic 1562begin 1563-- integrity constraint violation 1564declare continue handler for sqlstate '23000' 1565select 'Outer (bad)' as 'h_sx'; 1566begin 1567declare continue handler for sqlexception 1568select 'Inner (good)' as 'h_sx'; 1569insert into t3 values (1); 1570end; 1571end| 1572create procedure h_ne() 1573deterministic 1574begin 1575declare continue handler for not found 1576select 'Outer (bad)' as 'h_ne'; 1577begin 1578declare x int; 1579declare continue handler for 1329 -- ER_SP_FETCH_NO_DATA 1580select 'Inner (good)' as 'h_ne'; 1581select a into x from t3 where a = 42; 1582end; 1583end| 1584create procedure h_ns() 1585deterministic 1586begin 1587declare continue handler for not found 1588select 'Outer (bad)' as 'h_ns'; 1589begin 1590declare x int; 1591declare continue handler for sqlstate '02000' -- no data 1592select 'Inner (good)' as 'h_ns'; 1593select a into x from t3 where a = 42; 1594end; 1595end| 1596create procedure h_nn() 1597deterministic 1598begin 1599declare continue handler for not found 1600select 'Outer (bad)' as 'h_nn'; 1601begin 1602declare x int; 1603declare continue handler for not found 1604select 'Inner (good)' as 'h_nn'; 1605select a into x from t3 where a = 42; 1606end; 1607end| 1608create procedure h_we() 1609deterministic 1610begin 1611declare continue handler for sqlwarning 1612select 'Outer (bad)' as 'h_we'; 1613begin 1614declare continue handler for 1264 -- ER_WARN_DATA_OUT_OF_RANGE 1615select 'Inner (good)' as 'h_we'; 1616insert into t3 values (123456789012); 1617end; 1618delete from t3; 1619insert into t3 values (1); 1620end| 1621create procedure h_ws() 1622deterministic 1623begin 1624declare continue handler for sqlwarning 1625select 'Outer (bad)' as 'h_ws'; 1626begin 1627-- data exception - numeric value out of range 1628declare continue handler for sqlstate '22003' 1629 select 'Inner (good)' as 'h_ws'; 1630insert into t3 values (123456789012); 1631end; 1632delete from t3; 1633insert into t3 values (1); 1634end| 1635create procedure h_ww() 1636deterministic 1637begin 1638declare continue handler for sqlwarning 1639select 'Outer (bad)' as 'h_ww'; 1640begin 1641declare continue handler for sqlwarning 1642select 'Inner (good)' as 'h_ww'; 1643insert into t3 values (123456789012); 1644end; 1645delete from t3; 1646insert into t3 values (1); 1647end| 1648create procedure h_xe() 1649deterministic 1650begin 1651declare continue handler for sqlexception 1652select 'Outer (bad)' as 'h_xe'; 1653begin 1654declare continue handler for 1062 -- ER_DUP_ENTRY 1655select 'Inner (good)' as 'h_xe'; 1656insert into t3 values (1); 1657end; 1658end| 1659create procedure h_xs() 1660deterministic 1661begin 1662declare continue handler for sqlexception 1663select 'Outer (bad)' as 'h_xs'; 1664begin 1665-- integrity constraint violation 1666declare continue handler for sqlstate '23000' 1667 select 'Inner (good)' as 'h_xs'; 1668insert into t3 values (1); 1669end; 1670end| 1671create procedure h_xx() 1672deterministic 1673begin 1674declare continue handler for sqlexception 1675select 'Outer (bad)' as 'h_xx'; 1676begin 1677declare continue handler for sqlexception 1678select 'Inner (good)' as 'h_xx'; 1679insert into t3 values (1); 1680end; 1681end| 1682call h_ee()| 1683h_ee 1684Inner (good) 1685call h_es()| 1686h_es 1687Inner (good) 1688call h_en()| 1689h_en 1690Inner (good) 1691call h_ew()| 1692h_ew 1693Inner (good) 1694call h_ex()| 1695h_ex 1696Inner (good) 1697call h_se()| 1698h_se 1699Inner (good) 1700call h_ss()| 1701h_ss 1702Inner (good) 1703call h_sn()| 1704h_sn 1705Inner (good) 1706call h_sw()| 1707h_sw 1708Inner (good) 1709call h_sx()| 1710h_sx 1711Inner (good) 1712call h_ne()| 1713h_ne 1714Inner (good) 1715call h_ns()| 1716h_ns 1717Inner (good) 1718call h_nn()| 1719h_nn 1720Inner (good) 1721call h_we()| 1722h_we 1723Inner (good) 1724call h_ws()| 1725h_ws 1726Inner (good) 1727call h_ww()| 1728h_ww 1729Inner (good) 1730call h_xe()| 1731h_xe 1732Inner (good) 1733call h_xs()| 1734h_xs 1735Inner (good) 1736call h_xx()| 1737h_xx 1738Inner (good) 1739drop table t3| 1740drop procedure h_ee| 1741drop procedure h_es| 1742drop procedure h_en| 1743drop procedure h_ew| 1744drop procedure h_ex| 1745drop procedure h_se| 1746drop procedure h_ss| 1747drop procedure h_sn| 1748drop procedure h_sw| 1749drop procedure h_sx| 1750drop procedure h_ne| 1751drop procedure h_ns| 1752drop procedure h_nn| 1753drop procedure h_we| 1754drop procedure h_ws| 1755drop procedure h_ww| 1756drop procedure h_xe| 1757drop procedure h_xs| 1758drop procedure h_xx| 1759drop procedure if exists bug822| 1760create procedure bug822(a_id char(16), a_data int) 1761begin 1762declare n int; 1763select count(*) into n from t1 where id = a_id and data = a_data; 1764if n = 0 then 1765insert into t1 (id, data) values (a_id, a_data); 1766end if; 1767end| 1768delete from t1| 1769call bug822('foo', 42)| 1770call bug822('foo', 42)| 1771call bug822('bar', 666)| 1772select * from t1 order by data| 1773id data 1774foo 42 1775bar 666 1776delete from t1| 1777drop procedure bug822| 1778drop procedure if exists bug1495| 1779create procedure bug1495() 1780begin 1781declare x int; 1782select data into x from t1 order by id limit 1; 1783if x > 10 then 1784insert into t1 values ("less", x-10); 1785else 1786insert into t1 values ("more", x+10); 1787end if; 1788end| 1789insert into t1 values ('foo', 12)| 1790call bug1495()| 1791delete from t1 where id='foo'| 1792insert into t1 values ('bar', 7)| 1793call bug1495()| 1794delete from t1 where id='bar'| 1795select * from t1 order by data| 1796id data 1797less 2 1798more 17 1799delete from t1| 1800drop procedure bug1495| 1801drop procedure if exists bug1547| 1802create procedure bug1547(s char(16)) 1803begin 1804declare x int; 1805select data into x from t1 where s = id limit 1; 1806if x > 10 then 1807insert into t1 values ("less", x-10); 1808else 1809insert into t1 values ("more", x+10); 1810end if; 1811end| 1812insert into t1 values ("foo", 12), ("bar", 7)| 1813call bug1547("foo")| 1814call bug1547("bar")| 1815select * from t1 order by id| 1816id data 1817bar 7 1818foo 12 1819less 2 1820more 17 1821delete from t1| 1822drop procedure bug1547| 1823drop table if exists t70| 1824create table t70 (s1 int,s2 int)| 1825insert into t70 values (1,2)| 1826drop procedure if exists bug1656| 1827create procedure bug1656(out p1 int, out p2 int) 1828select * into p1, p1 from t70| 1829call bug1656(@1, @2)| 1830select @1, @2| 1831@1 @2 18322 NULL 1833drop table t70| 1834drop procedure bug1656| 1835create table t3(a int)| 1836drop procedure if exists bug1862| 1837create procedure bug1862() 1838begin 1839insert into t3 values(2); 1840flush tables; 1841end| 1842call bug1862()| 1843call bug1862()| 1844select * from t3| 1845a 18462 18472 1848drop table t3| 1849drop procedure bug1862| 1850drop procedure if exists bug1874| 1851create procedure bug1874() 1852begin 1853declare x int; 1854declare y double; 1855select max(data) into x from t1; 1856insert into t2 values ("max", x, 0); 1857select min(data) into x from t1; 1858insert into t2 values ("min", x, 0); 1859select sum(data) into x from t1; 1860insert into t2 values ("sum", x, 0); 1861select avg(data) into y from t1; 1862insert into t2 values ("avg", 0, y); 1863end| 1864insert into t1 (data) values (3), (1), (5), (9), (4)| 1865call bug1874()| 1866select * from t2 order by i| 1867s i d 1868avg 0 4.4 1869min 1 0 1870max 9 0 1871sum 22 0 1872delete from t1| 1873delete from t2| 1874drop procedure bug1874| 1875drop procedure if exists bug2260| 1876create procedure bug2260() 1877begin 1878declare v1 int; 1879declare c1 cursor for select data from t1; 1880declare continue handler for not found set @x2 = 1; 1881open c1; 1882fetch c1 into v1; 1883set @x2 = 2; 1884close c1; 1885end| 1886call bug2260()| 1887select @x2| 1888@x2 18892 1890drop procedure bug2260| 1891drop procedure if exists bug2267_1| 1892create procedure bug2267_1() 1893begin 1894show procedure status where db='test'; 1895end| 1896drop procedure if exists bug2267_2| 1897create procedure bug2267_2() 1898begin 1899show function status where db='test'; 1900end| 1901drop procedure if exists bug2267_3| 1902create procedure bug2267_3() 1903begin 1904show create procedure bug2267_1; 1905end| 1906drop procedure if exists bug2267_4| 1907drop function if exists bug2267_4| 1908create procedure bug2267_4() 1909begin 1910show create function bug2267_4; 1911end| 1912create function bug2267_4() returns int return 100| 1913call bug2267_1()| 1914Db Name Type Definer Modified Created Security_type Comment character_set_client collation_connection Database Collation 1915test bug2267_1 PROCEDURE root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER latin1 latin1_swedish_ci latin1_swedish_ci 1916test bug2267_2 PROCEDURE root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER latin1 latin1_swedish_ci latin1_swedish_ci 1917test bug2267_3 PROCEDURE root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER latin1 latin1_swedish_ci latin1_swedish_ci 1918test bug2267_4 PROCEDURE root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER latin1 latin1_swedish_ci latin1_swedish_ci 1919call bug2267_2()| 1920Db Name Type Definer Modified Created Security_type Comment character_set_client collation_connection Database Collation 1921test bug2267_4 FUNCTION root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER latin1 latin1_swedish_ci latin1_swedish_ci 1922call bug2267_3()| 1923Procedure sql_mode Create Procedure character_set_client collation_connection Database Collation 1924bug2267_1 CREATE DEFINER=`root`@`localhost` PROCEDURE `bug2267_1`() 1925begin 1926show procedure status where db='test'; 1927end latin1 latin1_swedish_ci latin1_swedish_ci 1928call bug2267_4()| 1929Function sql_mode Create Function character_set_client collation_connection Database Collation 1930bug2267_4 CREATE DEFINER=`root`@`localhost` FUNCTION `bug2267_4`() RETURNS int(11) 1931return 100 latin1 latin1_swedish_ci latin1_swedish_ci 1932drop procedure bug2267_1| 1933drop procedure bug2267_2| 1934drop procedure bug2267_3| 1935drop procedure bug2267_4| 1936drop function bug2267_4| 1937drop procedure if exists bug2227| 1938create procedure bug2227(x int) 1939begin 1940declare y float default 2.6; 1941declare z char(16) default "zzz"; 1942select 1.3, x, y, 42, z; 1943end| 1944call bug2227(9)| 19451.3 x y 42 z 19461.3 9 2.6 42 zzz 1947drop procedure bug2227| 1948drop procedure if exists bug2614| 1949create procedure bug2614() 1950begin 1951drop table if exists t3; 1952create table t3 (id int default '0' not null); 1953insert into t3 select 12; 1954insert into t3 select * from t3; 1955end| 1956call bug2614()| 1957call bug2614()| 1958drop table t3| 1959drop procedure bug2614| 1960drop function if exists bug2674| 1961create function bug2674() returns int 1962return @@sort_buffer_size| 1963set @osbs = @@sort_buffer_size| 1964set @@sort_buffer_size = 262000| 1965select bug2674()| 1966bug2674() 1967262000 1968drop function bug2674| 1969set @@sort_buffer_size = @osbs| 1970drop procedure if exists bug3259_1 | 1971create procedure bug3259_1 () begin end| 1972drop procedure if exists BUG3259_2 | 1973create procedure BUG3259_2 () begin end| 1974drop procedure if exists Bug3259_3 | 1975create procedure Bug3259_3 () begin end| 1976call BUG3259_1()| 1977call BUG3259_1()| 1978call bug3259_2()| 1979call Bug3259_2()| 1980call bug3259_3()| 1981call bUG3259_3()| 1982drop procedure bUg3259_1| 1983drop procedure BuG3259_2| 1984drop procedure BUG3259_3| 1985drop function if exists bug2772| 1986create function bug2772() returns char(10) character set latin2 1987return 'a'| 1988select bug2772()| 1989bug2772() 1990a 1991drop function bug2772| 1992create table t3 (s1 smallint)| 1993insert into t3 values (123456789012)| 1994Warnings: 1995Warning 1264 Out of range value for column 's1' at row 1 1996drop procedure if exists bug2780| 1997create procedure bug2780() 1998begin 1999declare exit handler for sqlwarning set @x = 1; 2000set @x = 0; 2001insert into t3 values (123456789012); 2002insert into t3 values (0); 2003end| 2004call bug2780()| 2005select @x| 2006@x 20071 2008select * from t3| 2009s1 201032767 201132767 2012drop procedure bug2780| 2013drop table t3| 2014create table t3 (content varchar(10) )| 2015insert into t3 values ("test1")| 2016insert into t3 values ("test2")| 2017create table t4 (f1 int, rc int, t3 int)| 2018drop procedure if exists bug1863| 2019create procedure bug1863(in1 int) 2020begin 2021declare ind int default 0; 2022declare t1 int; 2023declare t2 int; 2024declare t3 int; 2025declare rc int default 0; 2026declare continue handler for 1065 set rc = 1; 2027drop temporary table if exists temp_t1; 2028create temporary table temp_t1 ( 2029f1 int auto_increment, f2 varchar(20), primary key (f1) 2030); 2031insert into temp_t1 (f2) select content from t3; 2032select f2 into t3 from temp_t1 where f1 = 10; 2033if (rc) then 2034insert into t4 values (1, rc, t3); 2035end if; 2036insert into t4 values (2, rc, t3); 2037end| 2038call bug1863(10)| 2039call bug1863(10)| 2040select * from t4| 2041f1 rc t3 20422 0 NULL 20432 0 NULL 2044drop procedure bug1863| 2045drop temporary table temp_t1; 2046drop table t3, t4| 2047create table t3 ( 2048OrderID int not null, 2049MarketID int, 2050primary key (OrderID) 2051)| 2052create table t4 ( 2053MarketID int not null, 2054Market varchar(60), 2055Status char(1), 2056primary key (MarketID) 2057)| 2058insert t3 (OrderID,MarketID) values (1,1)| 2059insert t3 (OrderID,MarketID) values (2,2)| 2060insert t4 (MarketID,Market,Status) values (1,"MarketID One","A")| 2061insert t4 (MarketID,Market,Status) values (2,"MarketID Two","A")| 2062drop procedure if exists bug2656_1| 2063create procedure bug2656_1() 2064begin 2065select 2066m.Market 2067from t4 m JOIN t3 o 2068ON o.MarketID != 1 and o.MarketID = m.MarketID; 2069end | 2070drop procedure if exists bug2656_2| 2071create procedure bug2656_2() 2072begin 2073select 2074m.Market 2075from 2076t4 m, t3 o 2077where 2078m.MarketID != 1 and m.MarketID = o.MarketID; 2079end | 2080call bug2656_1()| 2081Market 2082MarketID Two 2083call bug2656_1()| 2084Market 2085MarketID Two 2086call bug2656_2()| 2087Market 2088MarketID Two 2089call bug2656_2()| 2090Market 2091MarketID Two 2092drop procedure bug2656_1| 2093drop procedure bug2656_2| 2094drop table t3, t4| 2095drop procedure if exists bug3426| 2096create procedure bug3426(in_time int unsigned, out x int) 2097begin 2098if in_time is null then 2099set @stamped_time=10; 2100set x=1; 2101else 2102set @stamped_time=in_time; 2103set x=2; 2104end if; 2105end| 2106set time_zone='+03:00'; 2107call bug3426(1000, @i)| 2108select @i, from_unixtime(@stamped_time, '%d-%m-%Y %h:%i:%s') as time| 2109@i time 21102 01-01-1970 03:16:40 2111call bug3426(NULL, @i)| 2112select @i, from_unixtime(@stamped_time, '%d-%m-%Y %h:%i:%s') as time| 2113@i time 21141 01-01-1970 03:00:10 2115alter procedure bug3426 sql security invoker| 2116call bug3426(NULL, @i)| 2117select @i, from_unixtime(@stamped_time, '%d-%m-%Y %h:%i:%s') as time| 2118@i time 21191 01-01-1970 03:00:10 2120call bug3426(1000, @i)| 2121select @i, from_unixtime(@stamped_time, '%d-%m-%Y %h:%i:%s') as time| 2122@i time 21232 01-01-1970 03:16:40 2124drop procedure bug3426| 2125create table t3 ( 2126id int unsigned auto_increment not null primary key, 2127title VARCHAR(200), 2128body text, 2129fulltext (title,body) 2130)| 2131insert into t3 (title,body) values 2132('MySQL Tutorial','DBMS stands for DataBase ...'), 2133('How To Use MySQL Well','After you went through a ...'), 2134('Optimizing MySQL','In this tutorial we will show ...'), 2135('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'), 2136('MySQL vs. YourSQL','In the following database comparison ...'), 2137('MySQL Security','When configured properly, MySQL ...')| 2138drop procedure if exists bug3734 | 2139create procedure bug3734 (param1 varchar(100)) 2140select * from t3 where match (title,body) against (param1)| 2141call bug3734('database')| 2142id title body 21435 MySQL vs. YourSQL In the following database comparison ... 21441 MySQL Tutorial DBMS stands for DataBase ... 2145call bug3734('Security')| 2146id title body 21476 MySQL Security When configured properly, MySQL ... 2148drop procedure bug3734| 2149drop table t3| 2150drop procedure if exists bug3863| 2151create procedure bug3863() 2152begin 2153set @a = 0; 2154while @a < 5 do 2155set @a = @a + 1; 2156end while; 2157end| 2158call bug3863()| 2159select @a| 2160@a 21615 2162call bug3863()| 2163select @a| 2164@a 21655 2166drop procedure bug3863| 2167create table t3 ( 2168id int(10) unsigned not null default 0, 2169rid int(10) unsigned not null default 0, 2170msg text not null, 2171primary key (id), 2172unique key rid (rid, id) 2173)| 2174drop procedure if exists bug2460_1| 2175create procedure bug2460_1(in v int) 2176begin 2177( select n0.id from t3 as n0 where n0.id = v ) 2178union 2179( select n0.id from t3 as n0, t3 as n1 2180where n0.id = n1.rid and n1.id = v ) 2181union 2182( select n0.id from t3 as n0, t3 as n1, t3 as n2 2183where n0.id = n1.rid and n1.id = n2.rid and n2.id = v ); 2184end| 2185call bug2460_1(2)| 2186id 2187call bug2460_1(2)| 2188id 2189insert into t3 values (1, 1, 'foo'), (2, 1, 'bar'), (3, 1, 'zip zap')| 2190call bug2460_1(2)| 2191id 21922 21931 2194call bug2460_1(2)| 2195id 21962 21971 2198drop procedure if exists bug2460_2| 2199create procedure bug2460_2() 2200begin 2201drop table if exists t3; 2202create temporary table t3 (s1 int); 2203insert into t3 select 1 union select 1; 2204end| 2205call bug2460_2()| 2206call bug2460_2()| 2207select * from t3| 2208s1 22091 2210drop procedure bug2460_1| 2211drop procedure bug2460_2| 2212drop table t3| 2213set @@sql_mode = ''| 2214drop procedure if exists bug2564_1| 2215create procedure bug2564_1() 2216comment 'Joe''s procedure' 2217 insert into `t1` values ("foo", 1)| 2218set @@sql_mode = 'ANSI_QUOTES'| 2219drop procedure if exists bug2564_2| 2220create procedure bug2564_2() 2221insert into "t1" values ('foo', 1)| 2222set @@sql_mode = ''$ 2223drop function if exists bug2564_3$ 2224create function bug2564_3(x int, y int) returns int 2225return x || y$ 2226set @@sql_mode = 'ANSI'$ 2227drop function if exists bug2564_4$ 2228create function bug2564_4(x int, y int) returns int 2229return x || y$ 2230set @@sql_mode = ''| 2231show create procedure bug2564_1| 2232Procedure sql_mode Create Procedure character_set_client collation_connection Database Collation 2233bug2564_1 CREATE DEFINER=`root`@`localhost` PROCEDURE `bug2564_1`() 2234 COMMENT 'Joe''s procedure' 2235insert into `t1` values ("foo", 1) latin1 latin1_swedish_ci latin1_swedish_ci 2236show create procedure bug2564_2| 2237Procedure sql_mode Create Procedure character_set_client collation_connection Database Collation 2238bug2564_2 ANSI_QUOTES CREATE DEFINER="root"@"localhost" PROCEDURE "bug2564_2"() 2239insert into "t1" values ('foo', 1) latin1 latin1_swedish_ci latin1_swedish_ci 2240show create function bug2564_3| 2241Function sql_mode Create Function character_set_client collation_connection Database Collation 2242bug2564_3 CREATE DEFINER=`root`@`localhost` FUNCTION `bug2564_3`(x int, y int) RETURNS int(11) 2243return x || y latin1 latin1_swedish_ci latin1_swedish_ci 2244show create function bug2564_4| 2245Function sql_mode Create Function character_set_client collation_connection Database Collation 2246bug2564_4 REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ANSI CREATE DEFINER="root"@"localhost" FUNCTION "bug2564_4"(x int, y int) RETURNS int(11) 2247return x || y latin1 latin1_swedish_ci latin1_swedish_ci 2248drop procedure bug2564_1| 2249drop procedure bug2564_2| 2250drop function bug2564_3| 2251drop function bug2564_4| 2252drop function if exists bug3132| 2253create function bug3132(s char(20)) returns char(50) 2254return concat('Hello, ', s, '!')| 2255select bug3132('Bob') union all select bug3132('Judy')| 2256bug3132('Bob') 2257Hello, Bob! 2258Hello, Judy! 2259drop function bug3132| 2260drop procedure if exists bug3843| 2261create procedure bug3843() 2262analyze table t1| 2263call bug3843()| 2264Table Op Msg_type Msg_text 2265test.t1 analyze status OK 2266call bug3843()| 2267Table Op Msg_type Msg_text 2268test.t1 analyze status Table is already up to date 2269select 1+2| 22701+2 22713 2272drop procedure bug3843| 2273create table t3 ( s1 char(10) )| 2274insert into t3 values ('a'), ('b')| 2275drop procedure if exists bug3368| 2276create procedure bug3368(v char(10)) 2277begin 2278select group_concat(v) from t3; 2279end| 2280call bug3368('x')| 2281group_concat(v) 2282x,x 2283call bug3368('yz')| 2284group_concat(v) 2285yz,yz 2286drop procedure bug3368| 2287drop table t3| 2288create table t3 (f1 int, f2 int)| 2289insert into t3 values (1,1)| 2290drop procedure if exists bug4579_1| 2291create procedure bug4579_1 () 2292begin 2293declare sf1 int; 2294select f1 into sf1 from t3 where f1=1 and f2=1; 2295update t3 set f2 = f2 + 1 where f1=1 and f2=1; 2296call bug4579_2(); 2297end| 2298drop procedure if exists bug4579_2| 2299create procedure bug4579_2 () 2300begin 2301end| 2302call bug4579_1()| 2303call bug4579_1()| 2304call bug4579_1()| 2305drop procedure bug4579_1| 2306drop procedure bug4579_2| 2307drop table t3| 2308drop procedure if exists bug2773| 2309create function bug2773() returns int return null| 2310create table t3 as select bug2773()| 2311show create table t3| 2312Table Create Table 2313t3 CREATE TABLE `t3` ( 2314 `bug2773()` int(11) DEFAULT NULL 2315) ENGINE=MyISAM DEFAULT CHARSET=latin1 2316drop table t3| 2317drop function bug2773| 2318drop procedure if exists bug3788| 2319create function bug3788() returns date return cast("2005-03-04" as date)| 2320select bug3788()| 2321bug3788() 23222005-03-04 2323drop function bug3788| 2324create function bug3788() returns binary(1) return 5| 2325select bug3788()| 2326bug3788() 23275 2328drop function bug3788| 2329create table t3 (f1 int, f2 int, f3 int)| 2330insert into t3 values (1,1,1)| 2331drop procedure if exists bug4726| 2332create procedure bug4726() 2333begin 2334declare tmp_o_id INT; 2335declare tmp_d_id INT default 1; 2336while tmp_d_id <= 2 do 2337begin 2338select f1 into tmp_o_id from t3 where f2=1 and f3=1; 2339set tmp_d_id = tmp_d_id + 1; 2340end; 2341end while; 2342end| 2343call bug4726()| 2344call bug4726()| 2345call bug4726()| 2346drop procedure bug4726| 2347drop table t3| 2348drop procedure if exists bug4902| 2349create procedure bug4902() 2350begin 2351show charset like 'foo'; 2352show collation like 'foo'; 2353show create table t1; 2354show create database test; 2355show databases like 'foo'; 2356show errors; 2357show columns from t1; 2358show keys from t1; 2359show open tables like 'foo'; 2360# Removed because result will differ in embedded mode. 2361#show privileges; 2362show status like 'foo'; 2363show tables like 'foo'; 2364show variables like 'foo'; 2365show warnings; 2366end| 2367call bug4902()| 2368Charset Description Default collation Maxlen 2369Collation Charset Id Default Compiled Sortlen 2370Table Create Table 2371t1 CREATE TABLE `t1` ( 2372 `id` char(16) NOT NULL DEFAULT '', 2373 `data` int(11) NOT NULL 2374) ENGINE=MyISAM DEFAULT CHARSET=latin1 2375Database Create Database 2376test CREATE DATABASE `test` /*!40100 DEFAULT CHARACTER SET latin1 */ 2377Database (foo) 2378Level Code Message 2379Field Type Null Key Default Extra 2380id char(16) NO 2381data int(11) NO NULL 2382Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment 2383Database Table In_use Name_locked 2384Variable_name Value 2385Tables_in_test (foo) 2386Variable_name Value 2387Level Code Message 2388call bug4902()| 2389Charset Description Default collation Maxlen 2390Collation Charset Id Default Compiled Sortlen 2391Table Create Table 2392t1 CREATE TABLE `t1` ( 2393 `id` char(16) NOT NULL DEFAULT '', 2394 `data` int(11) NOT NULL 2395) ENGINE=MyISAM DEFAULT CHARSET=latin1 2396Database Create Database 2397test CREATE DATABASE `test` /*!40100 DEFAULT CHARACTER SET latin1 */ 2398Database (foo) 2399Level Code Message 2400Field Type Null Key Default Extra 2401id char(16) NO 2402data int(11) NO NULL 2403Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment 2404Database Table In_use Name_locked 2405Variable_name Value 2406Tables_in_test (foo) 2407Variable_name Value 2408Level Code Message 2409drop procedure bug4902| 2410drop procedure if exists bug4904| 2411create procedure bug4904() 2412begin 2413declare continue handler for sqlstate 'HY000' begin end; 2414create table t2 as select * from t3; 2415end| 2416call bug4904()| 2417ERROR 42S02: Table 'test.t3' doesn't exist 2418drop procedure bug4904| 2419create table t3 (s1 char character set latin1, s2 char character set latin2)| 2420drop procedure if exists bug4904| 2421create procedure bug4904 () 2422begin 2423declare continue handler for sqlstate 'HY000' begin end; 2424select s1 from t3 union select s2 from t3; 2425end| 2426call bug4904()| 2427drop procedure bug4904| 2428drop table t3| 2429drop procedure if exists bug336| 2430create procedure bug336(out y int) 2431begin 2432declare x int; 2433set x = (select sum(t.data) from test.t1 t); 2434set y = x; 2435end| 2436insert into t1 values ("a", 2), ("b", 3)| 2437call bug336(@y)| 2438select @y| 2439@y 24405 2441delete from t1| 2442drop procedure bug336| 2443drop procedure if exists bug3157| 2444create procedure bug3157() 2445begin 2446if exists(select * from t1) then 2447set @n= @n + 1; 2448end if; 2449if (select count(*) from t1) then 2450set @n= @n + 1; 2451end if; 2452end| 2453set @n = 0| 2454insert into t1 values ("a", 1)| 2455call bug3157()| 2456select @n| 2457@n 24582 2459delete from t1| 2460drop procedure bug3157| 2461drop procedure if exists bug5251| 2462create procedure bug5251() 2463begin 2464end| 2465select created into @c1 from mysql.proc 2466where db='test' and name='bug5251'| 2467alter procedure bug5251 comment 'foobar'| 2468select count(*) from mysql.proc 2469where db='test' and name='bug5251' and created = @c1| 2470count(*) 24711 2472drop procedure bug5251| 2473drop procedure if exists bug5251| 2474create procedure bug5251() 2475checksum table t1| 2476call bug5251()| 2477Table Checksum 2478test.t1 0 2479call bug5251()| 2480Table Checksum 2481test.t1 0 2482drop procedure bug5251| 2483drop procedure if exists bug5287| 2484create procedure bug5287(param1 int) 2485label1: 2486begin 2487declare c cursor for select 5; 2488loop 2489if param1 >= 0 then 2490leave label1; 2491end if; 2492end loop; 2493end| 2494call bug5287(1)| 2495drop procedure bug5287| 2496drop procedure if exists bug5307| 2497create procedure bug5307() 2498begin 2499end; set @x = 3| 2500call bug5307()| 2501select @x| 2502@x 25033 2504drop procedure bug5307| 2505drop procedure if exists bug5258| 2506create procedure bug5258() 2507begin 2508end| 2509drop procedure if exists bug5258_aux| 2510create procedure bug5258_aux() 2511begin 2512declare c, m char(19); 2513select created,modified into c,m from mysql.proc where name = 'bug5258'; 2514if c = m then 2515select 'Ok'; 2516else 2517select c, m; 2518end if; 2519end| 2520call bug5258_aux()| 2521Ok 2522Ok 2523drop procedure bug5258| 2524drop procedure bug5258_aux| 2525drop function if exists bug4487| 2526create function bug4487() returns char 2527begin 2528declare v char; 2529return v; 2530end| 2531select bug4487()| 2532bug4487() 2533NULL 2534drop function bug4487| 2535drop procedure if exists bug4941| 2536drop procedure if exists bug4941| 2537create procedure bug4941(out x int) 2538begin 2539declare c cursor for select i from t2 limit 1; 2540open c; 2541fetch c into x; 2542close c; 2543end| 2544insert into t2 values (null, null, null)| 2545set @x = 42| 2546call bug4941(@x)| 2547select @x| 2548@x 2549NULL 2550delete from t1| 2551drop procedure bug4941| 2552drop procedure if exists bug4905| 2553create table t3 (s1 int,primary key (s1))| 2554drop procedure if exists bug4905| 2555create procedure bug4905() 2556begin 2557declare v int; 2558declare continue handler for sqlstate '23000' set v = 5; 2559insert into t3 values (1); 2560end| 2561call bug4905()| 2562select row_count()| 2563row_count() 25641 2565call bug4905()| 2566select row_count()| 2567row_count() 25680 2569call bug4905()| 2570select row_count()| 2571row_count() 25720 2573select * from t3| 2574s1 25751 2576drop procedure bug4905| 2577drop table t3| 2578drop procedure if exists bug6029| 2579drop procedure if exists bug6029| 2580create procedure bug6029() 2581begin 2582declare exit handler for 1136 select '1136'; 2583declare exit handler for sqlstate '23000' select 'sqlstate 23000'; 2584declare continue handler for sqlexception select 'sqlexception'; 2585insert into t3 values (1); 2586insert into t3 values (1,2); 2587end| 2588create table t3 (s1 int, primary key (s1))| 2589insert into t3 values (1)| 2590call bug6029()| 2591sqlstate 23000 2592sqlstate 23000 2593delete from t3| 2594call bug6029()| 25951136 25961136 2597drop procedure bug6029| 2598drop table t3| 2599drop procedure if exists bug8540| 2600create procedure bug8540() 2601begin 2602declare x int default 1; 2603select x as y, x+0 as z; 2604end| 2605call bug8540()| 2606y z 26071 1 2608drop procedure bug8540| 2609create table t3 (s1 int)| 2610drop procedure if exists bug6642| 2611create procedure bug6642() 2612select abs(count(s1)) from t3| 2613call bug6642()| 2614abs(count(s1)) 26150 2616call bug6642()| 2617abs(count(s1)) 26180 2619drop procedure bug6642| 2620insert into t3 values (0),(1)| 2621drop procedure if exists bug7013| 2622create procedure bug7013() 2623select s1,count(s1) from t3 group by s1 with rollup| 2624call bug7013()| 2625s1 count(s1) 26260 1 26271 1 2628NULL 2 2629call bug7013()| 2630s1 count(s1) 26310 1 26321 1 2633NULL 2 2634drop procedure bug7013| 2635drop table if exists t4| 2636create table t4 ( 2637a mediumint(8) unsigned not null auto_increment, 2638b smallint(5) unsigned not null, 2639c char(32) not null, 2640primary key (a) 2641) engine=myisam default charset=latin1| 2642insert into t4 values (1, 2, 'oneword')| 2643insert into t4 values (2, 2, 'anotherword')| 2644drop procedure if exists bug7743| 2645create procedure bug7743 ( searchstring char(28) ) 2646begin 2647declare var mediumint(8) unsigned; 2648select a into var from t4 where b = 2 and c = binary searchstring limit 1; 2649select var; 2650end| 2651call bug7743("oneword")| 2652var 26531 2654call bug7743("OneWord")| 2655var 2656NULL 2657Warnings: 2658Warning 1329 No data - zero rows fetched, selected, or processed 2659call bug7743("anotherword")| 2660var 26612 2662call bug7743("AnotherWord")| 2663var 2664NULL 2665Warnings: 2666Warning 1329 No data - zero rows fetched, selected, or processed 2667drop procedure bug7743| 2668drop table t4| 2669delete from t3| 2670insert into t3 values(1)| 2671drop procedure if exists bug7992_1| 2672Warnings: 2673Note 1305 PROCEDURE test.bug7992_1 does not exist 2674drop procedure if exists bug7992_2| 2675Warnings: 2676Note 1305 PROCEDURE test.bug7992_2 does not exist 2677create procedure bug7992_1() 2678begin 2679declare i int; 2680select max(s1)+1 into i from t3; 2681end| 2682create procedure bug7992_2() 2683insert into t3 (s1) select max(t4.s1)+1 from t3 as t4| 2684call bug7992_1()| 2685call bug7992_1()| 2686call bug7992_2()| 2687call bug7992_2()| 2688drop procedure bug7992_1| 2689drop procedure bug7992_2| 2690drop table t3| 2691create table t3 ( userid bigint(20) not null default 0 )| 2692drop procedure if exists bug8116| 2693create procedure bug8116(in _userid int) 2694select * from t3 where userid = _userid| 2695call bug8116(42)| 2696userid 2697call bug8116(42)| 2698userid 2699drop procedure bug8116| 2700drop table t3| 2701drop procedure if exists bug6857| 2702create procedure bug6857() 2703begin 2704declare t0, t1 int; 2705declare plus bool default 0; 2706set t0 = unix_timestamp(); 2707select sleep(1.1); 2708set t1 = unix_timestamp(); 2709if t1 > t0 then 2710set plus = 1; 2711end if; 2712select plus; 2713end| 2714call bug6857()| 2715sleep(1.1) 27160 2717plus 27181 2719drop procedure bug6857| 2720drop procedure if exists bug8757| 2721create procedure bug8757() 2722begin 2723declare x int; 2724declare c1 cursor for select data from t1 limit 1; 2725begin 2726declare y int; 2727declare c2 cursor for select i from t2 limit 1; 2728open c2; 2729fetch c2 into y; 2730close c2; 2731select 2,y; 2732end; 2733open c1; 2734fetch c1 into x; 2735close c1; 2736select 1,x; 2737end| 2738delete from t1| 2739delete from t2| 2740insert into t1 values ("x", 1)| 2741insert into t2 values ("y", 2, 0.0)| 2742call bug8757()| 27432 y 27442 2 27451 x 27461 1 2747delete from t1| 2748delete from t2| 2749drop procedure bug8757| 2750drop procedure if exists bug8762| 2751drop procedure if exists bug8762; create procedure bug8762() begin end| 2752drop procedure if exists bug8762; create procedure bug8762() begin end| 2753drop procedure bug8762| 2754drop function if exists bug5240| 2755create function bug5240 () returns int 2756begin 2757declare x int; 2758declare c cursor for select data from t1 limit 1; 2759open c; 2760fetch c into x; 2761close c; 2762return x; 2763end| 2764delete from t1| 2765insert into t1 values ("answer", 42)| 2766select id, bug5240() from t1| 2767id bug5240() 2768answer 42 2769drop function bug5240| 2770drop procedure if exists p1| 2771create table t3(id int)| 2772insert into t3 values(1)| 2773create procedure bug7992() 2774begin 2775declare i int; 2776select max(id)+1 into i from t3; 2777end| 2778call bug7992()| 2779call bug7992()| 2780drop procedure bug7992| 2781drop table t3| 2782create table t3 ( 2783lpitnumber int(11) default null, 2784lrecordtype int(11) default null 2785)| 2786create table t4 ( 2787lbsiid int(11) not null default '0', 2788ltradingmodeid int(11) not null default '0', 2789ltradingareaid int(11) not null default '0', 2790csellingprice decimal(19,4) default null, 2791primary key (lbsiid,ltradingmodeid,ltradingareaid) 2792)| 2793create table t5 ( 2794lbsiid int(11) not null default '0', 2795ltradingareaid int(11) not null default '0', 2796primary key (lbsiid,ltradingareaid) 2797)| 2798drop procedure if exists bug8849| 2799create procedure bug8849() 2800begin 2801insert into t5 2802( 2803t5.lbsiid, 2804t5.ltradingareaid 2805) 2806select distinct t3.lpitnumber, t4.ltradingareaid 2807from 2808t4 join t3 on 2809t3.lpitnumber = t4.lbsiid 2810and t3.lrecordtype = 1 2811left join t4 as price01 on 2812price01.lbsiid = t4.lbsiid and 2813price01.ltradingmodeid = 1 and 2814t4.ltradingareaid = price01.ltradingareaid; 2815end| 2816call bug8849()| 2817call bug8849()| 2818call bug8849()| 2819drop procedure bug8849| 2820drop tables t3,t4,t5| 2821drop procedure if exists bug8937| 2822create procedure bug8937() 2823begin 2824declare s,x,y,z int; 2825declare a float; 2826select sum(data),avg(data),min(data),max(data) into s,x,y,z from t1; 2827select s,x,y,z; 2828select avg(data) into a from t1; 2829select a; 2830end| 2831delete from t1| 2832insert into t1 (data) values (1), (2), (3), (4), (6)| 2833call bug8937()| 2834s x y z 283516 3 1 6 2836a 28373.2 2838drop procedure bug8937| 2839delete from t1| 2840drop procedure if exists bug6900| 2841drop procedure if exists bug9074| 2842drop procedure if exists bug6900_9074| 2843create table t3 (w char unique, x char)| 2844insert into t3 values ('a', 'b')| 2845create procedure bug6900() 2846begin 2847declare exit handler for sqlexception select '1'; 2848begin 2849declare exit handler for sqlexception select '2'; 2850insert into t3 values ('x', 'y', 'z'); 2851end; 2852end| 2853create procedure bug9074() 2854begin 2855declare x1, x2, x3, x4, x5, x6 int default 0; 2856begin 2857declare continue handler for sqlstate '23000' set x5 = 1; 2858insert into t3 values ('a', 'b'); 2859set x6 = 1; 2860end; 2861begin1_label: 2862begin 2863declare continue handler for sqlstate '23000' set x1 = 1; 2864insert into t3 values ('a', 'b'); 2865set x2 = 1; 2866begin2_label: 2867begin 2868declare exit handler for sqlstate '23000' set x3 = 1; 2869set x4= 1; 2870insert into t3 values ('a','b'); 2871set x4= 0; 2872end begin2_label; 2873end begin1_label; 2874select x1, x2, x3, x4, x5, x6; 2875end| 2876create procedure bug6900_9074(z int) 2877begin 2878declare exit handler for sqlstate '23000' select '23000'; 2879begin 2880declare exit handler for sqlexception select 'sqlexception'; 2881if z = 1 then 2882insert into t3 values ('a', 'b'); 2883else 2884insert into t3 values ('x', 'y', 'z'); 2885end if; 2886end; 2887end| 2888call bug6900()| 28892 28902 2891call bug9074()| 2892x1 x2 x3 x4 x5 x6 28931 1 1 1 1 1 2894call bug6900_9074(0)| 2895sqlexception 2896sqlexception 2897call bug6900_9074(1)| 2898sqlexception 2899sqlexception 2900drop procedure bug6900| 2901drop procedure bug9074| 2902drop procedure bug6900_9074| 2903drop table t3| 2904drop procedure if exists avg| 2905create procedure avg () 2906begin 2907end| 2908call avg ()| 2909drop procedure avg| 2910drop procedure if exists bug6129| 2911set @old_mode= @@sql_mode; 2912set @@sql_mode= "ERROR_FOR_DIVISION_BY_ZERO"; 2913create procedure bug6129() 2914select @@sql_mode| 2915call bug6129()| 2916@@sql_mode 2917ERROR_FOR_DIVISION_BY_ZERO 2918set @@sql_mode= "NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO"| 2919Warnings: 2920Warning 1681 'ERROR_FOR_DIVISION_BY_ZERO' is deprecated and will be removed in a future release. 2921Warning 1681 'NO_ZERO_DATE' is deprecated and will be removed in a future release. 2922Warning 1681 'NO_ZERO_IN_DATE' is deprecated and will be removed in a future release. 2923call bug6129()| 2924@@sql_mode 2925ERROR_FOR_DIVISION_BY_ZERO 2926set @@sql_mode= "NO_ZERO_IN_DATE"| 2927Warnings: 2928Warning 1681 'NO_ZERO_IN_DATE' is deprecated and will be removed in a future release. 2929call bug6129()| 2930@@sql_mode 2931ERROR_FOR_DIVISION_BY_ZERO 2932set @@sql_mode=@old_mode; 2933drop procedure bug6129| 2934drop procedure if exists bug9856| 2935create procedure bug9856() 2936begin 2937declare v int; 2938declare c cursor for select data from t1; 2939declare exit handler for sqlexception, not found select '16'; 2940open c; 2941fetch c into v; 2942select v; 2943end| 2944delete from t1| 2945call bug9856()| 294616 294716 2948call bug9856()| 294916 295016 2951drop procedure bug9856| 2952drop procedure if exists bug9674_1| 2953drop procedure if exists bug9674_2| 2954create procedure bug9674_1(out arg int) 2955begin 2956declare temp_in1 int default 0; 2957declare temp_fl1 int default 0; 2958set temp_in1 = 100; 2959set temp_fl1 = temp_in1/10; 2960set arg = temp_fl1; 2961end| 2962create procedure bug9674_2() 2963begin 2964declare v int default 100; 2965select v/10; 2966end| 2967call bug9674_1(@sptmp)| 2968call bug9674_1(@sptmp)| 2969select @sptmp| 2970@sptmp 297110 2972call bug9674_2()| 2973v/10 297410.0000 2975call bug9674_2()| 2976v/10 297710.0000 2978drop procedure bug9674_1| 2979drop procedure bug9674_2| 2980drop procedure if exists bug9598_1| 2981drop procedure if exists bug9598_2| 2982create procedure bug9598_1(in var_1 char(16), 2983out var_2 integer, out var_3 integer) 2984begin 2985set var_2 = 50; 2986set var_3 = 60; 2987end| 2988create procedure bug9598_2(in v1 char(16), 2989in v2 integer, 2990in v3 integer, 2991in v4 integer, 2992in v5 integer) 2993begin 2994select v1,v2,v3,v4,v5; 2995call bug9598_1(v1,@tmp1,@tmp2); 2996select v1,v2,v3,v4,v5; 2997end| 2998call bug9598_2('Test',2,3,4,5)| 2999v1 v2 v3 v4 v5 3000Test 2 3 4 5 3001v1 v2 v3 v4 v5 3002Test 2 3 4 5 3003select @tmp1, @tmp2| 3004@tmp1 @tmp2 300550 60 3006drop procedure bug9598_1| 3007drop procedure bug9598_2| 3008drop procedure if exists bug9902| 3009create function bug9902() returns int(11) 3010begin 3011set @x = @x + 1; 3012return @x; 3013end| 3014set @qcs1 = @@query_cache_size| 3015set global query_cache_size = 102400| 3016set @x = 1| 3017insert into t1 values ("qc", 42)| 3018select bug9902() from t1| 3019bug9902() 30202 3021select bug9902() from t1| 3022bug9902() 30233 3024select @x| 3025@x 30263 3027set global query_cache_size = @qcs1| 3028delete from t1| 3029drop function bug9902| 3030drop function if exists bug9102| 3031create function bug9102() returns blob return 'a'| 3032select bug9102()| 3033bug9102() 3034a 3035drop function bug9102| 3036drop function if exists bug7648| 3037create function bug7648() returns bit(8) return 'a'| 3038select bug7648()| 3039bug7648() 3040a 3041drop function bug7648| 3042drop function if exists bug9775| 3043create function bug9775(v1 char(1)) returns enum('a','b') return v1| 3044select bug9775('a'),bug9775('b'),bug9775('c')| 3045bug9775('a') bug9775('b') bug9775('c') 3046a b 3047Warnings: 3048Warning 1265 Data truncated for column 'bug9775('c')' at row 1 3049drop function bug9775| 3050create function bug9775(v1 int) returns enum('a','b') return v1| 3051select bug9775(1),bug9775(2),bug9775(3)| 3052bug9775(1) bug9775(2) bug9775(3) 3053a b 3054Warnings: 3055Warning 1265 Data truncated for column 'bug9775(3)' at row 1 3056drop function bug9775| 3057create function bug9775(v1 char(1)) returns set('a','b') return v1| 3058select bug9775('a'),bug9775('b'),bug9775('a,b'),bug9775('c')| 3059bug9775('a') bug9775('b') bug9775('a,b') bug9775('c') 3060a b a 3061Warnings: 3062Warning 1265 Data truncated for column 'v1' at row 1 3063Warning 1265 Data truncated for column 'bug9775('c')' at row 1 3064drop function bug9775| 3065create function bug9775(v1 int) returns set('a','b') return v1| 3066select bug9775(1),bug9775(2),bug9775(3),bug9775(4)| 3067bug9775(1) bug9775(2) bug9775(3) bug9775(4) 3068a b a,b 3069Warnings: 3070Warning 1265 Data truncated for column 'bug9775(4)' at row 1 3071drop function bug9775| 3072drop function if exists bug8861| 3073create function bug8861(v1 int) returns year return v1| 3074select bug8861(05)| 3075bug8861(05) 30762005 3077set @x = bug8861(05)| 3078select @x| 3079@x 30802005 3081drop function bug8861| 3082drop procedure if exists bug9004_1| 3083drop procedure if exists bug9004_2| 3084create procedure bug9004_1(x char(16)) 3085begin 3086insert into t1 values (x, 42); 3087insert into t1 values (x, 17); 3088end| 3089create procedure bug9004_2(x char(16)) 3090call bug9004_1(x)| 3091call bug9004_1('12345678901234567')| 3092Warnings: 3093Warning 1265 Data truncated for column 'x' at row 1 3094call bug9004_2('12345678901234567890')| 3095Warnings: 3096Warning 1265 Data truncated for column 'x' at row 1 3097delete from t1| 3098drop procedure bug9004_1| 3099drop procedure bug9004_2| 3100drop procedure if exists bug7293| 3101insert into t1 values ('secret', 0)| 3102create procedure bug7293(p1 varchar(100)) 3103begin 3104if exists (select id from t1 where soundex(p1)=soundex(id)) then 3105select 'yes'; 3106end if; 3107end;| 3108call bug7293('secret')| 3109yes 3110yes 3111call bug7293 ('secrete')| 3112yes 3113yes 3114drop procedure bug7293| 3115delete from t1| 3116drop procedure if exists bug9841| 3117drop view if exists v1| 3118create view v1 as select * from t1, t2 where id = s| 3119create procedure bug9841 () 3120update v1 set data = 10| 3121call bug9841()| 3122drop view v1| 3123drop procedure bug9841| 3124drop procedure if exists bug5963| 3125create procedure bug5963_1 () begin declare v int; set v = (select s1 from t3); select v; end;| 3126create table t3 (s1 int)| 3127insert into t3 values (5)| 3128call bug5963_1()| 3129v 31305 3131call bug5963_1()| 3132v 31335 3134drop procedure bug5963_1| 3135drop table t3| 3136create procedure bug5963_2 (cfk_value int) 3137begin 3138if cfk_value in (select cpk from t3) then 3139set @x = 5; 3140end if; 3141end; 3142| 3143create table t3 (cpk int)| 3144insert into t3 values (1)| 3145call bug5963_2(1)| 3146call bug5963_2(1)| 3147drop procedure bug5963_2| 3148drop table t3| 3149drop function if exists bug9559| 3150create function bug9559() 3151returns int 3152begin 3153set @y = -6/2; 3154return @y; 3155end| 3156select bug9559()| 3157bug9559() 3158-3 3159drop function bug9559| 3160drop procedure if exists bug10961| 3161create procedure bug10961() 3162begin 3163declare v char; 3164declare x int; 3165declare c cursor for select * from dual; 3166declare continue handler for sqlexception select x; 3167set x = 1; 3168open c; 3169set x = 2; 3170fetch c into v; 3171set x = 3; 3172close c; 3173end| 3174call bug10961()| 3175x 31761 3177x 31782 3179x 31803 3181call bug10961()| 3182x 31831 3184x 31852 3186x 31873 3188drop procedure bug10961| 3189DROP PROCEDURE IF EXISTS bug6866| 3190DROP VIEW IF EXISTS tv| 3191Warnings: 3192Note 1051 Unknown table 'test.tv' 3193DROP TABLE IF EXISTS tt1,tt2,tt3| 3194Warnings: 3195Note 1051 Unknown table 'test.tt1' 3196Note 1051 Unknown table 'test.tt2' 3197Note 1051 Unknown table 'test.tt3' 3198CREATE TABLE tt1 (a1 int, a2 int, a3 int, data varchar(10))| 3199CREATE TABLE tt2 (a2 int, data2 varchar(10))| 3200CREATE TABLE tt3 (a3 int, data3 varchar(10))| 3201INSERT INTO tt1 VALUES (1, 1, 4, 'xx')| 3202INSERT INTO tt2 VALUES (1, 'a')| 3203INSERT INTO tt2 VALUES (2, 'b')| 3204INSERT INTO tt2 VALUES (3, 'c')| 3205INSERT INTO tt3 VALUES (4, 'd')| 3206INSERT INTO tt3 VALUES (5, 'e')| 3207INSERT INTO tt3 VALUES (6, 'f')| 3208CREATE VIEW tv AS 3209SELECT tt1.*, tt2.data2, tt3.data3 3210FROM tt1 INNER JOIN tt2 ON tt1.a2 = tt2.a2 3211LEFT JOIN tt3 ON tt1.a3 = tt3.a3 3212ORDER BY tt1.a1, tt2.a2, tt3.a3| 3213CREATE PROCEDURE bug6866 (_a1 int) 3214BEGIN 3215SELECT * FROM tv WHERE a1 = _a1; 3216END| 3217CALL bug6866(1)| 3218a1 a2 a3 data data2 data3 32191 1 4 xx a d 3220CALL bug6866(1)| 3221a1 a2 a3 data data2 data3 32221 1 4 xx a d 3223CALL bug6866(1)| 3224a1 a2 a3 data data2 data3 32251 1 4 xx a d 3226DROP PROCEDURE bug6866; 3227DROP VIEW tv| 3228DROP TABLE tt1, tt2, tt3| 3229DROP PROCEDURE IF EXISTS bug10136| 3230create table t3 ( name char(5) not null primary key, val float not null)| 3231insert into t3 values ('aaaaa', 1), ('bbbbb', 2), ('ccccc', 3)| 3232create procedure bug10136() 3233begin 3234declare done int default 3; 3235repeat 3236select * from t3; 3237set done = done - 1; 3238until done <= 0 end repeat; 3239end| 3240call bug10136()| 3241name val 3242aaaaa 1 3243bbbbb 2 3244ccccc 3 3245name val 3246aaaaa 1 3247bbbbb 2 3248ccccc 3 3249name val 3250aaaaa 1 3251bbbbb 2 3252ccccc 3 3253call bug10136()| 3254name val 3255aaaaa 1 3256bbbbb 2 3257ccccc 3 3258name val 3259aaaaa 1 3260bbbbb 2 3261ccccc 3 3262name val 3263aaaaa 1 3264bbbbb 2 3265ccccc 3 3266call bug10136()| 3267name val 3268aaaaa 1 3269bbbbb 2 3270ccccc 3 3271name val 3272aaaaa 1 3273bbbbb 2 3274ccccc 3 3275name val 3276aaaaa 1 3277bbbbb 2 3278ccccc 3 3279drop procedure bug10136| 3280drop table t3| 3281drop procedure if exists bug11529| 3282create procedure bug11529() 3283begin 3284declare c cursor for select id, data from t1 where data in (10,13); 3285open c; 3286begin 3287declare vid char(16); 3288declare vdata int; 3289declare exit handler for not found begin end; 3290while true do 3291fetch c into vid, vdata; 3292end while; 3293end; 3294close c; 3295end| 3296insert into t1 values 3297('Name1', 10), 3298('Name2', 11), 3299('Name3', 12), 3300('Name4', 13), 3301('Name5', 14)| 3302call bug11529()| 3303call bug11529()| 3304delete from t1| 3305drop procedure bug11529| 3306set character set utf8| 3307drop procedure if exists bug6063| 3308drop procedure if exists bug7088_1| 3309drop procedure if exists bug7088_2| 3310create procedure bug6063() 3311begin 3312lâbel: begin end; 3313label: begin end; 3314label1: begin end; 3315end| 3316create procedure bug7088_1() 3317label1: begin end label1| 3318create procedure bug7088_2() 3319läbel1: begin end| 3320call bug6063()| 3321call bug7088_1()| 3322call bug7088_2()| 3323set character set default| 3324show create procedure bug6063| 3325Procedure sql_mode Create Procedure character_set_client collation_connection Database Collation 3326bug6063 CREATE DEFINER=`root`@`localhost` PROCEDURE `bug6063`() 3327begin 3328l�bel: begin end; 3329label: begin end; 3330label1: begin end; 3331end utf8 latin1_swedish_ci latin1_swedish_ci 3332show create procedure bug7088_1| 3333Procedure sql_mode Create Procedure character_set_client collation_connection Database Collation 3334bug7088_1 CREATE DEFINER=`root`@`localhost` PROCEDURE `bug7088_1`() 3335label1: begin end label1 utf8 latin1_swedish_ci latin1_swedish_ci 3336show create procedure bug7088_2| 3337Procedure sql_mode Create Procedure character_set_client collation_connection Database Collation 3338bug7088_2 CREATE DEFINER=`root`@`localhost` PROCEDURE `bug7088_2`() 3339l�bel1: begin end utf8 latin1_swedish_ci latin1_swedish_ci 3340drop procedure bug6063| 3341drop procedure bug7088_1| 3342drop procedure bug7088_2| 3343drop procedure if exists bug9565_sub| 3344drop procedure if exists bug9565| 3345create procedure bug9565_sub() 3346begin 3347select * from t1; 3348end| 3349create procedure bug9565() 3350begin 3351insert into t1 values ("one", 1); 3352call bug9565_sub(); 3353end| 3354call bug9565()| 3355id data 3356one 1 3357delete from t1| 3358drop procedure bug9565_sub| 3359drop procedure bug9565| 3360drop procedure if exists bug9538| 3361create procedure bug9538() 3362set @@sort_buffer_size = 1000000| 3363set @x = @@sort_buffer_size| 3364set @@sort_buffer_size = 2000000| 3365select @@sort_buffer_size| 3366@@sort_buffer_size 33672000000 3368call bug9538()| 3369select @@sort_buffer_size| 3370@@sort_buffer_size 33711000000 3372set @@sort_buffer_size = @x| 3373drop procedure bug9538| 3374drop procedure if exists bug8692| 3375create table t3 (c1 varchar(5), c2 char(5), c3 enum('one','two'), c4 text, c5 blob, c6 char(5), c7 varchar(5))| 3376insert into t3 values ('', '', '', '', '', '', NULL)| 3377Warnings: 3378Warning 1265 Data truncated for column 'c3' at row 1 3379create procedure bug8692() 3380begin 3381declare v1 VARCHAR(10); 3382declare v2 VARCHAR(10); 3383declare v3 VARCHAR(10); 3384declare v4 VARCHAR(10); 3385declare v5 VARCHAR(10); 3386declare v6 VARCHAR(10); 3387declare v7 VARCHAR(10); 3388declare c8692 cursor for select c1,c2,c3,c4,c5,c6,c7 from t3; 3389open c8692; 3390fetch c8692 into v1,v2,v3,v4,v5,v6,v7; 3391select v1, v2, v3, v4, v5, v6, v7; 3392end| 3393call bug8692()| 3394v1 v2 v3 v4 v5 v6 v7 3395 NULL 3396drop procedure bug8692| 3397drop table t3| 3398drop function if exists bug10055| 3399create function bug10055(v char(255)) returns char(255) return lower(v)| 3400select t.column_name, bug10055(t.column_name) 3401from information_schema.columns as t 3402where t.table_schema = 'test' and t.table_name = 't1'| 3403column_name bug10055(t.column_name) 3404id id 3405data data 3406drop function bug10055| 3407drop procedure if exists bug12297| 3408create procedure bug12297(lim int) 3409begin 3410set @x = 0; 3411repeat 3412insert into t1(id,data) 3413values('aa', @x); 3414set @x = @x + 1; 3415until @x >= lim 3416end repeat; 3417end| 3418call bug12297(10)| 3419drop procedure bug12297| 3420drop function if exists f_bug11247| 3421drop procedure if exists p_bug11247| 3422create function f_bug11247(param int) 3423returns int 3424return param + 1| 3425create procedure p_bug11247(lim int) 3426begin 3427declare v int default 0; 3428while v < lim do 3429set v= f_bug11247(v); 3430end while; 3431end| 3432call p_bug11247(10)| 3433drop function f_bug11247| 3434drop procedure p_bug11247| 3435drop procedure if exists bug12168| 3436drop table if exists t3, t4| 3437create table t3 (a int)| 3438insert into t3 values (1),(2),(3),(4)| 3439create table t4 (a int)| 3440create procedure bug12168(arg1 char(1)) 3441begin 3442declare b, c integer; 3443if arg1 = 'a' then 3444begin 3445declare c1 cursor for select a from t3 where a % 2; 3446declare continue handler for not found set b = 1; 3447set b = 0; 3448open c1; 3449c1_repeat: repeat 3450fetch c1 into c; 3451if (b = 1) then 3452leave c1_repeat; 3453end if; 3454insert into t4 values (c); 3455until b = 1 3456end repeat; 3457end; 3458end if; 3459if arg1 = 'b' then 3460begin 3461declare c2 cursor for select a from t3 where not a % 2; 3462declare continue handler for not found set b = 1; 3463set b = 0; 3464open c2; 3465c2_repeat: repeat 3466fetch c2 into c; 3467if (b = 1) then 3468leave c2_repeat; 3469end if; 3470insert into t4 values (c); 3471until b = 1 3472end repeat; 3473end; 3474end if; 3475end| 3476call bug12168('a')| 3477select * from t4| 3478a 34791 34803 3481truncate t4| 3482call bug12168('b')| 3483select * from t4| 3484a 34852 34864 3487truncate t4| 3488call bug12168('a')| 3489select * from t4| 3490a 34911 34923 3493truncate t4| 3494call bug12168('b')| 3495select * from t4| 3496a 34972 34984 3499truncate t4| 3500drop table t3, t4| 3501drop procedure if exists bug12168| 3502drop table if exists t3| 3503drop procedure if exists bug11333| 3504create table t3 (c1 char(128))| 3505insert into t3 values 3506('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA')| 3507create procedure bug11333(i int) 3508begin 3509declare tmp varchar(128); 3510set @x = 0; 3511repeat 3512select c1 into tmp from t3 3513where c1 = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'; 3514set @x = @x + 1; 3515until @x >= i 3516end repeat; 3517end| 3518call bug11333(10)| 3519drop procedure bug11333| 3520drop table t3| 3521drop function if exists bug9048| 3522create function bug9048(f1 char binary) returns char 3523begin 3524set f1= concat( 'hello', f1 ); 3525return f1; 3526end| 3527drop function bug9048| 3528create function bug9048(f1 char binary) returns char binary 3529begin 3530set f1= concat( 'hello', f1 ); 3531return f1; 3532end| 3533ERROR 42000: This version of MySQL doesn't yet support 'return value collation' 3534drop procedure if exists bug12849_1| 3535create procedure bug12849_1(inout x char) select x into x| 3536set @var='a'| 3537call bug12849_1(@var)| 3538select @var| 3539@var 3540a 3541drop procedure bug12849_1| 3542drop procedure if exists bug12849_2| 3543create procedure bug12849_2(inout foo varchar(15)) 3544begin 3545select concat(foo, foo) INTO foo; 3546end| 3547set @var='abcd'| 3548call bug12849_2(@var)| 3549select @var| 3550@var 3551abcdabcd 3552drop procedure bug12849_2| 3553drop procedure if exists bug131333| 3554drop function if exists bug131333| 3555create procedure bug131333() 3556begin 3557begin 3558declare a int; 3559select a; 3560set a = 1; 3561select a; 3562end; 3563begin 3564declare b int; 3565select b; 3566end; 3567end| 3568create function bug131333() 3569returns int 3570begin 3571begin 3572declare a int; 3573set a = 1; 3574end; 3575begin 3576declare b int; 3577return b; 3578end; 3579end| 3580call bug131333()| 3581a 3582NULL 3583a 35841 3585b 3586NULL 3587select bug131333()| 3588bug131333() 3589NULL 3590drop procedure bug131333| 3591drop function bug131333| 3592drop function if exists bug12379| 3593drop procedure if exists bug12379_1| 3594drop procedure if exists bug12379_2| 3595drop procedure if exists bug12379_3| 3596drop table if exists t3| 3597create table t3 (c1 char(1) primary key not null)| 3598create function bug12379() 3599returns integer 3600begin 3601insert into t3 values('X'); 3602insert into t3 values('X'); 3603return 0; 3604end| 3605create procedure bug12379_1() 3606begin 3607declare exit handler for sqlexception select 42; 3608select bug12379(); 3609END| 3610create procedure bug12379_2() 3611begin 3612declare exit handler for sqlexception begin end; 3613select bug12379(); 3614end| 3615create procedure bug12379_3() 3616begin 3617select bug12379(); 3618end| 3619select bug12379()| 3620ERROR 23000: Duplicate entry 'X' for key 'PRIMARY' 3621select 1| 36221 36231 3624call bug12379_1()| 3625bug12379() 362642 362742 3628select 2| 36292 36302 3631call bug12379_2()| 3632bug12379() 3633select 3| 36343 36353 3636call bug12379_3()| 3637ERROR 23000: Duplicate entry 'X' for key 'PRIMARY' 3638select 4| 36394 36404 3641drop function bug12379| 3642drop procedure bug12379_1| 3643drop procedure bug12379_2| 3644drop procedure bug12379_3| 3645drop table t3| 3646drop procedure if exists bug13124| 3647create procedure bug13124() 3648begin 3649declare y integer; 3650set @x=y; 3651end| 3652call bug13124()| 3653drop procedure bug13124| 3654drop procedure if exists bug12979_1| 3655create procedure bug12979_1(inout d decimal(5)) set d = d / 2| 3656set @bug12979_user_var = NULL| 3657call bug12979_1(@bug12979_user_var)| 3658drop procedure bug12979_1| 3659drop procedure if exists bug12979_2| 3660create procedure bug12979_2() 3661begin 3662declare internal_var decimal(5); 3663set internal_var= internal_var / 2; 3664select internal_var; 3665end| 3666call bug12979_2()| 3667internal_var 3668NULL 3669drop procedure bug12979_2| 3670drop table if exists t3| 3671drop procedure if exists bug6127| 3672create table t3 (s1 int unique)| 3673set @sm=@@sql_mode| 3674set sql_mode='traditional'| 3675create procedure bug6127() 3676begin 3677declare continue handler for sqlstate '23000' 3678 begin 3679declare continue handler for sqlstate '22003' 3680 insert into t3 values (0); 3681insert into t3 values (1000000000000000); 3682end; 3683insert into t3 values (1); 3684insert into t3 values (1); 3685end| 3686call bug6127()| 3687select * from t3| 3688s1 36890 36901 3691call bug6127()| 3692ERROR 23000: Duplicate entry '0' for key 's1' 3693select * from t3| 3694s1 36950 36961 3697set sql_mode=@sm| 3698drop table t3| 3699drop procedure bug6127| 3700drop procedure if exists bug12589_1| 3701drop procedure if exists bug12589_2| 3702drop procedure if exists bug12589_3| 3703create procedure bug12589_1() 3704begin 3705declare spv1 decimal(3,3); 3706set spv1= 123.456; 3707set spv1 = 'test'; 3708create temporary table tm1 as select spv1; 3709show create table tm1; 3710drop temporary table tm1; 3711end| 3712create procedure bug12589_2() 3713begin 3714declare spv1 decimal(6,3); 3715set spv1= 123.456; 3716create temporary table tm1 as select spv1; 3717show create table tm1; 3718drop temporary table tm1; 3719end| 3720create procedure bug12589_3() 3721begin 3722declare spv1 decimal(6,3); 3723set spv1= -123.456; 3724create temporary table tm1 as select spv1; 3725show create table tm1; 3726drop temporary table tm1; 3727end| 3728call bug12589_1()| 3729Table Create Table 3730tm1 CREATE TEMPORARY TABLE `tm1` ( 3731 `spv1` decimal(3,3) DEFAULT NULL 3732) ENGINE=MyISAM DEFAULT CHARSET=latin1 3733call bug12589_2()| 3734Table Create Table 3735tm1 CREATE TEMPORARY TABLE `tm1` ( 3736 `spv1` decimal(6,3) DEFAULT NULL 3737) ENGINE=MyISAM DEFAULT CHARSET=latin1 3738call bug12589_3()| 3739Table Create Table 3740tm1 CREATE TEMPORARY TABLE `tm1` ( 3741 `spv1` decimal(6,3) DEFAULT NULL 3742) ENGINE=MyISAM DEFAULT CHARSET=latin1 3743drop procedure bug12589_1| 3744drop procedure bug12589_2| 3745drop procedure bug12589_3| 3746drop table if exists t3| 3747drop procedure if exists bug7049_1| 3748drop procedure if exists bug7049_2| 3749drop procedure if exists bug7049_3| 3750drop procedure if exists bug7049_4| 3751drop function if exists bug7049_1| 3752drop function if exists bug7049_2| 3753create table t3 ( x int unique )| 3754create procedure bug7049_1() 3755begin 3756insert into t3 values (42); 3757insert into t3 values (42); 3758end| 3759create procedure bug7049_2() 3760begin 3761declare exit handler for sqlexception 3762select 'Caught it' as 'Result'; 3763call bug7049_1(); 3764select 'Missed it' as 'Result'; 3765end| 3766create procedure bug7049_3() 3767call bug7049_1()| 3768create procedure bug7049_4() 3769begin 3770declare exit handler for sqlexception 3771select 'Caught it' as 'Result'; 3772call bug7049_3(); 3773select 'Missed it' as 'Result'; 3774end| 3775create function bug7049_1() 3776returns int 3777begin 3778insert into t3 values (42); 3779insert into t3 values (42); 3780return 42; 3781end| 3782create function bug7049_2() 3783returns int 3784begin 3785declare x int default 0; 3786declare continue handler for sqlexception 3787set x = 1; 3788set x = bug7049_1(); 3789return x; 3790end| 3791call bug7049_2()| 3792Result 3793Caught it 3794select * from t3| 3795x 379642 3797delete from t3| 3798call bug7049_4()| 3799Result 3800Caught it 3801select * from t3| 3802x 380342 3804select bug7049_2()| 3805bug7049_2() 38061 3807drop table t3| 3808drop procedure bug7049_1| 3809drop procedure bug7049_2| 3810drop procedure bug7049_3| 3811drop procedure bug7049_4| 3812drop function bug7049_1| 3813drop function bug7049_2| 3814drop function if exists bug13941| 3815drop procedure if exists bug13941| 3816create function bug13941(p_input_str text) 3817returns text 3818begin 3819declare p_output_str text; 3820set p_output_str = p_input_str; 3821set p_output_str = replace(p_output_str, 'xyzzy', 'plugh'); 3822set p_output_str = replace(p_output_str, 'test', 'prova'); 3823set p_output_str = replace(p_output_str, 'this', 'questo'); 3824set p_output_str = replace(p_output_str, ' a ', 'una '); 3825set p_output_str = replace(p_output_str, 'is', ''); 3826return p_output_str; 3827end| 3828create procedure bug13941(out sout varchar(128)) 3829begin 3830set sout = 'Local'; 3831set sout = ifnull(sout, 'DEF'); 3832end| 3833select bug13941('this is a test')| 3834bug13941('this is a test') 3835questo una prova 3836call bug13941(@a)| 3837select @a| 3838@a 3839Local 3840drop function bug13941| 3841drop procedure bug13941| 3842DROP PROCEDURE IF EXISTS bug13095; 3843DROP TABLE IF EXISTS bug13095_t1; 3844DROP VIEW IF EXISTS bug13095_v1; 3845CREATE PROCEDURE bug13095(tbl_name varchar(32)) 3846BEGIN 3847SET @str = 3848CONCAT("CREATE TABLE ", tbl_name, "(stuff char(15))"); 3849SELECT @str; 3850PREPARE stmt FROM @str; 3851EXECUTE stmt; 3852SET @str = 3853CONCAT("INSERT INTO ", tbl_name, " VALUES('row1'),('row2'),('row3')" ); 3854SELECT @str; 3855PREPARE stmt FROM @str; 3856EXECUTE stmt; 3857SET @str = 3858CONCAT("CREATE VIEW bug13095_v1(c1) AS SELECT stuff FROM ", tbl_name); 3859SELECT @str; 3860PREPARE stmt FROM @str; 3861EXECUTE stmt; 3862SELECT * FROM bug13095_v1; 3863SET @str = 3864"DROP VIEW bug13095_v1"; 3865SELECT @str; 3866PREPARE stmt FROM @str; 3867EXECUTE stmt; 3868END| 3869CALL bug13095('bug13095_t1'); 3870@str 3871CREATE TABLE bug13095_t1(stuff char(15)) 3872@str 3873INSERT INTO bug13095_t1 VALUES('row1'),('row2'),('row3') 3874@str 3875CREATE VIEW bug13095_v1(c1) AS SELECT stuff FROM bug13095_t1 3876c1 3877row1 3878row2 3879row3 3880@str 3881DROP VIEW bug13095_v1 3882DROP PROCEDURE IF EXISTS bug13095; 3883DROP VIEW IF EXISTS bug13095_v1; 3884DROP TABLE IF EXISTS bug13095_t1; 3885drop function if exists bug14723| 3886drop procedure if exists bug14723| 3887/*!50003 create function bug14723() 3888returns bigint(20) 3889main_loop: begin 3890return 42; 3891end */;; 3892show create function bug14723;; 3893Function sql_mode Create Function character_set_client collation_connection Database Collation 3894bug14723 CREATE DEFINER=`root`@`localhost` FUNCTION `bug14723`() RETURNS bigint(20) 3895main_loop: begin 3896return 42; 3897end latin1 latin1_swedish_ci latin1_swedish_ci 3898select bug14723();; 3899bug14723() 390042 3901/*!50003 create procedure bug14723() 3902main_loop: begin 3903select 42; 3904end */;; 3905show create procedure bug14723;; 3906Procedure sql_mode Create Procedure character_set_client collation_connection Database Collation 3907bug14723 CREATE DEFINER=`root`@`localhost` PROCEDURE `bug14723`() 3908main_loop: begin 3909select 42; 3910end latin1 latin1_swedish_ci latin1_swedish_ci 3911call bug14723();; 391242 391342 3914drop function bug14723| 3915drop procedure bug14723| 3916create procedure bug14845() 3917begin 3918declare a char(255); 3919declare done int default 0; 3920declare c cursor for select count(*) from t1 where 1 = 0; 3921declare continue handler for sqlstate '02000' set done = 1; 3922open c; 3923repeat 3924fetch c into a; 3925if not done then 3926select a; 3927end if; 3928until done end repeat; 3929close c; 3930end| 3931call bug14845()| 3932a 39330 3934drop procedure bug14845| 3935drop procedure if exists bug13549_1| 3936drop procedure if exists bug13549_2| 3937CREATE PROCEDURE `bug13549_2`() 3938begin 3939call bug13549_1(); 3940end| 3941CREATE PROCEDURE `bug13549_1`() 3942begin 3943declare done int default 0; 3944set done= not done; 3945end| 3946CALL bug13549_2()| 3947drop procedure bug13549_2| 3948drop procedure bug13549_1| 3949drop function if exists bug10100f| 3950drop procedure if exists bug10100p| 3951drop procedure if exists bug10100t| 3952drop procedure if exists bug10100pt| 3953drop procedure if exists bug10100pv| 3954drop procedure if exists bug10100pd| 3955drop procedure if exists bug10100pc| 3956create function bug10100f(prm int) returns int 3957begin 3958if prm > 1 then 3959return prm * bug10100f(prm - 1); 3960end if; 3961return 1; 3962end| 3963create procedure bug10100p(prm int, inout res int) 3964begin 3965set res = res * prm; 3966if prm > 1 then 3967call bug10100p(prm - 1, res); 3968end if; 3969end| 3970create procedure bug10100t(prm int) 3971begin 3972declare res int; 3973set res = 1; 3974call bug10100p(prm, res); 3975select res; 3976end| 3977create table t3 (a int)| 3978insert into t3 values (0)| 3979create view v1 as select a from t3| 3980create procedure bug10100pt(level int, lim int) 3981begin 3982if level < lim then 3983update t3 set a=level; 3984FLUSH TABLES; 3985call bug10100pt(level+1, lim); 3986else 3987select * from t3; 3988end if; 3989end| 3990create procedure bug10100pv(level int, lim int) 3991begin 3992if level < lim then 3993update v1 set a=level; 3994FLUSH TABLES; 3995call bug10100pv(level+1, lim); 3996else 3997select * from v1; 3998end if; 3999end| 4000prepare stmt2 from "select * from t3;"| 4001create procedure bug10100pd(level int, lim int) 4002begin 4003if level < lim then 4004select level; 4005prepare stmt1 from "update t3 set a=a+2"; 4006execute stmt1; 4007FLUSH TABLES; 4008execute stmt1; 4009FLUSH TABLES; 4010execute stmt1; 4011FLUSH TABLES; 4012deallocate prepare stmt1; 4013execute stmt2; 4014select * from t3; 4015call bug10100pd(level+1, lim); 4016else 4017execute stmt2; 4018end if; 4019end| 4020create procedure bug10100pc(level int, lim int) 4021begin 4022declare lv int; 4023declare c cursor for select a from t3; 4024open c; 4025if level < lim then 4026select level; 4027fetch c into lv; 4028select lv; 4029update t3 set a=level+lv; 4030FLUSH TABLES; 4031call bug10100pc(level+1, lim); 4032else 4033select * from t3; 4034end if; 4035close c; 4036end| 4037set @@max_sp_recursion_depth=4| 4038select @@max_sp_recursion_depth| 4039@@max_sp_recursion_depth 40404 4041select bug10100f(3)| 4042ERROR HY000: Recursive stored functions and triggers are not allowed. 4043select bug10100f(6)| 4044ERROR HY000: Recursive stored functions and triggers are not allowed. 4045call bug10100t(5)| 4046res 4047120 4048call bug10100pt(1,5)| 4049a 40504 4051call bug10100pv(1,5)| 4052a 40534 4054update t3 set a=1| 4055call bug10100pd(1,5)| 4056level 40571 4058a 40597 4060a 40617 4062level 40632 4064a 406513 4066a 406713 4068level 40693 4070a 407119 4072a 407319 4074level 40754 4076a 407725 4078a 407925 4080a 408125 4082select * from t3| 4083a 408425 4085update t3 set a=1| 4086call bug10100pc(1,5)| 4087level 40881 4089lv 40901 4091level 40922 4093lv 40942 4095level 40963 4097lv 40984 4099level 41004 4101lv 41027 4103a 410411 4105select * from t3| 4106a 410711 4108set @@max_sp_recursion_depth=0| 4109select @@max_sp_recursion_depth| 4110@@max_sp_recursion_depth 41110 4112select bug10100f(5)| 4113ERROR HY000: Recursive stored functions and triggers are not allowed. 4114call bug10100t(5)| 4115ERROR HY000: Recursive limit 0 (as set by the max_sp_recursion_depth variable) was exceeded for routine bug10100p 4116deallocate prepare stmt2| 4117drop function bug10100f| 4118drop procedure bug10100p| 4119drop procedure bug10100t| 4120drop procedure bug10100pt| 4121drop procedure bug10100pv| 4122drop procedure bug10100pd| 4123drop procedure bug10100pc| 4124drop view v1| 4125drop procedure if exists bug13729| 4126drop table if exists t3| 4127create table t3 (s1 int, primary key (s1))| 4128insert into t3 values (1),(2)| 4129create procedure bug13729() 4130begin 4131declare continue handler for sqlexception select 55; 4132update t3 set s1 = 1; 4133end| 4134call bug13729()| 413555 413655 4137select * from t3| 4138s1 41391 41402 4141drop procedure bug13729| 4142drop table t3| 4143drop procedure if exists bug14643_1| 4144drop procedure if exists bug14643_2| 4145create procedure bug14643_1() 4146begin 4147declare continue handler for sqlexception select 'boo' as 'Handler'; 4148begin 4149declare v int default undefined_var; 4150if v = 1 then 4151select 1; 4152else 4153select v, isnull(v); 4154end if; 4155end; 4156end| 4157create procedure bug14643_2() 4158begin 4159declare continue handler for sqlexception select 'boo' as 'Handler'; 4160case undefined_var 4161when 1 then 4162select 1; 4163else 4164select 2; 4165end case; 4166select undefined_var; 4167end| 4168call bug14643_1()| 4169Handler 4170boo 4171v isnull(v) 4172NULL 1 4173call bug14643_2()| 4174Handler 4175boo 4176Handler 4177boo 4178drop procedure bug14643_1| 4179drop procedure bug14643_2| 4180drop procedure if exists bug14304| 4181drop table if exists t3, t4| 4182create table t3(a int primary key auto_increment)| 4183create table t4(a int primary key auto_increment)| 4184create procedure bug14304() 4185begin 4186insert into t3 set a=null; 4187insert into t4 set a=null; 4188insert into t4 set a=null; 4189insert into t4 set a=null; 4190insert into t4 set a=null; 4191insert into t4 set a=null; 4192insert into t4 select null as a; 4193insert into t3 set a=null; 4194insert into t3 set a=null; 4195select * from t3; 4196end| 4197call bug14304()| 4198a 41991 42002 42013 4202drop procedure bug14304| 4203drop table t3, t4| 4204drop procedure if exists bug14376| 4205create procedure bug14376() 4206begin 4207declare x int default x; 4208end| 4209call bug14376()| 4210ERROR 42S22: Unknown column 'x' in 'field list' 4211drop procedure bug14376| 4212create procedure bug14376() 4213begin 4214declare x int default 42; 4215begin 4216declare x int default x; 4217select x; 4218end; 4219end| 4220call bug14376()| 4221x 422242 4223drop procedure bug14376| 4224create procedure bug14376(x int) 4225begin 4226declare x int default x; 4227select x; 4228end| 4229call bug14376(4711)| 4230x 42314711 4232drop procedure bug14376| 4233drop procedure if exists bug5967| 4234drop table if exists t3| 4235create table t3 (a varchar(255))| 4236insert into t3 (a) values ("a - table column")| 4237create procedure bug5967(a varchar(255)) 4238begin 4239declare i varchar(255); 4240declare c cursor for select a from t3; 4241select a; 4242select a from t3 into i; 4243select i as 'Parameter takes precedence over table column'; open c; 4244fetch c into i; 4245close c; 4246select i as 'Parameter takes precedence over table column in cursors'; 4247begin 4248declare a varchar(255) default 'a - local variable'; 4249declare c1 cursor for select a from t3; 4250select a as 'A local variable takes precedence over parameter'; 4251open c1; 4252fetch c1 into i; 4253close c1; 4254select i as 'A local variable takes precedence over parameter in cursors'; 4255begin 4256declare a varchar(255) default 'a - local variable in a nested compound statement'; 4257declare c2 cursor for select a from t3; 4258select a as 'A local variable in a nested compound statement takes precedence over a local variable in the outer statement'; 4259select a from t3 into i; 4260select i as 'A local variable in a nested compound statement takes precedence over table column'; 4261open c2; 4262fetch c2 into i; 4263close c2; 4264select i as 'A local variable in a nested compound statement takes precedence over table column in cursors'; 4265end; 4266end; 4267end| 4268call bug5967("a - stored procedure parameter")| 4269a 4270a - stored procedure parameter 4271Parameter takes precedence over table column 4272a - stored procedure parameter 4273Parameter takes precedence over table column in cursors 4274a - stored procedure parameter 4275A local variable takes precedence over parameter 4276a - local variable 4277A local variable takes precedence over parameter in cursors 4278a - local variable 4279A local variable in a nested compound statement takes precedence over a local variable in the outer statement 4280a - local variable in a nested compound statement 4281A local variable in a nested compound statement takes precedence over table column 4282a - local variable in a nested compound statement 4283A local variable in a nested compound statement takes precedence over table column in cursors 4284a - local variable in a nested compound statement 4285drop procedure bug5967| 4286drop procedure if exists bug13012| 4287create procedure bug13012() 4288BEGIN 4289REPAIR TABLE t1; 4290END| 4291call bug13012()| 4292Table Op Msg_type Msg_text 4293test.t1 repair status OK 4294drop procedure bug13012| 4295create view v1 as select * from t1| 4296create procedure bug13012() 4297BEGIN 4298REPAIR TABLE t1,t2,t3,v1; 4299OPTIMIZE TABLE t1,t2,t3,v1; 4300ANALYZE TABLE t1,t2,t3,v1; 4301END| 4302call bug13012()| 4303Table Op Msg_type Msg_text 4304test.t1 repair status OK 4305test.t2 repair status OK 4306test.t3 repair status OK 4307test.v1 repair Error 'test.v1' is not BASE TABLE 4308test.v1 repair status Operation failed 4309Table Op Msg_type Msg_text 4310test.t1 optimize status OK 4311test.t2 optimize status OK 4312test.t3 optimize status OK 4313test.v1 optimize Error 'test.v1' is not BASE TABLE 4314test.v1 optimize status Operation failed 4315Table Op Msg_type Msg_text 4316test.t1 analyze status Table is already up to date 4317test.t2 analyze status Table is already up to date 4318test.t3 analyze status Table is already up to date 4319test.v1 analyze Error 'test.v1' is not BASE TABLE 4320test.v1 analyze status Operation failed 4321call bug13012()| 4322Table Op Msg_type Msg_text 4323test.t1 repair status OK 4324test.t2 repair status OK 4325test.t3 repair status OK 4326test.v1 repair Error 'test.v1' is not BASE TABLE 4327test.v1 repair status Operation failed 4328Table Op Msg_type Msg_text 4329test.t1 optimize status OK 4330test.t2 optimize status OK 4331test.t3 optimize status OK 4332test.v1 optimize Error 'test.v1' is not BASE TABLE 4333test.v1 optimize status Operation failed 4334Table Op Msg_type Msg_text 4335test.t1 analyze status Table is already up to date 4336test.t2 analyze status Table is already up to date 4337test.t3 analyze status Table is already up to date 4338test.v1 analyze Error 'test.v1' is not BASE TABLE 4339test.v1 analyze status Operation failed 4340call bug13012()| 4341Table Op Msg_type Msg_text 4342test.t1 repair status OK 4343test.t2 repair status OK 4344test.t3 repair status OK 4345test.v1 repair Error 'test.v1' is not BASE TABLE 4346test.v1 repair status Operation failed 4347Table Op Msg_type Msg_text 4348test.t1 optimize status OK 4349test.t2 optimize status OK 4350test.t3 optimize status OK 4351test.v1 optimize Error 'test.v1' is not BASE TABLE 4352test.v1 optimize status Operation failed 4353Table Op Msg_type Msg_text 4354test.t1 analyze status Table is already up to date 4355test.t2 analyze status Table is already up to date 4356test.t3 analyze status Table is already up to date 4357test.v1 analyze Error 'test.v1' is not BASE TABLE 4358test.v1 analyze status Operation failed 4359drop procedure bug13012| 4360drop view v1| 4361select * from t1 order by data| 4362id data 4363aa 0 4364aa 1 4365aa 2 4366aa 3 4367aa 4 4368aa 5 4369aa 6 4370aa 7 4371aa 8 4372aa 9 4373drop schema if exists mysqltest1| 4374Warnings: 4375Note 1008 Can't drop database 'mysqltest1'; database doesn't exist 4376drop schema if exists mysqltest2| 4377Warnings: 4378Note 1008 Can't drop database 'mysqltest2'; database doesn't exist 4379drop schema if exists mysqltest3| 4380Warnings: 4381Note 1008 Can't drop database 'mysqltest3'; database doesn't exist 4382create schema mysqltest1| 4383create schema mysqltest2| 4384create schema mysqltest3| 4385use mysqltest3| 4386create procedure mysqltest1.p1 (out prequestid varchar(100)) 4387begin 4388call mysqltest2.p2('call mysqltest3.p3(1, 2)'); 4389end| 4390create procedure mysqltest2.p2(in psql text) 4391begin 4392declare lsql text; 4393set @lsql= psql; 4394prepare lstatement from @lsql; 4395execute lstatement; 4396deallocate prepare lstatement; 4397end| 4398create procedure mysqltest3.p3(in p1 int) 4399begin 4400select p1; 4401end| 4402call mysqltest1.p1(@rs)| 4403ERROR 42000: Incorrect number of arguments for PROCEDURE mysqltest3.p3; expected 1, got 2 4404call mysqltest1.p1(@rs)| 4405ERROR 42000: Incorrect number of arguments for PROCEDURE mysqltest3.p3; expected 1, got 2 4406call mysqltest1.p1(@rs)| 4407ERROR 42000: Incorrect number of arguments for PROCEDURE mysqltest3.p3; expected 1, got 2 4408drop schema if exists mysqltest1| 4409drop schema if exists mysqltest2| 4410drop schema if exists mysqltest3| 4411use test| 4412drop table if exists t3| 4413drop procedure if exists bug15441| 4414create table t3 (id int not null primary key, county varchar(25))| 4415insert into t3 (id, county) values (1, 'York')| 4416create procedure bug15441(c varchar(25)) 4417begin 4418update t3 set id=2, county=values(c); 4419end| 4420call bug15441('county')| 4421ERROR 42S22: Unknown column 'c' in 'field list' 4422drop procedure bug15441| 4423create procedure bug15441(county varchar(25)) 4424begin 4425declare c varchar(25) default "hello"; 4426insert into t3 (id, county) values (1, county) 4427on duplicate key update county= values(county); 4428select * from t3; 4429update t3 set id=2, county=values(id); 4430select * from t3; 4431end| 4432call bug15441('Yale')| 4433id county 44341 Yale 4435id county 44362 NULL 4437drop table t3| 4438drop procedure bug15441| 4439drop procedure if exists bug14498_1| 4440drop procedure if exists bug14498_2| 4441drop procedure if exists bug14498_3| 4442drop procedure if exists bug14498_4| 4443drop procedure if exists bug14498_5| 4444create procedure bug14498_1() 4445begin 4446declare continue handler for sqlexception select 'error' as 'Handler'; 4447if v then 4448select 'yes' as 'v'; 4449else 4450select 'no' as 'v'; 4451end if; 4452select 'done' as 'End'; 4453end| 4454create procedure bug14498_2() 4455begin 4456declare continue handler for sqlexception select 'error' as 'Handler'; 4457while v do 4458select 'yes' as 'v'; 4459end while; 4460select 'done' as 'End'; 4461end| 4462create procedure bug14498_3() 4463begin 4464declare continue handler for sqlexception select 'error' as 'Handler'; 4465repeat 4466select 'maybe' as 'v'; 4467until v end repeat; 4468select 'done' as 'End'; 4469end| 4470create procedure bug14498_4() 4471begin 4472declare continue handler for sqlexception select 'error' as 'Handler'; 4473case v 4474when 1 then 4475select '1' as 'v'; 4476when 2 then 4477select '2' as 'v'; 4478else 4479select '?' as 'v'; 4480end case; 4481select 'done' as 'End'; 4482end| 4483create procedure bug14498_5() 4484begin 4485declare continue handler for sqlexception select 'error' as 'Handler'; 4486case 4487when v = 1 then 4488select '1' as 'v'; 4489when v = 2 then 4490select '2' as 'v'; 4491else 4492select '?' as 'v'; 4493end case; 4494select 'done' as 'End'; 4495end| 4496call bug14498_1()| 4497Handler 4498error 4499End 4500done 4501call bug14498_2()| 4502Handler 4503error 4504End 4505done 4506call bug14498_3()| 4507v 4508maybe 4509Handler 4510error 4511End 4512done 4513call bug14498_4()| 4514Handler 4515error 4516End 4517done 4518call bug14498_5()| 4519Handler 4520error 4521End 4522done 4523drop procedure bug14498_1| 4524drop procedure bug14498_2| 4525drop procedure bug14498_3| 4526drop procedure bug14498_4| 4527drop procedure bug14498_5| 4528drop table if exists t3| 4529drop procedure if exists bug15231_1| 4530drop procedure if exists bug15231_2| 4531drop procedure if exists bug15231_3| 4532drop procedure if exists bug15231_4| 4533drop procedure if exists bug15231_5| 4534drop procedure if exists bug15231_6| 4535create table t3 (id int not null)| 4536create procedure bug15231_1() 4537begin 4538declare xid integer; 4539declare xdone integer default 0; 4540declare continue handler for not found set xdone = 1; 4541set xid=null; 4542call bug15231_2(xid); 4543select xid, xdone; 4544end| 4545create procedure bug15231_2(inout ioid integer) 4546begin 4547select "Before NOT FOUND condition is triggered" as '1'; 4548select id into ioid from t3 where id=ioid; 4549select "After NOT FOUND condtition is triggered" as '2'; 4550if ioid is null then 4551set ioid=1; 4552end if; 4553end| 4554create procedure bug15231_3() 4555begin 4556declare exit handler for sqlwarning 4557select 'Caught it (correct)' as 'Result'; 4558call bug15231_4(); 4559end| 4560create procedure bug15231_4() 4561begin 4562declare x decimal(2,1); 4563set x = 'zap'; 4564select 'Missed it (correct)' as 'Result'; 4565show warnings; 4566end| 4567create procedure bug15231_5() 4568begin 4569declare exit handler for sqlwarning 4570select 'Caught it (wrong)' as 'Result'; 4571call bug15231_6(); 4572end| 4573create procedure bug15231_6() 4574begin 4575declare x decimal(2,1); 4576set x = 'zap'; 4577select 'Missed it (correct)' as 'Result'; 4578select id from t3; 4579end| 4580call bug15231_1()| 45811 4582Before NOT FOUND condition is triggered 45832 4584After NOT FOUND condtition is triggered 4585xid xdone 45861 1 4587call bug15231_3()| 4588Result 4589Missed it (correct) 4590Level Code Message 4591Warning 1366 Incorrect decimal value: 'zap' for column 'x' at row 1 4592Result 4593Caught it (correct) 4594call bug15231_5()| 4595Result 4596Missed it (correct) 4597id 4598drop table t3| 4599drop procedure bug15231_1| 4600drop procedure bug15231_2| 4601drop procedure bug15231_3| 4602drop procedure bug15231_4| 4603drop procedure bug15231_5| 4604drop procedure bug15231_6| 4605drop procedure if exists bug15011| 4606create table t3 (c1 int primary key)| 4607insert into t3 values (1)| 4608create procedure bug15011() 4609deterministic 4610begin 4611declare continue handler for 1062 4612select 'Outer' as 'Handler'; 4613begin 4614declare continue handler for 1062 4615select 'Inner' as 'Handler'; 4616insert into t3 values (1); 4617end; 4618end| 4619call bug15011()| 4620Handler 4621Inner 4622drop procedure bug15011| 4623drop table t3| 4624drop procedure if exists bug17476| 4625create table t3 ( d date )| 4626insert into t3 values 4627( '2005-01-01' ), ( '2005-01-02' ), ( '2005-01-03' ), 4628( '2005-01-04' ), ( '2005-02-01' ), ( '2005-02-02' )| 4629create procedure bug17476(pDateFormat varchar(10)) 4630select date_format(t3.d, pDateFormat), count(*) 4631from t3 4632group by date_format(t3.d, pDateFormat)| 4633call bug17476('%Y-%m')| 4634date_format(t3.d, pDateFormat) count(*) 46352005-01 4 46362005-02 2 4637call bug17476('%Y-%m')| 4638date_format(t3.d, pDateFormat) count(*) 46392005-01 4 46402005-02 2 4641drop table t3| 4642drop procedure bug17476| 4643drop table if exists t3| 4644drop procedure if exists bug16887| 4645create table t3 ( c varchar(1) )| 4646insert into t3 values 4647(' '),('.'),(';'),(','),('-'),('_'),('('),(')'),('/'),('\\')| 4648create procedure bug16887() 4649begin 4650declare i int default 10; 4651again: 4652while i > 0 do 4653begin 4654declare breakchar varchar(1); 4655declare done int default 0; 4656declare t3_cursor cursor for select c from t3; 4657declare continue handler for not found set done = 1; 4658set i = i - 1; 4659select i; 4660if i = 3 then 4661iterate again; 4662end if; 4663open t3_cursor; 4664loop 4665fetch t3_cursor into breakchar; 4666if done = 1 then 4667begin 4668close t3_cursor; 4669iterate again; 4670end; 4671end if; 4672end loop; 4673end; 4674end while; 4675end| 4676call bug16887()| 4677i 46789 4679i 46808 4681i 46827 4683i 46846 4685i 46865 4687i 46884 4689i 46903 4691i 46922 4693i 46941 4695i 46960 4697drop table t3| 4698drop procedure bug16887| 4699drop procedure if exists bug16474_1| 4700drop procedure if exists bug16474_2| 4701delete from t1| 4702insert into t1 values ('c', 2), ('b', 3), ('a', 1)| 4703create procedure bug16474_1() 4704begin 4705declare x int; 4706select id from t1 order by x, id; 4707end| 4708drop procedure if exists bug14945| 4709create table t3 (id int not null auto_increment primary key)| 4710create procedure bug14945() deterministic truncate t3| 4711insert into t3 values (null)| 4712call bug14945()| 4713insert into t3 values (null)| 4714select * from t3| 4715id 47161 4717drop table t3| 4718drop procedure bug14945| 4719create procedure bug16474_2(x int) 4720select id from t1 order by x, id| 4721call bug16474_1()| 4722id 4723a 4724b 4725c 4726call bug16474_2(1)| 4727id 4728a 4729b 4730c 4731call bug16474_2(2)| 4732id 4733a 4734b 4735c 4736drop procedure bug16474_1| 4737drop procedure bug16474_2| 4738set @x = 2| 4739select * from t1 order by @x, data| 4740id data 4741a 1 4742c 2 4743b 3 4744delete from t1| 4745drop function if exists bug15728| 4746drop table if exists t3| 4747create table t3 ( 4748id int not null auto_increment, 4749primary key (id) 4750)| 4751create function bug15728() returns int(11) 4752return last_insert_id()| 4753insert into t3 values (0)| 4754select last_insert_id()| 4755last_insert_id() 47561 4757select bug15728()| 4758bug15728() 47591 4760drop function bug15728| 4761drop table t3| 4762drop procedure if exists bug18787| 4763create procedure bug18787() 4764begin 4765declare continue handler for sqlexception begin end; 4766select no_such_function(); 4767end| 4768call bug18787()| 4769drop procedure bug18787| 4770create database bug18344_012345678901| 4771use bug18344_012345678901| 4772create procedure bug18344() begin end| 4773create procedure bug18344_2() begin end| 4774create database bug18344_0123456789012| 4775use bug18344_0123456789012| 4776create procedure bug18344() begin end| 4777create procedure bug18344_2() begin end| 4778use test| 4779select schema_name from information_schema.schemata where 4780schema_name like 'bug18344%'| 4781schema_name 4782bug18344_012345678901 4783bug18344_0123456789012 4784select routine_name,routine_schema from information_schema.routines where 4785routine_schema like 'bug18344%'| 4786routine_name routine_schema 4787bug18344 bug18344_012345678901 4788bug18344_2 bug18344_012345678901 4789bug18344 bug18344_0123456789012 4790bug18344_2 bug18344_0123456789012 4791drop database bug18344_012345678901| 4792drop database bug18344_0123456789012| 4793select schema_name from information_schema.schemata where 4794schema_name like 'bug18344%'| 4795schema_name 4796select routine_name,routine_schema from information_schema.routines where 4797routine_schema like 'bug18344%'| 4798routine_name routine_schema 4799drop function if exists bug12472| 4800create function bug12472() returns int return (select count(*) from t1)| 4801create table t3 as select bug12472() as i| 4802show create table t3| 4803Table Create Table 4804t3 CREATE TABLE `t3` ( 4805 `i` int(11) DEFAULT NULL 4806) ENGINE=MyISAM DEFAULT CHARSET=latin1 4807select * from t3| 4808i 48090 4810drop table t3| 4811create view v1 as select bug12472() as j| 4812create table t3 as select * from v1| 4813show create table t3| 4814Table Create Table 4815t3 CREATE TABLE `t3` ( 4816 `j` int(11) DEFAULT NULL 4817) ENGINE=MyISAM DEFAULT CHARSET=latin1 4818select * from t3| 4819j 48200 4821drop table t3| 4822drop view v1| 4823drop function bug12472| 4824DROP FUNCTION IF EXISTS bug18589_f1| 4825DROP PROCEDURE IF EXISTS bug18589_p1| 4826DROP PROCEDURE IF EXISTS bug18589_p2| 4827CREATE FUNCTION bug18589_f1(arg TEXT) RETURNS TEXT 4828BEGIN 4829RETURN CONCAT(arg, ""); 4830END| 4831CREATE PROCEDURE bug18589_p1(arg TEXT, OUT ret TEXT) 4832BEGIN 4833SET ret = CONCAT(arg, ""); 4834END| 4835CREATE PROCEDURE bug18589_p2(arg TEXT) 4836BEGIN 4837DECLARE v TEXT; 4838CALL bug18589_p1(arg, v); 4839SELECT v; 4840END| 4841SELECT bug18589_f1(REPEAT("a", 767))| 4842bug18589_f1(REPEAT("a", 767)) 4843aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 4844SET @bug18589_v1 = ""| 4845CALL bug18589_p1(REPEAT("a", 767), @bug18589_v1)| 4846SELECT @bug18589_v1| 4847@bug18589_v1 4848aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 4849CALL bug18589_p2(REPEAT("a", 767))| 4850v 4851aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 4852DROP FUNCTION bug18589_f1| 4853DROP PROCEDURE bug18589_p1| 4854DROP PROCEDURE bug18589_p2| 4855DROP FUNCTION IF EXISTS bug18037_f1| 4856DROP PROCEDURE IF EXISTS bug18037_p1| 4857DROP PROCEDURE IF EXISTS bug18037_p2| 4858CREATE FUNCTION bug18037_f1() RETURNS INT 4859BEGIN 4860RETURN @@server_id; 4861END| 4862CREATE PROCEDURE bug18037_p1() 4863BEGIN 4864DECLARE v INT DEFAULT @@server_id; 4865END| 4866CREATE PROCEDURE bug18037_p2() 4867BEGIN 4868CASE @@server_id 4869WHEN -1 THEN 4870SELECT 0; 4871ELSE 4872SELECT 1; 4873END CASE; 4874END| 4875SELECT bug18037_f1()| 4876bug18037_f1() 48771 4878CALL bug18037_p1()| 4879CALL bug18037_p2()| 48801 48811 4882DROP FUNCTION bug18037_f1| 4883DROP PROCEDURE bug18037_p1| 4884DROP PROCEDURE bug18037_p2| 4885use test| 4886create table t3 (i int)| 4887insert into t3 values (1), (2)| 4888create database mysqltest1| 4889use mysqltest1| 4890create function bug17199() returns varchar(2) deterministic return 'ok'| 4891use test| 4892select *, mysqltest1.bug17199() from t3| 4893i mysqltest1.bug17199() 48941 ok 48952 ok 4896use mysqltest1| 4897create function bug18444(i int) returns int no sql deterministic return i + 1| 4898use test| 4899select mysqltest1.bug18444(i) from t3| 4900mysqltest1.bug18444(i) 49012 49023 4903drop database mysqltest1| 4904create database mysqltest1 charset=utf8| 4905create database mysqltest2 charset=utf8| 4906create procedure mysqltest1.p1() 4907begin 4908-- alters the default collation of database test 4909alter database character set koi8r; 4910end| 4911use mysqltest1| 4912call p1()| 4913show create database mysqltest1| 4914Database Create Database 4915mysqltest1 CREATE DATABASE `mysqltest1` /*!40100 DEFAULT CHARACTER SET koi8r */ 4916show create database mysqltest2| 4917Database Create Database 4918mysqltest2 CREATE DATABASE `mysqltest2` /*!40100 DEFAULT CHARACTER SET utf8 */ 4919alter database mysqltest1 character set utf8| 4920use mysqltest2| 4921call mysqltest1.p1()| 4922show create database mysqltest1| 4923Database Create Database 4924mysqltest1 CREATE DATABASE `mysqltest1` /*!40100 DEFAULT CHARACTER SET koi8r */ 4925show create database mysqltest2| 4926Database Create Database 4927mysqltest2 CREATE DATABASE `mysqltest2` /*!40100 DEFAULT CHARACTER SET utf8 */ 4928drop database mysqltest1| 4929drop database mysqltest2| 4930use test| 4931drop table if exists t3| 4932drop procedure if exists bug15217| 4933create table t3 as select 1| 4934create procedure bug15217() 4935begin 4936declare var1 char(255); 4937declare cur1 cursor for select * from t3; 4938open cur1; 4939fetch cur1 into var1; 4940select concat('data was: /', var1, '/'); 4941close cur1; 4942end | 4943call bug15217()| 4944concat('data was: /', var1, '/') 4945data was: /1/ 4946flush tables | 4947call bug15217()| 4948concat('data was: /', var1, '/') 4949data was: /1/ 4950drop table t3| 4951drop procedure bug15217| 4952DROP PROCEDURE IF EXISTS bug21013 | 4953CREATE PROCEDURE bug21013(IN lim INT) 4954BEGIN 4955DECLARE i INT DEFAULT 0; 4956WHILE (i < lim) DO 4957SET @b = LOCATE(_latin1'b', @a, 1); 4958SET i = i + 1; 4959END WHILE; 4960END | 4961SET @a = _latin2"aaaaaaaaaa" | 4962CALL bug21013(10) | 4963DROP PROCEDURE bug21013 | 4964DROP DATABASE IF EXISTS mysqltest1| 4965DROP DATABASE IF EXISTS mysqltest2| 4966CREATE DATABASE mysqltest1 DEFAULT CHARACTER SET utf8| 4967CREATE DATABASE mysqltest2 DEFAULT CHARACTER SET utf8| 4968use mysqltest1| 4969CREATE FUNCTION bug16211_f1() RETURNS CHAR(10) 4970RETURN ""| 4971CREATE FUNCTION bug16211_f2() RETURNS CHAR(10) CHARSET koi8r 4972RETURN ""| 4973CREATE FUNCTION mysqltest2.bug16211_f3() RETURNS CHAR(10) 4974RETURN ""| 4975CREATE FUNCTION mysqltest2.bug16211_f4() RETURNS CHAR(10) CHARSET koi8r 4976RETURN ""| 4977SHOW CREATE FUNCTION bug16211_f1| 4978Function sql_mode Create Function character_set_client collation_connection Database Collation 4979bug16211_f1 CREATE DEFINER=`root`@`localhost` FUNCTION `bug16211_f1`() RETURNS char(10) CHARSET utf8 4980RETURN "" latin1 latin1_swedish_ci utf8_general_ci 4981SHOW CREATE FUNCTION bug16211_f2| 4982Function sql_mode Create Function character_set_client collation_connection Database Collation 4983bug16211_f2 CREATE DEFINER=`root`@`localhost` FUNCTION `bug16211_f2`() RETURNS char(10) CHARSET koi8r 4984RETURN "" latin1 latin1_swedish_ci utf8_general_ci 4985SHOW CREATE FUNCTION mysqltest2.bug16211_f3| 4986Function sql_mode Create Function character_set_client collation_connection Database Collation 4987bug16211_f3 CREATE DEFINER=`root`@`localhost` FUNCTION `bug16211_f3`() RETURNS char(10) CHARSET utf8 4988RETURN "" latin1 latin1_swedish_ci utf8_general_ci 4989SHOW CREATE FUNCTION mysqltest2.bug16211_f4| 4990Function sql_mode Create Function character_set_client collation_connection Database Collation 4991bug16211_f4 CREATE DEFINER=`root`@`localhost` FUNCTION `bug16211_f4`() RETURNS char(10) CHARSET koi8r 4992RETURN "" latin1 latin1_swedish_ci utf8_general_ci 4993SELECT dtd_identifier 4994FROM INFORMATION_SCHEMA.ROUTINES 4995WHERE ROUTINE_SCHEMA = "mysqltest1" AND ROUTINE_NAME = "bug16211_f1"| 4996dtd_identifier 4997char(10) 4998SELECT dtd_identifier 4999FROM INFORMATION_SCHEMA.ROUTINES 5000WHERE ROUTINE_SCHEMA = "mysqltest1" AND ROUTINE_NAME = "bug16211_f2"| 5001dtd_identifier 5002char(10) 5003SELECT dtd_identifier 5004FROM INFORMATION_SCHEMA.ROUTINES 5005WHERE ROUTINE_SCHEMA = "mysqltest2" AND ROUTINE_NAME = "bug16211_f3"| 5006dtd_identifier 5007char(10) 5008SELECT dtd_identifier 5009FROM INFORMATION_SCHEMA.ROUTINES 5010WHERE ROUTINE_SCHEMA = "mysqltest2" AND ROUTINE_NAME = "bug16211_f4"| 5011dtd_identifier 5012char(10) 5013SELECT CHARSET(bug16211_f1())| 5014CHARSET(bug16211_f1()) 5015utf8 5016SELECT CHARSET(bug16211_f2())| 5017CHARSET(bug16211_f2()) 5018koi8r 5019SELECT CHARSET(mysqltest2.bug16211_f3())| 5020CHARSET(mysqltest2.bug16211_f3()) 5021utf8 5022SELECT CHARSET(mysqltest2.bug16211_f4())| 5023CHARSET(mysqltest2.bug16211_f4()) 5024koi8r 5025ALTER DATABASE mysqltest1 CHARACTER SET cp1251| 5026ALTER DATABASE mysqltest2 CHARACTER SET cp1251| 5027SHOW CREATE FUNCTION bug16211_f1| 5028Function sql_mode Create Function character_set_client collation_connection Database Collation 5029bug16211_f1 CREATE DEFINER=`root`@`localhost` FUNCTION `bug16211_f1`() RETURNS char(10) CHARSET utf8 5030RETURN "" latin1 latin1_swedish_ci utf8_general_ci 5031SHOW CREATE FUNCTION bug16211_f2| 5032Function sql_mode Create Function character_set_client collation_connection Database Collation 5033bug16211_f2 CREATE DEFINER=`root`@`localhost` FUNCTION `bug16211_f2`() RETURNS char(10) CHARSET koi8r 5034RETURN "" latin1 latin1_swedish_ci utf8_general_ci 5035SHOW CREATE FUNCTION mysqltest2.bug16211_f3| 5036Function sql_mode Create Function character_set_client collation_connection Database Collation 5037bug16211_f3 CREATE DEFINER=`root`@`localhost` FUNCTION `bug16211_f3`() RETURNS char(10) CHARSET utf8 5038RETURN "" latin1 latin1_swedish_ci utf8_general_ci 5039SHOW CREATE FUNCTION mysqltest2.bug16211_f4| 5040Function sql_mode Create Function character_set_client collation_connection Database Collation 5041bug16211_f4 CREATE DEFINER=`root`@`localhost` FUNCTION `bug16211_f4`() RETURNS char(10) CHARSET koi8r 5042RETURN "" latin1 latin1_swedish_ci utf8_general_ci 5043SELECT dtd_identifier 5044FROM INFORMATION_SCHEMA.ROUTINES 5045WHERE ROUTINE_SCHEMA = "mysqltest1" AND ROUTINE_NAME = "bug16211_f1"| 5046dtd_identifier 5047char(10) 5048SELECT dtd_identifier 5049FROM INFORMATION_SCHEMA.ROUTINES 5050WHERE ROUTINE_SCHEMA = "mysqltest1" AND ROUTINE_NAME = "bug16211_f2"| 5051dtd_identifier 5052char(10) 5053SELECT dtd_identifier 5054FROM INFORMATION_SCHEMA.ROUTINES 5055WHERE ROUTINE_SCHEMA = "mysqltest2" AND ROUTINE_NAME = "bug16211_f3"| 5056dtd_identifier 5057char(10) 5058SELECT dtd_identifier 5059FROM INFORMATION_SCHEMA.ROUTINES 5060WHERE ROUTINE_SCHEMA = "mysqltest2" AND ROUTINE_NAME = "bug16211_f4"| 5061dtd_identifier 5062char(10) 5063SELECT CHARSET(bug16211_f1())| 5064CHARSET(bug16211_f1()) 5065utf8 5066SELECT CHARSET(bug16211_f2())| 5067CHARSET(bug16211_f2()) 5068koi8r 5069SELECT CHARSET(mysqltest2.bug16211_f3())| 5070CHARSET(mysqltest2.bug16211_f3()) 5071utf8 5072SELECT CHARSET(mysqltest2.bug16211_f4())| 5073CHARSET(mysqltest2.bug16211_f4()) 5074koi8r 5075use test| 5076DROP DATABASE mysqltest1| 5077DROP DATABASE mysqltest2| 5078DROP DATABASE IF EXISTS mysqltest1| 5079CREATE DATABASE mysqltest1 DEFAULT CHARACTER SET utf8| 5080use mysqltest1| 5081CREATE PROCEDURE bug16676_p1( 5082IN p1 CHAR(10), 5083INOUT p2 CHAR(10), 5084OUT p3 CHAR(10)) 5085BEGIN 5086SELECT CHARSET(p1), COLLATION(p1); 5087SELECT CHARSET(p2), COLLATION(p2); 5088SELECT CHARSET(p3), COLLATION(p3); 5089END| 5090CREATE PROCEDURE bug16676_p2( 5091IN p1 CHAR(10) CHARSET koi8r, 5092INOUT p2 CHAR(10) CHARSET cp1251, 5093OUT p3 CHAR(10) CHARSET greek) 5094BEGIN 5095SELECT CHARSET(p1), COLLATION(p1); 5096SELECT CHARSET(p2), COLLATION(p2); 5097SELECT CHARSET(p3), COLLATION(p3); 5098END| 5099SET @v2 = 'b'| 5100SET @v3 = 'c'| 5101CALL bug16676_p1('a', @v2, @v3)| 5102CHARSET(p1) COLLATION(p1) 5103utf8 utf8_general_ci 5104CHARSET(p2) COLLATION(p2) 5105utf8 utf8_general_ci 5106CHARSET(p3) COLLATION(p3) 5107utf8 utf8_general_ci 5108CALL bug16676_p2('a', @v2, @v3)| 5109CHARSET(p1) COLLATION(p1) 5110koi8r koi8r_general_ci 5111CHARSET(p2) COLLATION(p2) 5112cp1251 cp1251_general_ci 5113CHARSET(p3) COLLATION(p3) 5114greek greek_general_ci 5115use test| 5116DROP DATABASE mysqltest1| 5117drop table if exists t3| 5118drop table if exists t4| 5119drop procedure if exists bug8153_subselect| 5120drop procedure if exists bug8153_subselect_a| 5121drop procedure if exists bug8153_subselect_b| 5122drop procedure if exists bug8153_proc_a| 5123drop procedure if exists bug8153_proc_b| 5124create table t3 (a int)| 5125create table t4 (a int)| 5126insert into t3 values (1), (1), (2), (3)| 5127insert into t4 values (1), (1)| 5128create procedure bug8153_subselect() 5129begin 5130declare continue handler for sqlexception 5131begin 5132select 'statement failed'; 5133end; 5134update t3 set a=a+1 where (select a from t4 where a=1) is null; 5135select 'statement after update'; 5136end| 5137call bug8153_subselect()| 5138statement failed 5139statement failed 5140statement after update 5141statement after update 5142select * from t3| 5143a 51441 51451 51462 51473 5148call bug8153_subselect()| 5149statement failed 5150statement failed 5151statement after update 5152statement after update 5153select * from t3| 5154a 51551 51561 51572 51583 5159drop procedure bug8153_subselect| 5160create procedure bug8153_subselect_a() 5161begin 5162declare continue handler for sqlexception 5163begin 5164select 'in continue handler'; 5165end; 5166select 'reachable code a1'; 5167call bug8153_subselect_b(); 5168select 'reachable code a2'; 5169end| 5170create procedure bug8153_subselect_b() 5171begin 5172select 'reachable code b1'; 5173update t3 set a=a+1 where (select a from t4 where a=1) is null; 5174select 'unreachable code b2'; 5175end| 5176call bug8153_subselect_a()| 5177reachable code a1 5178reachable code a1 5179reachable code b1 5180reachable code b1 5181in continue handler 5182in continue handler 5183reachable code a2 5184reachable code a2 5185select * from t3| 5186a 51871 51881 51892 51903 5191call bug8153_subselect_a()| 5192reachable code a1 5193reachable code a1 5194reachable code b1 5195reachable code b1 5196in continue handler 5197in continue handler 5198reachable code a2 5199reachable code a2 5200select * from t3| 5201a 52021 52031 52042 52053 5206drop procedure bug8153_subselect_a| 5207drop procedure bug8153_subselect_b| 5208create procedure bug8153_proc_a() 5209begin 5210declare continue handler for sqlexception 5211begin 5212select 'in continue handler'; 5213end; 5214select 'reachable code a1'; 5215call bug8153_proc_b(); 5216select 'reachable code a2'; 5217end| 5218create procedure bug8153_proc_b() 5219begin 5220select 'reachable code b1'; 5221select no_such_function(); 5222select 'unreachable code b2'; 5223end| 5224call bug8153_proc_a()| 5225reachable code a1 5226reachable code a1 5227reachable code b1 5228reachable code b1 5229in continue handler 5230in continue handler 5231reachable code a2 5232reachable code a2 5233drop procedure bug8153_proc_a| 5234drop procedure bug8153_proc_b| 5235drop table t3| 5236drop table t4| 5237drop procedure if exists bug19862| 5238CREATE TABLE t11 (a INT)| 5239CREATE TABLE t12 (a INT)| 5240CREATE FUNCTION bug19862(x INT) RETURNS INT 5241BEGIN 5242INSERT INTO t11 VALUES (x); 5243RETURN x+1; 5244END| 5245INSERT INTO t12 VALUES (1), (2)| 5246SELECT bug19862(a) FROM t12 ORDER BY 1| 5247bug19862(a) 52482 52493 5250SELECT * FROM t11| 5251a 52521 52532 5254DROP TABLE t11, t12| 5255DROP FUNCTION bug19862| 5256drop table if exists t3| 5257drop database if exists mysqltest1| 5258create table t3 (a int)| 5259insert into t3 (a) values (1), (2)| 5260create database mysqltest1| 5261use mysqltest1| 5262drop database mysqltest1| 5263select database()| 5264database() 5265NULL 5266select * from (select 1 as a) as t1 natural join (select * from test.t3) as t2| 5267a 52681 5269use test| 5270drop table t3| 5271DROP PROCEDURE IF EXISTS bug16899_p1| 5272DROP FUNCTION IF EXISTS bug16899_f1| 5273CREATE DEFINER=1234567890abcdefGHIKL@localhost PROCEDURE bug16899_p1() 5274BEGIN 5275SET @a = 1; 5276END| 5277ERROR HY000: String '1234567890abcdefGHIKL' is too long for user name (should be no longer than 16) 5278CREATE DEFINER=some_user_name@1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY 5279FUNCTION bug16899_f1() RETURNS INT 5280BEGIN 5281RETURN 1; 5282END| 5283ERROR HY000: String '1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY' is too long for host name (should be no longer than 60) 5284drop procedure if exists bug21416| 5285create procedure bug21416() show create procedure bug21416| 5286call bug21416()| 5287Procedure sql_mode Create Procedure character_set_client collation_connection Database Collation 5288bug21416 CREATE DEFINER=`root`@`localhost` PROCEDURE `bug21416`() 5289show create procedure bug21416 latin1 latin1_swedish_ci latin1_swedish_ci 5290drop procedure bug21416| 5291DROP PROCEDURE IF EXISTS bug21414| 5292CREATE PROCEDURE bug21414() SELECT 1| 5293FLUSH TABLES WITH READ LOCK| 5294DROP PROCEDURE bug21414| 5295ERROR HY000: Can't execute the query because you have a conflicting read lock 5296UNLOCK TABLES| 5297The following should succeed. 5298DROP PROCEDURE bug21414| 5299set names utf8| 5300drop database if exists това_е_дълго_име_за_база_данни_нали| 5301create database това_е_дълго_име_за_база_данни_нали| 5302INSERT INTO mysql.proc VALUES ('това_е_дълго_име_за_база_данни_нали','това_е_процедура_с_доста_дълго_име_нали_и_още_по_дълго','PROCEDURE','това_е_процедура_с_доста_дълго_име_нали_и_още_по_дълго','SQL','CONTAINS_SQL','NO','DEFINER','','','bad_body','root@localhost',now(), now(),'','', 'utf8', 'utf8_general_ci', 'utf8_general_ci', 'n/a')| 5303call това_е_дълго_име_за_база_данни_нали.това_е_процедура_с_доста_дълго_име_нали_и_още_по_дълго()| 5304ERROR HY000: Failed to load routine това_е_дълго_име_за_база_данни_нали.това_е_процедура_с_доста_дълго_име_нали_и_още_по_дълго. The table mysql.proc is missing, corrupt, or contains bad data (internal code -6) 5305drop database това_е_дълго_име_за_база_данни_нали| 5306CREATE TABLE t3 ( 5307Member_ID varchar(15) NOT NULL, 5308PRIMARY KEY (Member_ID) 5309)| 5310CREATE TABLE t4 ( 5311ID int(10) unsigned NOT NULL auto_increment, 5312Member_ID varchar(15) NOT NULL default '', 5313Action varchar(12) NOT NULL, 5314Action_Date datetime NOT NULL, 5315Track varchar(15) default NULL, 5316User varchar(12) default NULL, 5317Date_Updated timestamp NOT NULL default CURRENT_TIMESTAMP on update 5318CURRENT_TIMESTAMP, 5319PRIMARY KEY (ID), 5320KEY Action (Action), 5321KEY Action_Date (Action_Date) 5322)| 5323INSERT INTO t3(Member_ID) VALUES 5324('111111'), ('222222'), ('333333'), ('444444'), ('555555'), ('666666')| 5325INSERT INTO t4(Member_ID, Action, Action_Date, Track) VALUES 5326('111111', 'Disenrolled', '2006-03-01', 'CAD' ), 5327('111111', 'Enrolled', '2006-03-01', 'CAD' ), 5328('111111', 'Disenrolled', '2006-07-03', 'CAD' ), 5329('222222', 'Enrolled', '2006-03-07', 'CAD' ), 5330('222222', 'Enrolled', '2006-03-07', 'CHF' ), 5331('222222', 'Disenrolled', '2006-08-02', 'CHF' ), 5332('333333', 'Enrolled', '2006-03-01', 'CAD' ), 5333('333333', 'Disenrolled', '2006-03-01', 'CAD' ), 5334('444444', 'Enrolled', '2006-03-01', 'CAD' ), 5335('555555', 'Disenrolled', '2006-03-01', 'CAD' ), 5336('555555', 'Enrolled', '2006-07-21', 'CAD' ), 5337('555555', 'Disenrolled', '2006-03-01', 'CHF' ), 5338('666666', 'Enrolled', '2006-02-09', 'CAD' ), 5339('666666', 'Enrolled', '2006-05-12', 'CHF' ), 5340('666666', 'Disenrolled', '2006-06-01', 'CAD' )| 5341DROP FUNCTION IF EXISTS bug21493| 5342CREATE FUNCTION bug21493(paramMember VARCHAR(15)) RETURNS varchar(45) 5343BEGIN 5344DECLARE tracks VARCHAR(45); 5345SELECT GROUP_CONCAT(Track SEPARATOR ', ') INTO tracks FROM t4 5346WHERE Member_ID=paramMember AND Action='Enrolled' AND 5347(Track,Action_Date) IN (SELECT Track, MAX(Action_Date) FROM t4 5348WHERE Member_ID=paramMember GROUP BY Track); 5349RETURN tracks; 5350END| 5351SELECT bug21493('111111')| 5352bug21493('111111') 5353NULL 5354SELECT bug21493('222222')| 5355bug21493('222222') 5356CAD 5357SELECT bug21493(Member_ID) FROM t3| 5358bug21493(Member_ID) 5359NULL 5360CAD 5361CAD 5362CAD 5363CAD 5364CHF 5365DROP FUNCTION bug21493| 5366DROP TABLE t3,t4| 5367drop function if exists func_20028_a| 5368drop function if exists func_20028_b| 5369drop function if exists func_20028_c| 5370drop procedure if exists proc_20028_a| 5371drop procedure if exists proc_20028_b| 5372drop procedure if exists proc_20028_c| 5373drop table if exists table_20028| 5374create table table_20028 (i int)| 5375SET @save_sql_mode=@@sql_mode| 5376SET sql_mode=''| 5377create function func_20028_a() returns integer 5378begin 5379declare temp integer; 5380select i into temp from table_20028 limit 1; 5381return ifnull(temp, 0); 5382end| 5383create function func_20028_b() returns integer 5384begin 5385return func_20028_a(); 5386end| 5387create function func_20028_c() returns integer 5388begin 5389declare div_zero integer; 5390set SQL_MODE='TRADITIONAL'; 5391select 1/0 into div_zero; 5392return div_zero; 5393end| 5394create procedure proc_20028_a() 5395begin 5396declare temp integer; 5397select i into temp from table_20028 limit 1; 5398end| 5399create procedure proc_20028_b() 5400begin 5401call proc_20028_a(); 5402end| 5403create procedure proc_20028_c() 5404begin 5405declare div_zero integer; 5406set SQL_MODE='TRADITIONAL'; 5407select 1/0 into div_zero; 5408end| 5409select func_20028_a()| 5410func_20028_a() 54110 5412select func_20028_b()| 5413func_20028_b() 54140 5415select func_20028_c()| 5416ERROR 22012: Division by 0 5417call proc_20028_a()| 5418Warnings: 5419Warning 1329 No data - zero rows fetched, selected, or processed 5420call proc_20028_b()| 5421Warnings: 5422Warning 1329 No data - zero rows fetched, selected, or processed 5423call proc_20028_c()| 5424ERROR 22012: Division by 0 5425SET sql_mode='TRADITIONAL'| 5426drop function func_20028_a| 5427drop function func_20028_b| 5428drop function func_20028_c| 5429drop procedure proc_20028_a| 5430drop procedure proc_20028_b| 5431drop procedure proc_20028_c| 5432create function func_20028_a() returns integer 5433begin 5434declare temp integer; 5435select i into temp from table_20028 limit 1; 5436return ifnull(temp, 0); 5437end| 5438create function func_20028_b() returns integer 5439begin 5440return func_20028_a(); 5441end| 5442create function func_20028_c() returns integer 5443begin 5444declare div_zero integer; 5445set SQL_MODE=''; 5446select 1/0 into div_zero; 5447return div_zero; 5448end| 5449create procedure proc_20028_a() 5450begin 5451declare temp integer; 5452select i into temp from table_20028 limit 1; 5453end| 5454create procedure proc_20028_b() 5455begin 5456call proc_20028_a(); 5457end| 5458create procedure proc_20028_c() 5459begin 5460declare div_zero integer; 5461set SQL_MODE=''; 5462select 1/0 into div_zero; 5463end| 5464select func_20028_a()| 5465func_20028_a() 54660 5467select func_20028_b()| 5468func_20028_b() 54690 5470select func_20028_c()| 5471func_20028_c() 5472NULL 5473call proc_20028_a()| 5474Warnings: 5475Warning 1329 No data - zero rows fetched, selected, or processed 5476call proc_20028_b()| 5477Warnings: 5478Warning 1329 No data - zero rows fetched, selected, or processed 5479call proc_20028_c()| 5480SET @@sql_mode=@save_sql_mode| 5481drop function func_20028_a| 5482drop function func_20028_b| 5483drop function func_20028_c| 5484drop procedure proc_20028_a| 5485drop procedure proc_20028_b| 5486drop procedure proc_20028_c| 5487drop table table_20028| 5488drop procedure if exists proc_21462_a| 5489drop procedure if exists proc_21462_b| 5490create procedure proc_21462_a() 5491begin 5492select "Called A"; 5493end| 5494create procedure proc_21462_b(x int) 5495begin 5496select "Called B"; 5497end| 5498call proc_21462_a| 5499Called A 5500Called A 5501call proc_21462_a()| 5502Called A 5503Called A 5504call proc_21462_a(1)| 5505ERROR 42000: Incorrect number of arguments for PROCEDURE test.proc_21462_a; expected 0, got 1 5506call proc_21462_b| 5507ERROR 42000: Incorrect number of arguments for PROCEDURE test.proc_21462_b; expected 1, got 0 5508call proc_21462_b()| 5509ERROR 42000: Incorrect number of arguments for PROCEDURE test.proc_21462_b; expected 1, got 0 5510call proc_21462_b(1)| 5511Called B 5512Called B 5513drop procedure proc_21462_a| 5514drop procedure proc_21462_b| 5515drop table if exists t3| 5516drop procedure if exists proc_bug19733| 5517create table t3 (s1 int)| 5518create procedure proc_bug19733() 5519begin 5520declare v int default 0; 5521while v < 100 do 5522create index i on t3 (s1); 5523drop index i on t3; 5524set v = v + 1; 5525end while; 5526end| 5527call proc_bug19733()| 5528call proc_bug19733()| 5529call proc_bug19733()| 5530drop procedure proc_bug19733| 5531drop table t3| 5532DROP PROCEDURE IF EXISTS p1| 5533DROP VIEW IF EXISTS v1, v2| 5534DROP TABLE IF EXISTS t3, t4| 5535CREATE TABLE t3 (t3_id INT)| 5536INSERT INTO t3 VALUES (0)| 5537INSERT INTO t3 VALUES (1)| 5538CREATE TABLE t4 (t4_id INT)| 5539INSERT INTO t4 VALUES (2)| 5540CREATE VIEW v1 AS 5541SELECT t3.t3_id, t4.t4_id 5542FROM t3 JOIN t4 ON t3.t3_id = 0| 5543CREATE VIEW v2 AS 5544SELECT t3.t3_id AS t3_id_1, v1.t3_id AS t3_id_2, v1.t4_id 5545FROM t3 LEFT JOIN v1 ON t3.t3_id = 0| 5546CREATE PROCEDURE p1() SELECT * FROM v2| 5547CALL p1()| 5548t3_id_1 t3_id_2 t4_id 55490 0 2 55501 NULL NULL 5551CALL p1()| 5552t3_id_1 t3_id_2 t4_id 55530 0 2 55541 NULL NULL 5555DROP PROCEDURE p1| 5556DROP VIEW v1, v2| 5557DROP TABLE t3, t4| 5558End of 5.0 tests 5559Begin of 5.1 tests 5560drop function if exists pi; 5561create function pi() returns varchar(50) 5562return "pie, my favorite desert."; 5563Warnings: 5564Note 1585 This function 'pi' has the same name as a native function 5565SET @save_sql_mode=@@sql_mode; 5566SET SQL_MODE='IGNORE_SPACE'; 5567select pi(), pi (); 5568pi() pi () 55693.141593 3.141593 5570select test.pi(), test.pi (); 5571test.pi() test.pi () 5572pie, my favorite desert. pie, my favorite desert. 5573SET SQL_MODE=''; 5574select pi(), pi (); 5575pi() pi () 55763.141593 3.141593 5577select test.pi(), test.pi (); 5578test.pi() test.pi () 5579pie, my favorite desert. pie, my favorite desert. 5580SET @@sql_mode=@save_sql_mode; 5581drop function pi; 5582drop function if exists test.database; 5583drop function if exists test.current_user; 5584drop function if exists test.md5; 5585create database nowhere; 5586use nowhere; 5587drop database nowhere; 5588SET @save_sql_mode=@@sql_mode; 5589SET SQL_MODE='IGNORE_SPACE'; 5590select database(), database (); 5591database() database () 5592NULL NULL 5593select current_user(), current_user (); 5594current_user() current_user () 5595root@localhost root@localhost 5596select md5("aaa"), md5 ("aaa"); 5597md5("aaa") md5 ("aaa") 559847bce5c74f589f4867dbd57e9ca9f808 47bce5c74f589f4867dbd57e9ca9f808 5599SET SQL_MODE=''; 5600select database(), database (); 5601database() database () 5602NULL NULL 5603select current_user(), current_user (); 5604current_user() current_user () 5605root@localhost root@localhost 5606select md5("aaa"), md5 ("aaa"); 5607md5("aaa") md5 ("aaa") 560847bce5c74f589f4867dbd57e9ca9f808 47bce5c74f589f4867dbd57e9ca9f808 5609use test; 5610create function `database`() returns varchar(50) 5611return "Stored function database"; 5612Warnings: 5613Note 1585 This function 'database' has the same name as a native function 5614create function `current_user`() returns varchar(50) 5615return "Stored function current_user"; 5616Warnings: 5617Note 1585 This function 'current_user' has the same name as a native function 5618create function md5(x varchar(50)) returns varchar(50) 5619return "Stored function md5"; 5620Warnings: 5621Note 1585 This function 'md5' has the same name as a native function 5622SET SQL_MODE='IGNORE_SPACE'; 5623select database(), database (); 5624database() database () 5625test test 5626select current_user(), current_user (); 5627current_user() current_user () 5628root@localhost root@localhost 5629select md5("aaa"), md5 ("aaa"); 5630md5("aaa") md5 ("aaa") 563147bce5c74f589f4867dbd57e9ca9f808 47bce5c74f589f4867dbd57e9ca9f808 5632select test.database(), test.database (); 5633test.database() test.database () 5634Stored function database Stored function database 5635select test.current_user(), test.current_user (); 5636test.current_user() test.current_user () 5637Stored function current_user Stored function current_user 5638select test.md5("aaa"), test.md5 ("aaa"); 5639test.md5("aaa") test.md5 ("aaa") 5640Stored function md5 Stored function md5 5641SET SQL_MODE=''; 5642select database(), database (); 5643database() database () 5644test test 5645select current_user(), current_user (); 5646current_user() current_user () 5647root@localhost root@localhost 5648select md5("aaa"), md5 ("aaa"); 5649md5("aaa") md5 ("aaa") 565047bce5c74f589f4867dbd57e9ca9f808 47bce5c74f589f4867dbd57e9ca9f808 5651select test.database(), test.database (); 5652test.database() test.database () 5653Stored function database Stored function database 5654select test.current_user(), test.current_user (); 5655test.current_user() test.current_user () 5656Stored function current_user Stored function current_user 5657select test.md5("aaa"), test.md5 ("aaa"); 5658test.md5("aaa") test.md5 ("aaa") 5659Stored function md5 Stored function md5 5660SET @@sql_mode=@save_sql_mode; 5661drop function test.database; 5662drop function test.current_user; 5663drop function md5; 5664use test; 5665End of 5.1 tests 5666DROP TABLE IF EXISTS bug23760| 5667DROP TABLE IF EXISTS bug23760_log| 5668DROP PROCEDURE IF EXISTS bug23760_update_log| 5669DROP PROCEDURE IF EXISTS bug23760_test_row_count| 5670DROP FUNCTION IF EXISTS bug23760_rc_test| 5671CREATE TABLE bug23760 ( 5672id INT NOT NULL AUTO_INCREMENT , 5673num INT NOT NULL , 5674PRIMARY KEY ( id ) 5675)| 5676CREATE TABLE bug23760_log ( 5677id INT NOT NULL AUTO_INCREMENT , 5678reason VARCHAR(50)NULL , 5679ammount INT NOT NULL , 5680PRIMARY KEY ( id ) 5681)| 5682CREATE PROCEDURE bug23760_update_log(r Varchar(50), a INT) 5683BEGIN 5684INSERT INTO bug23760_log (reason, ammount) VALUES(r, a); 5685END| 5686CREATE PROCEDURE bug23760_test_row_count() 5687BEGIN 5688UPDATE bug23760 SET num = num + 1; 5689CALL bug23760_update_log('Test is working', ROW_COUNT()); 5690UPDATE bug23760 SET num = num - 1; 5691END| 5692CREATE PROCEDURE bug23760_test_row_count2(level INT) 5693BEGIN 5694IF level THEN 5695UPDATE bug23760 SET num = num + 1; 5696CALL bug23760_update_log('Test2 is working', ROW_COUNT()); 5697CALL bug23760_test_row_count2(level - 1); 5698END IF; 5699END| 5700CREATE FUNCTION bug23760_rc_test(in_var INT) RETURNS INT RETURN in_var| 5701INSERT INTO bug23760 (num) VALUES (0), (1), (1), (2), (3), (5), (8)| 5702SELECT ROW_COUNT()| 5703ROW_COUNT() 57047 5705CALL bug23760_test_row_count()| 5706SELECT * FROM bug23760_log ORDER BY id| 5707id reason ammount 57081 Test is working 7 5709SET @save_max_sp_recursion= @@max_sp_recursion_depth| 5710SELECT @save_max_sp_recursion| 5711@save_max_sp_recursion 57120 5713SET max_sp_recursion_depth= 5| 5714SELECT @@max_sp_recursion_depth| 5715@@max_sp_recursion_depth 57165 5717CALL bug23760_test_row_count2(2)| 5718SELECT ROW_COUNT()| 5719ROW_COUNT() 57201 5721SELECT * FROM bug23760_log ORDER BY id| 5722id reason ammount 57231 Test is working 7 57242 Test2 is working 7 57253 Test2 is working 7 5726SELECT * FROM bug23760 ORDER by ID| 5727id num 57281 2 57292 3 57303 3 57314 4 57325 5 57336 7 57347 10 5735SET max_sp_recursion_depth= @save_max_sp_recursion| 5736SELECT bug23760_rc_test(123)| 5737bug23760_rc_test(123) 5738123 5739INSERT INTO bug23760 (num) VALUES (13), (21), (34), (55)| 5740SELECT bug23760_rc_test(ROW_COUNT())| 5741bug23760_rc_test(ROW_COUNT()) 57424 5743DROP TABLE bug23760, bug23760_log| 5744DROP PROCEDURE bug23760_update_log| 5745DROP PROCEDURE bug23760_test_row_count| 5746DROP PROCEDURE bug23760_test_row_count2| 5747DROP FUNCTION bug23760_rc_test| 5748DROP PROCEDURE IF EXISTS bug24117| 5749DROP TABLE IF EXISTS t3| 5750CREATE TABLE t3(c1 ENUM('abc'))| 5751INSERT INTO t3 VALUES('abc')| 5752CREATE PROCEDURE bug24117() 5753BEGIN 5754DECLARE t3c1 ENUM('abc'); 5755DECLARE mycursor CURSOR FOR SELECT c1 FROM t3; 5756OPEN mycursor; 5757FLUSH TABLES; 5758FETCH mycursor INTO t3c1; 5759CLOSE mycursor; 5760END| 5761CALL bug24117()| 5762DROP PROCEDURE bug24117| 5763DROP TABLE t3| 5764drop function if exists func_8407_a| 5765drop function if exists func_8407_b| 5766create function func_8407_a() returns int 5767begin 5768declare x int; 5769declare continue handler for sqlexception 5770begin 5771end; 5772select 1 from no_such_view limit 1 into x; 5773return x; 5774end| 5775create function func_8407_b() returns int 5776begin 5777declare x int default 0; 5778declare continue handler for sqlstate '42S02' 5779 begin 5780set x:= x+1000; 5781end; 5782case (select 1 from no_such_view limit 1) 5783when 1 then set x:= x+1; 5784when 2 then set x:= x+2; 5785else set x:= x+100; 5786end case; 5787set x:=x + 500; 5788return x; 5789end| 5790select func_8407_a()| 5791func_8407_a() 5792NULL 5793select func_8407_b()| 5794func_8407_b() 57951500 5796drop function func_8407_a| 5797drop function func_8407_b| 5798drop table if exists table_26503| 5799drop procedure if exists proc_26503_ok_1| 5800drop procedure if exists proc_26503_ok_2| 5801drop procedure if exists proc_26503_ok_3| 5802drop procedure if exists proc_26503_ok_4| 5803create table table_26503(a int unique)| 5804create procedure proc_26503_ok_1(v int) 5805begin 5806declare i int default 5; 5807declare continue handler for sqlexception 5808begin 5809select 'caught something'; 5810retry: 5811while i > 0 do 5812begin 5813set i = i - 1; 5814select 'looping', i; 5815iterate retry; 5816select 'dead code'; 5817end; 5818end while retry; 5819select 'leaving handler'; 5820end; 5821select 'do something'; 5822insert into table_26503 values (v); 5823select 'do something again'; 5824insert into table_26503 values (v); 5825end| 5826create procedure proc_26503_ok_2(v int) 5827begin 5828declare i int default 5; 5829declare continue handler for sqlexception 5830begin 5831select 'caught something'; 5832retry: 5833while i > 0 do 5834begin 5835set i = i - 1; 5836select 'looping', i; 5837leave retry; 5838select 'dead code'; 5839end; 5840end while; 5841select 'leaving handler'; 5842end; 5843select 'do something'; 5844insert into table_26503 values (v); 5845select 'do something again'; 5846insert into table_26503 values (v); 5847end| 5848create procedure proc_26503_ok_3(v int) 5849begin 5850declare i int default 5; 5851retry: 5852begin 5853declare continue handler for sqlexception 5854begin 5855select 'caught something'; 5856retry: 5857while i > 0 do 5858begin 5859set i = i - 1; 5860select 'looping', i; 5861iterate retry; 5862select 'dead code'; 5863end; 5864end while retry; 5865select 'leaving handler'; 5866end; 5867select 'do something'; 5868insert into table_26503 values (v); 5869select 'do something again'; 5870insert into table_26503 values (v); 5871end; 5872end| 5873create procedure proc_26503_ok_4(v int) 5874begin 5875declare i int default 5; 5876retry: 5877begin 5878declare continue handler for sqlexception 5879begin 5880select 'caught something'; 5881retry: 5882while i > 0 do 5883begin 5884set i = i - 1; 5885select 'looping', i; 5886leave retry; 5887select 'dead code'; 5888end; 5889end while; 5890select 'leaving handler'; 5891end; 5892select 'do something'; 5893insert into table_26503 values (v); 5894select 'do something again'; 5895insert into table_26503 values (v); 5896end; 5897end| 5898call proc_26503_ok_1(1)| 5899do something 5900do something 5901do something again 5902do something again 5903caught something 5904caught something 5905looping i 5906looping 4 5907looping i 5908looping 3 5909looping i 5910looping 2 5911looping i 5912looping 1 5913looping i 5914looping 0 5915leaving handler 5916leaving handler 5917call proc_26503_ok_2(2)| 5918do something 5919do something 5920do something again 5921do something again 5922caught something 5923caught something 5924looping i 5925looping 4 5926leaving handler 5927leaving handler 5928call proc_26503_ok_3(3)| 5929do something 5930do something 5931do something again 5932do something again 5933caught something 5934caught something 5935looping i 5936looping 4 5937looping i 5938looping 3 5939looping i 5940looping 2 5941looping i 5942looping 1 5943looping i 5944looping 0 5945leaving handler 5946leaving handler 5947call proc_26503_ok_4(4)| 5948do something 5949do something 5950do something again 5951do something again 5952caught something 5953caught something 5954looping i 5955looping 4 5956leaving handler 5957leaving handler 5958drop table table_26503| 5959drop procedure proc_26503_ok_1| 5960drop procedure proc_26503_ok_2| 5961drop procedure proc_26503_ok_3| 5962drop procedure proc_26503_ok_4| 5963DROP FUNCTION IF EXISTS bug25373| 5964CREATE FUNCTION bug25373(p1 INTEGER) RETURNS INTEGER 5965LANGUAGE SQL DETERMINISTIC 5966RETURN p1;| 5967CREATE TABLE t3 (f1 INT, f2 FLOAT)| 5968INSERT INTO t3 VALUES (1, 3.4), (1, 2), (1, 0.9), (2, 8), (2, 7)| 5969SELECT SUM(f2), bug25373(f1) FROM t3 GROUP BY bug25373(f1) WITH ROLLUP| 5970SUM(f2) bug25373(f1) 59716.300000071525574 1 597215 2 597321.300000071525574 NULL 5974DROP FUNCTION bug25373| 5975DROP TABLE t3| 5976DROP DATABASE IF EXISTS mysqltest1| 5977DROP DATABASE IF EXISTS mysqltest2| 5978CREATE DATABASE mysqltest1| 5979CREATE DATABASE mysqltest2| 5980CREATE PROCEDURE mysqltest1.p1() 5981DROP DATABASE mysqltest2| 5982use mysqltest2| 5983CALL mysqltest1.p1()| 5984Warnings: 5985Note 1049 Unknown database 'mysqltest2' 5986SELECT DATABASE()| 5987DATABASE() 5988NULL 5989DROP DATABASE mysqltest1| 5990use test| 5991drop function if exists bug20777| 5992drop table if exists examplebug20777| 5993create function bug20777(f1 bigint unsigned) returns bigint unsigned 5994begin 5995set f1 = (f1 - 10); set f1 = (f1 + 10); 5996return f1; 5997end| 5998select bug20777(9223372036854775803) as '9223372036854775803 2**63-5'; 59999223372036854775803 2**63-5 60009223372036854775803 6001select bug20777(9223372036854775804) as '9223372036854775804 2**63-4'; 60029223372036854775804 2**63-4 60039223372036854775804 6004select bug20777(9223372036854775805) as '9223372036854775805 2**63-3'; 60059223372036854775805 2**63-3 60069223372036854775805 6007select bug20777(9223372036854775806) as '9223372036854775806 2**63-2'; 60089223372036854775806 2**63-2 60099223372036854775806 6010select bug20777(9223372036854775807) as '9223372036854775807 2**63-1'; 60119223372036854775807 2**63-1 60129223372036854775807 6013select bug20777(9223372036854775808) as '9223372036854775808 2**63+0'; 60149223372036854775808 2**63+0 60159223372036854775808 6016select bug20777(9223372036854775809) as '9223372036854775809 2**63+1'; 60179223372036854775809 2**63+1 60189223372036854775809 6019select bug20777(9223372036854775810) as '9223372036854775810 2**63+2'; 60209223372036854775810 2**63+2 60219223372036854775810 6022select bug20777(-9223372036854775808) as 'lower bounds signed bigint'; 6023ERROR 22003: BIGINT UNSIGNED value is out of range in '(f1@0 - 10)' 6024select bug20777(9223372036854775807) as 'upper bounds signed bigint'; 6025upper bounds signed bigint 60269223372036854775807 6027select bug20777(0) as 'lower bounds unsigned bigint'; 6028ERROR 22003: BIGINT UNSIGNED value is out of range in '(f1@0 - 10)' 6029select bug20777(18446744073709551615) as 'upper bounds unsigned bigint'; 6030upper bounds unsigned bigint 603118446744073709551615 6032select bug20777(18446744073709551616) as 'upper bounds unsigned bigint + 1'; 6033upper bounds unsigned bigint + 1 603418446744073709551615 6035Warnings: 6036Warning 1264 Out of range value for column 'f1' at row 1 6037select bug20777(-1) as 'lower bounds unsigned bigint - 1'; 6038ERROR 22003: BIGINT UNSIGNED value is out of range in '(f1@0 - 10)' 6039create table examplebug20777 as select 60400 as 'i', 6041bug20777(9223372036854775806) as '2**63-2', 6042bug20777(9223372036854775807) as '2**63-1', 6043bug20777(9223372036854775808) as '2**63', 6044bug20777(9223372036854775809) as '2**63+1', 6045bug20777(18446744073709551614) as '2**64-2', 6046bug20777(18446744073709551615) as '2**64-1', 6047bug20777(18446744073709551616) as '2**64'; 6048Warnings: 6049Warning 1264 Out of range value for column 'f1' at row 1 6050insert into examplebug20777 values (1, 9223372036854775806, 9223372036854775807, 223372036854775808, 9223372036854775809, 18446744073709551614, 18446744073709551615, 8446744073709551616); 6051show create table examplebug20777; 6052Table Create Table 6053examplebug20777 CREATE TABLE `examplebug20777` ( 6054 `i` int(1) NOT NULL DEFAULT '0', 6055 `2**63-2` bigint(20) unsigned DEFAULT NULL, 6056 `2**63-1` bigint(20) unsigned DEFAULT NULL, 6057 `2**63` bigint(20) unsigned DEFAULT NULL, 6058 `2**63+1` bigint(20) unsigned DEFAULT NULL, 6059 `2**64-2` bigint(20) unsigned DEFAULT NULL, 6060 `2**64-1` bigint(20) unsigned DEFAULT NULL, 6061 `2**64` bigint(20) unsigned DEFAULT NULL 6062) ENGINE=MyISAM DEFAULT CHARSET=latin1 6063select * from examplebug20777 order by i; 6064i 2**63-2 2**63-1 2**63 2**63+1 2**64-2 2**64-1 2**64 60650 9223372036854775806 9223372036854775807 9223372036854775808 9223372036854775809 18446744073709551614 18446744073709551615 18446744073709551615 60661 9223372036854775806 9223372036854775807 223372036854775808 9223372036854775809 18446744073709551614 18446744073709551615 8446744073709551616 6067drop table examplebug20777; 6068select bug20777(18446744073709551613)+1; 6069bug20777(18446744073709551613)+1 607018446744073709551614 6071drop function bug20777; 6072DROP FUNCTION IF EXISTS bug5274_f1| 6073DROP FUNCTION IF EXISTS bug5274_f2| 6074CREATE FUNCTION bug5274_f1(p1 CHAR) RETURNS CHAR 6075RETURN CONCAT(p1, p1)| 6076CREATE FUNCTION bug5274_f2() RETURNS CHAR 6077BEGIN 6078DECLARE v1 INT DEFAULT 0; 6079DECLARE v2 CHAR DEFAULT 'x'; 6080WHILE v1 < 30 DO 6081SET v1 = v1 + 1; 6082SET v2 = bug5274_f1(v2); 6083END WHILE; 6084RETURN v2; 6085END| 6086SELECT bug5274_f2()| 6087bug5274_f2() 6088x 6089DROP FUNCTION bug5274_f1| 6090DROP FUNCTION bug5274_f2| 6091drop procedure if exists proc_21513| 6092create procedure proc_21513()`my_label`:BEGIN END| 6093show create procedure proc_21513| 6094Procedure sql_mode Create Procedure character_set_client collation_connection Database Collation 6095proc_21513 CREATE DEFINER=`root`@`localhost` PROCEDURE `proc_21513`() 6096`my_label`:BEGIN END utf8 utf8_general_ci latin1_swedish_ci 6097drop procedure proc_21513| 6098End of 5.0 tests. 6099drop table t1,t2; 6100CREATE TABLE t1 (a int auto_increment primary key) engine=MyISAM; 6101CREATE TABLE t2 (a int auto_increment primary key, b int) engine=innodb; 6102set @a=0; 6103CREATE function bug27354() RETURNS int not deterministic 6104begin 6105insert into t1 values (null); 6106set @a=@a+1; 6107return @a; 6108end| 6109update t2 set b=1 where a=bug27354(); 6110select count(t_1.a),count(t_2.a) from t1 as t_1, t2 as t_2 /* must be 0,0 */; 6111count(t_1.a) count(t_2.a) 61120 0 6113insert into t2 values (1,1),(2,2),(3,3); 6114update t2 set b=-b where a=bug27354(); 6115select * from t2 /* must return 1,-1 ... */; 6116a b 61171 -1 61182 -2 61193 -3 6120select count(*) from t1 /* must be 3 */; 6121count(*) 61223 6123drop table t1,t2; 6124drop function bug27354; 6125CREATE TABLE t1 (a INT); 6126INSERT INTO t1 VALUES (1),(2); 6127CREATE FUNCTION metered(a INT) RETURNS INT RETURN 12; 6128CREATE VIEW v1 AS SELECT test.metered(a) as metered FROM t1; 6129SHOW CREATE VIEW v1; 6130View Create View character_set_client collation_connection 6131v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `test`.`metered`(`t1`.`a`) AS `metered` from `t1` utf8 utf8_general_ci 6132DROP VIEW v1; 6133DROP FUNCTION metered; 6134DROP TABLE t1; 6135SET @p1_p2_cnt= 2; 6136CREATE TABLE t1 (c1 INT); 6137CREATE VIEW v1 AS SELECT * FROM t1; 6138PREPARE s1 FROM 'SELECT c1 FROM v1'; 6139EXECUTE s1; 6140c1 6141EXECUTE s1; 6142c1 6143CREATE PROCEDURE p1(IN loops BIGINT(19) UNSIGNED) 6144BEGIN 6145WHILE loops > 0 DO 6146SELECT c1 FROM v1; 6147SET loops = loops - 1; 6148END WHILE; 6149END| 6150CREATE PROCEDURE p2(IN loops BIGINT(19) UNSIGNED) 6151BEGIN 6152WHILE loops > 0 DO 6153SELECT c1 FROM v1; 6154CALL p1(@p1_p2_cnt); 6155SET loops = loops - 1; 6156END WHILE; 6157END| 6158CREATE FUNCTION f1(loops INT UNSIGNED) 6159RETURNS INT 6160BEGIN 6161DECLARE tmp INT; 6162WHILE loops > 0 DO 6163SELECT c1 INTO tmp FROM v1; 6164SET loops = loops - 1; 6165END WHILE; 6166RETURN loops; 6167END| 6168CALL p1(2); 6169c1 6170c1 6171CALL p2(2); 6172c1 6173c1 6174c1 6175c1 6176c1 6177c1 6178SELECT f1(2); 6179f1(2) 61800 6181PREPARE s1 FROM 'SELECT f1(2)'; 6182EXECUTE s1; 6183f1(2) 61840 6185EXECUTE s1; 6186f1(2) 61870 6188DROP PROCEDURE p1; 6189DROP PROCEDURE p2; 6190DROP FUNCTION f1; 6191DROP VIEW v1; 6192DROP TABLE t1; 6193drop database if exists mysqltest_db1; 6194create database mysqltest_db1; 6195create procedure mysqltest_db1.sp_bug28551() begin end; 6196call mysqltest_db1.sp_bug28551(); 6197show warnings; 6198Level Code Message 6199Note 1008 Can't drop database 'mysqltest_db1'; database doesn't exist 6200drop database mysqltest_db1; 6201drop database if exists mysqltest_db1; 6202drop table if exists test.t1; 6203create database mysqltest_db1; 6204use mysqltest_db1; 6205drop database mysqltest_db1; 6206create table test.t1 (id int); 6207insert into test.t1 (id) values (1); 6208create procedure test.sp_bug29050() begin select * from t1; end// 6209show warnings; 6210Level Code Message 6211call test.sp_bug29050(); 6212id 62131 6214show warnings; 6215Level Code Message 6216use test; 6217drop procedure sp_bug29050; 6218drop table t1; 6219SET NAMES latin1; 6220CREATE PROCEDURE p1() 6221BEGIN 6222DECLARE ��� INT; 6223SELECT ���; 6224END| 6225CALL p1(); 6226��� 6227NULL 6228SET NAMES default; 6229DROP PROCEDURE p1; 6230drop procedure if exists proc_25411_a; 6231drop procedure if exists proc_25411_b; 6232drop procedure if exists proc_25411_c; 6233create procedure proc_25411_a() 6234begin 6235/* real comment */ 6236select 1; 6237/*! select 2; */ 6238select 3; 6239/*!00000 select 4; */ 6240/*!99999 select 5; */ 6241end 6242$$ 6243create procedure proc_25411_b( 6244/* real comment */ 6245/*! p1 int, */ 6246/*!00000 p2 int */ 6247/*!99999 ,p3 int */ 6248) 6249begin 6250select p1, p2; 6251end 6252$$ 6253create procedure proc_25411_c() 6254begin 6255select 1/*!,2*//*!00000,3*//*!99999,4*/; 6256select 1/*! ,2*//*!00000 ,3*//*!99999 ,4*/; 6257select 1/*!,2 *//*!00000,3 *//*!99999,4 */; 6258select 1/*! ,2 *//*!00000 ,3 *//*!99999 ,4 */; 6259select 1 /*!,2*/ /*!00000,3*/ /*!99999,4*/ ; 6260end 6261$$ 6262show create procedure proc_25411_a; 6263Procedure sql_mode Create Procedure character_set_client collation_connection Database Collation 6264proc_25411_a CREATE DEFINER=`root`@`localhost` PROCEDURE `proc_25411_a`() 6265begin 6266/* real comment */ 6267select 1; 6268 select 2; 6269select 3; 6270 select 4; 6271 6272end latin1 latin1_swedish_ci latin1_swedish_ci 6273call proc_25411_a(); 62741 62751 62762 62772 62783 62793 62804 62814 6282show create procedure proc_25411_b; 6283Procedure sql_mode Create Procedure character_set_client collation_connection Database Collation 6284proc_25411_b CREATE DEFINER=`root`@`localhost` PROCEDURE `proc_25411_b`( 6285/* real comment */ 6286 p1 int, 6287 p2 int 6288 6289) 6290begin 6291select p1, p2; 6292end latin1 latin1_swedish_ci latin1_swedish_ci 6293select name, param_list, body from mysql.proc where name like "%25411%"; 6294name param_list body 6295proc_25411_a begin 6296/* real comment */ 6297select 1; 6298 select 2; 6299select 3; 6300 select 4; 6301 6302end 6303proc_25411_b 6304/* real comment */ 6305 p1 int, 6306 p2 int 6307 6308 begin 6309select p1, p2; 6310end 6311proc_25411_c begin 6312select 1,2 ,3 ; 6313select 1 ,2 ,3 ; 6314select 1,2 ,3 ; 6315select 1 ,2 ,3 ; 6316select 1 ,2 ,3 ; 6317end 6318call proc_25411_b(10, 20); 6319p1 p2 632010 20 6321show create procedure proc_25411_c; 6322Procedure sql_mode Create Procedure character_set_client collation_connection Database Collation 6323proc_25411_c CREATE DEFINER=`root`@`localhost` PROCEDURE `proc_25411_c`() 6324begin 6325select 1,2 ,3 ; 6326select 1 ,2 ,3 ; 6327select 1,2 ,3 ; 6328select 1 ,2 ,3 ; 6329select 1 ,2 ,3 ; 6330end latin1 latin1_swedish_ci latin1_swedish_ci 6331call proc_25411_c(); 63321 2 3 63331 2 3 63341 2 3 63351 2 3 63361 2 3 63371 2 3 63381 2 3 63391 2 3 63401 2 3 63411 2 3 6342drop procedure proc_25411_a; 6343drop procedure proc_25411_b; 6344drop procedure proc_25411_c; 6345drop procedure if exists proc_26302; 6346create procedure proc_26302() 6347select 1 /* testing */; 6348show create procedure proc_26302; 6349Procedure sql_mode Create Procedure character_set_client collation_connection Database Collation 6350proc_26302 CREATE DEFINER=`root`@`localhost` PROCEDURE `proc_26302`() 6351select 1 /* testing */ latin1 latin1_swedish_ci latin1_swedish_ci 6352select ROUTINE_NAME, ROUTINE_DEFINITION from information_schema.ROUTINES 6353where ROUTINE_NAME = "proc_26302"; 6354ROUTINE_NAME ROUTINE_DEFINITION 6355proc_26302 select 1 /* testing */ 6356drop procedure proc_26302; 6357CREATE FUNCTION f1() RETURNS INT DETERMINISTIC RETURN 2; 6358CREATE FUNCTION f2(I INT) RETURNS INT DETERMINISTIC RETURN 3; 6359CREATE TABLE t1 (c1 INT, INDEX(c1)); 6360INSERT INTO t1 VALUES (1), (2), (3), (4), (5); 6361CREATE VIEW v1 AS SELECT c1 FROM t1; 6362EXPLAIN SELECT * FROM t1 WHERE c1=1; 6363id select_type table type possible_keys key key_len ref rows Extra 63641 SIMPLE t1 ref c1 c1 5 const 1 Using index 6365EXPLAIN SELECT * FROM t1 WHERE c1=f1(); 6366id select_type table type possible_keys key key_len ref rows Extra 63671 SIMPLE t1 ref c1 c1 5 const 1 Using index 6368EXPLAIN SELECT * FROM v1 WHERE c1=1; 6369id select_type table type possible_keys key key_len ref rows Extra 63701 SIMPLE t1 ref c1 c1 5 const 1 Using index 6371EXPLAIN SELECT * FROM v1 WHERE c1=f1(); 6372id select_type table type possible_keys key key_len ref rows Extra 63731 SIMPLE t1 ref c1 c1 5 const 1 Using index 6374EXPLAIN SELECT * FROM t1 WHERE c1=f2(10); 6375id select_type table type possible_keys key key_len ref rows Extra 63761 SIMPLE t1 ref c1 c1 5 const 1 Using index 6377EXPLAIN SELECT * FROM t1 WHERE c1=f2(c1); 6378id select_type table type possible_keys key key_len ref rows Extra 63791 SIMPLE t1 index NULL c1 5 NULL 5 Using where; Using index 6380EXPLAIN SELECT * FROM t1 WHERE c1=f2(rand()); 6381id select_type table type possible_keys key key_len ref rows Extra 63821 SIMPLE t1 index NULL c1 5 NULL 5 Using where; Using index 6383DROP VIEW v1; 6384DROP FUNCTION f1; 6385DROP FUNCTION f2; 6386DROP TABLE t1; 6387create function f1() 6388returns int(11) 6389not deterministic 6390contains sql 6391sql security definer 6392comment '' 6393begin 6394declare x int(11); 6395set x=-1; 6396return x; 6397end| 6398create view v1 as select 1 as one, f1() as days; 6399show create view test.v1; 6400View Create View character_set_client collation_connection 6401v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `test`.`v1` AS select 1 AS `one`,`f1`() AS `days` latin1 latin1_swedish_ci 6402select column_name from information_schema.columns 6403where table_name='v1' and table_schema='test'; 6404column_name 6405one 6406days 6407drop view v1; 6408drop function f1; 6409 6410# Bug#13675. 6411 6412DROP PROCEDURE IF EXISTS p1; 6413DROP PROCEDURE IF EXISTS p2; 6414DROP TABLE IF EXISTS t1; 6415 6416CREATE PROCEDURE p1(v DATETIME) CREATE TABLE t1 SELECT v; 6417CREATE PROCEDURE p2(v INT) CREATE TABLE t1 SELECT v; 6418 6419CALL p1(NOW()); 6420SHOW CREATE TABLE t1; 6421Table Create Table 6422t1 CREATE TABLE `t1` ( 6423 `v` datetime DEFAULT NULL 6424) ENGINE=MyISAM DEFAULT CHARSET=latin1 6425 6426DROP TABLE t1; 6427 6428CALL p1('text'); 6429Warnings: 6430Warning 1265 Data truncated for column 'v' at row 1 6431SHOW CREATE TABLE t1; 6432Table Create Table 6433t1 CREATE TABLE `t1` ( 6434 `v` datetime DEFAULT NULL 6435) ENGINE=MyISAM DEFAULT CHARSET=latin1 6436 6437DROP TABLE t1; 6438 6439CALL p2(10); 6440SHOW CREATE TABLE t1; 6441Table Create Table 6442t1 CREATE TABLE `t1` ( 6443 `v` bigint(11) DEFAULT NULL 6444) ENGINE=MyISAM DEFAULT CHARSET=latin1 6445 6446DROP TABLE t1; 6447 6448CALL p2('text'); 6449Warnings: 6450Warning 1366 Incorrect integer value: 'text' for column 'v' at row 1 6451SHOW CREATE TABLE t1; 6452Table Create Table 6453t1 CREATE TABLE `t1` ( 6454 `v` bigint(11) DEFAULT NULL 6455) ENGINE=MyISAM DEFAULT CHARSET=latin1 6456 6457DROP TABLE t1; 6458 6459DROP PROCEDURE p1; 6460DROP PROCEDURE p2; 6461 6462# 6463# Bug#31035. 6464# 6465 6466# 6467# - Prepare. 6468# 6469 6470DROP TABLE IF EXISTS t1; 6471DROP FUNCTION IF EXISTS f1; 6472DROP FUNCTION IF EXISTS f2; 6473DROP FUNCTION IF EXISTS f3; 6474DROP FUNCTION IF EXISTS f4; 6475 6476# 6477# - Create required objects. 6478# 6479 6480CREATE TABLE t1(c1 INT); 6481 6482INSERT INTO t1 VALUES (1), (2), (3); 6483 6484CREATE FUNCTION f1() 6485RETURNS INT 6486NOT DETERMINISTIC 6487RETURN 1; 6488 6489CREATE FUNCTION f2(p INT) 6490RETURNS INT 6491NOT DETERMINISTIC 6492RETURN 1; 6493 6494CREATE FUNCTION f3() 6495RETURNS INT 6496DETERMINISTIC 6497RETURN 1; 6498 6499CREATE FUNCTION f4(p INT) 6500RETURNS INT 6501DETERMINISTIC 6502RETURN 1; 6503 6504# 6505# - Check. 6506# 6507 6508SELECT f1() AS a FROM t1 GROUP BY a; 6509a 65101 6511 6512SELECT f2(@a) AS a FROM t1 GROUP BY a; 6513a 65141 6515 6516SELECT f3() AS a FROM t1 GROUP BY a; 6517a 65181 6519 6520SELECT f4(0) AS a FROM t1 GROUP BY a; 6521a 65221 6523 6524SELECT f4(@a) AS a FROM t1 GROUP BY a; 6525a 65261 6527 6528# 6529# - Cleanup. 6530# 6531 6532DROP TABLE t1; 6533DROP FUNCTION f1; 6534DROP FUNCTION f2; 6535DROP FUNCTION f3; 6536DROP FUNCTION f4; 6537 6538# 6539# Bug#31191. 6540# 6541 6542# 6543# - Prepare. 6544# 6545 6546DROP TABLE IF EXISTS t1; 6547DROP TABLE IF EXISTS t2; 6548DROP FUNCTION IF EXISTS f1; 6549 6550# 6551# - Create required objects. 6552# 6553 6554CREATE TABLE t1 ( 6555id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, 6556barcode INT(8) UNSIGNED ZEROFILL nOT NULL, 6557PRIMARY KEY (id), 6558UNIQUE KEY barcode (barcode) 6559); 6560 6561INSERT INTO t1 (id, barcode) VALUES (1, 12345678); 6562INSERT INTO t1 (id, barcode) VALUES (2, 12345679); 6563 6564CREATE TABLE test.t2 ( 6565id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, 6566barcode BIGINT(11) UNSIGNED ZEROFILL NOT NULL, 6567PRIMARY KEY (id) 6568); 6569 6570INSERT INTO test.t2 (id, barcode) VALUES (1, 12345106708); 6571INSERT INTO test.t2 (id, barcode) VALUES (2, 12345106709); 6572 6573CREATE FUNCTION f1(p INT(8)) 6574RETURNS BIGINT(11) UNSIGNED 6575READS SQL DATA 6576RETURN FLOOR(p/1000)*1000000 + 100000 + FLOOR((p MOD 1000)/10)*100 + (p MOD 10); 6577 6578# 6579# - Check. 6580# 6581 6582SELECT DISTINCT t1.barcode, f1(t1.barcode) 6583FROM t1 6584INNER JOIN t2 6585ON f1(t1.barcode) = t2.barcode 6586WHERE t1.barcode=12345678; 6587barcode f1(t1.barcode) 658812345678 12345106708 6589 6590# 6591# - Cleanup. 6592# 6593 6594DROP TABLE t1; 6595DROP TABLE t2; 6596DROP FUNCTION f1; 6597 6598# 6599# Bug#31226. 6600# 6601 6602# 6603# - Prepare. 6604# 6605 6606DROP TABLE IF EXISTS t1; 6607DROP FUNCTION IF EXISTS f1; 6608 6609# 6610# - Create required objects. 6611# 6612 6613CREATE TABLE t1(id INT); 6614 6615INSERT INTO t1 VALUES (1), (2), (3); 6616 6617CREATE FUNCTION f1() 6618RETURNS DATETIME 6619NOT DETERMINISTIC NO SQL 6620RETURN NOW(); 6621 6622# 6623# - Check. 6624# 6625 6626SELECT f1() FROM t1 GROUP BY 1; 6627f1() 6628<timestamp> 6629 6630# 6631# - Cleanup. 6632# 6633 6634DROP TABLE t1; 6635DROP FUNCTION f1; 6636 6637DROP PROCEDURE IF EXISTS db28318_a.t1; 6638DROP PROCEDURE IF EXISTS db28318_b.t2; 6639DROP DATABASE IF EXISTS db28318_a; 6640DROP DATABASE IF EXISTS db28318_b; 6641CREATE DATABASE db28318_a; 6642CREATE DATABASE db28318_b; 6643CREATE PROCEDURE db28318_a.t1() SELECT "db28318_a.t1"; 6644CREATE PROCEDURE db28318_b.t2() CALL t1(); 6645use db28318_a; 6646CALL db28318_b.t2(); 6647ERROR 42000: PROCEDURE db28318_b.t1 does not exist 6648DROP PROCEDURE db28318_a.t1; 6649DROP PROCEDURE db28318_b.t2; 6650DROP DATABASE db28318_a; 6651DROP DATABASE db28318_b; 6652use test; 6653DROP TABLE IF EXISTS t1; 6654DROP PROCEDURE IF EXISTS bug29770; 6655CREATE TABLE t1(a int); 6656CREATE PROCEDURE bug29770() 6657BEGIN 6658DECLARE CONTINUE HANDLER FOR SQLSTATE '42S22' SET @state:= 'run'; 6659DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET @exception:= 'run'; 6660SELECT x FROM t1; 6661END| 6662CALL bug29770(); 6663SELECT @state, @exception; 6664@state @exception 6665run NULL 6666DROP TABLE t1; 6667DROP PROCEDURE bug29770; 6668use test; 6669drop table if exists t_33618; 6670drop procedure if exists proc_33618; 6671create table t_33618 (`a` int, unique(`a`), `b` varchar(30)) engine=myisam; 6672insert into t_33618 (`a`,`b`) values (1,'1'),(2,'2'); 6673create procedure proc_33618(num int) 6674begin 6675declare count1 int default '0'; 6676declare vb varchar(30); 6677declare last_row int; 6678while(num>=1) do 6679set num=num-1; 6680begin 6681declare cur1 cursor for select `a` from t_33618; 6682declare continue handler for not found set last_row = 1; 6683set last_row:=0; 6684open cur1; 6685rep1: 6686repeat 6687begin 6688declare exit handler for 1062 begin end; 6689fetch cur1 into vb; 6690if (last_row = 1) then 6691leave rep1; 6692end if; 6693end; 6694until last_row=1 6695end repeat; 6696close cur1; 6697end; 6698end while; 6699end// 6700call proc_33618(20); 6701drop table t_33618; 6702drop procedure proc_33618; 6703# 6704# Bug#30787: Stored function ignores user defined alias. 6705# 6706use test; 6707drop function if exists func30787; 6708create table t1(f1 int); 6709insert into t1 values(1),(2); 6710create function func30787(p1 int) returns int 6711begin 6712return p1; 6713end | 6714select (select func30787(f1)) as ttt from t1; 6715ttt 67161 67172 6718drop function func30787; 6719drop table t1; 6720CREATE TABLE t1 (id INT); 6721INSERT INTO t1 VALUES (1),(2),(3),(4); 6722CREATE PROCEDURE test_sp() 6723SELECT t1.* FROM t1 RIGHT JOIN t1 t2 ON t1.id=t2.id; 6724CALL test_sp(); 6725id 67261 67272 67283 67294 6730CALL test_sp(); 6731id 67321 67332 67343 67354 6736DROP PROCEDURE test_sp; 6737DROP TABLE t1; 6738create table t1(c1 INT); 6739create function f1(p1 int) returns varchar(32) 6740return 'aaa'; 6741create view v1 as select f1(c1) as parent_control_name from t1; 6742create procedure p1() 6743begin 6744select parent_control_name as c1 from v1; 6745end // 6746call p1(); 6747c1 6748call p1(); 6749c1 6750drop procedure p1; 6751drop function f1; 6752drop view v1; 6753drop table t1; 6754drop procedure if exists `p2` $ 6755create procedure `p2`(in `a` text charset utf8) 6756begin 6757declare `pos` int default 1; 6758declare `str` text charset utf8; 6759set `str` := `a`; 6760select substr(`str`, `pos`+ 1 ) into `str`; 6761end $ 6762call `p2`('s s s s s s'); 6763drop procedure `p2`; 6764drop table if exists t1; 6765drop procedure if exists p1; 6766create procedure p1() begin select * from t1; end$ 6767call p1$ 6768ERROR 42S02: Table 'test.t1' doesn't exist 6769create table t1 (a integer)$ 6770call p1$ 6771a 6772alter table t1 add b integer; 6773call p1$ 6774a b 6775drop table t1; 6776drop procedure p1; 6777# ------------------------------------------------------------------ 6778# -- End of 5.0 tests 6779# ------------------------------------------------------------------ 6780 6781# 6782# Bug#20550. 6783# 6784 6785# 6786# - Prepare. 6787# 6788 6789DROP VIEW IF EXISTS v1; 6790DROP VIEW IF EXISTS v2; 6791DROP FUNCTION IF EXISTS f1; 6792DROP FUNCTION IF EXISTS f2; 6793 6794# 6795# - Create required objects. 6796# 6797 6798CREATE FUNCTION f1() RETURNS VARCHAR(65525) RETURN 'Hello'; 6799 6800CREATE FUNCTION f2() RETURNS TINYINT RETURN 1; 6801 6802CREATE VIEW v1 AS SELECT f1(); 6803 6804CREATE VIEW v2 AS SELECT f2(); 6805 6806# 6807# - Check. 6808# 6809 6810SELECT DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'v1'; 6811DATA_TYPE 6812varchar 6813 6814SELECT DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'v2'; 6815DATA_TYPE 6816tinyint 6817 6818# 6819# - Cleanup. 6820# 6821 6822DROP FUNCTION f1; 6823DROP FUNCTION f2; 6824DROP VIEW v1; 6825DROP VIEW v2; 6826 6827# 6828# - Bug#24923: prepare. 6829# 6830 6831DROP FUNCTION IF EXISTS f1; 6832 6833# 6834# - Bug#24923: create required objects. 6835# 6836 6837CREATE FUNCTION f1(p INT) 6838RETURNS ENUM ('Very_long_enum_element_identifier', 6839'Another_very_long_enum_element_identifier') 6840BEGIN 6841CASE p 6842WHEN 1 THEN 6843RETURN 'Very_long_enum_element_identifier'; 6844ELSE 6845RETURN 'Another_very_long_enum_element_identifier'; 6846END CASE; 6847END| 6848 6849# 6850# - Bug#24923: check. 6851# 6852 6853SELECT f1(1); 6854f1(1) 6855Very_long_enum_element_identifier 6856 6857SELECT f1(2); 6858f1(2) 6859Another_very_long_enum_element_identifier 6860 6861SHOW CREATE FUNCTION f1; 6862Function sql_mode Create Function character_set_client collation_connection Database Collation 6863f1 CREATE DEFINER=`root`@`localhost` FUNCTION `f1`(p INT) RETURNS enum('Very_long_enum_element_identifier','Another_very_long_enum_element_identifier') CHARSET latin1 6864BEGIN 6865CASE p 6866WHEN 1 THEN 6867RETURN 'Very_long_enum_element_identifier'; 6868ELSE 6869RETURN 'Another_very_long_enum_element_identifier'; 6870END CASE; 6871END latin1 latin1_swedish_ci latin1_swedish_ci 6872# 6873# - Bug#24923: cleanup. 6874# 6875 6876DROP FUNCTION f1; 6877 6878drop procedure if exists p; 6879set @old_mode= @@sql_mode; 6880set @@sql_mode= cast(pow(2,32)-1 as unsigned integer); 6881Warnings: 6882Warning 1681 'ERROR_FOR_DIVISION_BY_ZERO' is deprecated and will be removed in a future release. 6883Warning 1681 'NO_ZERO_DATE' is deprecated and will be removed in a future release. 6884Warning 1681 'NO_ZERO_IN_DATE' is deprecated and will be removed in a future release. 6885select @@sql_mode into @full_mode; 6886create procedure p() begin end; 6887call p(); 6888set @@sql_mode= @old_mode; 6889select replace(@full_mode, ',,,', ',NOT_USED,') into @full_mode; 6890select replace(@full_mode, 'ALLOW_INVALID_DATES', 'INVALID_DATES') into @full_mode; 6891select name from mysql.proc where name = 'p' and sql_mode = @full_mode; 6892name 6893p 6894drop procedure p; 6895CREATE DEFINER = 'root'@'localhost' PROCEDURE p1() 6896NOT DETERMINISTIC 6897CONTAINS SQL 6898SQL SECURITY DEFINER 6899COMMENT '' 6900BEGIN 6901SHOW TABLE STATUS like 't1'; 6902END;// 6903CREATE TABLE t1 (f1 INT); 6904CALL p1(); 6905CALL p1(); 6906CALL p1(); 6907CALL p1(); 6908DROP PROCEDURE p1; 6909DROP TABLE t1; 6910CREATE TABLE t1 ( f1 integer, primary key (f1)); 6911CREATE TABLE t2 LIKE t1; 6912CREATE TEMPORARY TABLE t3 LIKE t1; 6913CREATE PROCEDURE p1 () BEGIN SELECT f1 FROM t3 AS A WHERE A.f1 IN ( SELECT f1 FROM t3 ) ; 6914END| 6915CALL p1; 6916ERROR HY000: Can't reopen table: 'A' 6917CREATE VIEW t3 AS SELECT f1 FROM t2 A WHERE A.f1 IN ( SELECT f1 FROM t2 ); 6918DROP TABLE t3; 6919CALL p1; 6920f1 6921CALL p1; 6922f1 6923DROP PROCEDURE p1; 6924DROP TABLE t1, t2; 6925DROP VIEW t3; 6926# 6927# Bug #46629: Item_in_subselect::val_int(): Assertion `0' 6928# on subquery inside a SP 6929# 6930CREATE TABLE t1(a INT); 6931CREATE TABLE t2(a INT, b INT PRIMARY KEY); 6932CREATE PROCEDURE p1 () 6933BEGIN 6934SELECT a FROM t1 A WHERE A.b IN (SELECT b FROM t2 AS B); 6935END| 6936CALL p1; 6937ERROR 42S22: Unknown column 'A.b' in 'IN/ALL/ANY subquery' 6938CALL p1; 6939ERROR 42S22: Unknown column 'A.b' in 'IN/ALL/ANY subquery' 6940DROP PROCEDURE p1; 6941DROP TABLE t1, t2; 6942# 6943# Bug#47627: SET @@{global.session}.local_variable in stored routine causes crash 6944# Bug#48626: Crash or lost connection using SET for declared variables with @@ 6945# 6946DROP PROCEDURE IF EXISTS p1; 6947DROP PROCEDURE IF EXISTS p2; 6948DROP PROCEDURE IF EXISTS p3; 6949CREATE PROCEDURE p1() 6950BEGIN 6951DECLARE v INT DEFAULT 0; 6952SET @@SESSION.v= 10; 6953END// 6954ERROR HY000: Unknown system variable 'v' 6955CREATE PROCEDURE p2() 6956BEGIN 6957DECLARE v INT DEFAULT 0; 6958SET v= 10; 6959END// 6960call p2()// 6961CREATE PROCEDURE p3() 6962BEGIN 6963DECLARE v INT DEFAULT 0; 6964SELECT @@SESSION.v; 6965END// 6966ERROR HY000: Unknown system variable 'v' 6967CREATE PROCEDURE p4() 6968BEGIN 6969DECLARE v INT DEFAULT 0; 6970SET @@GLOBAL.v= 10; 6971END// 6972ERROR HY000: Unknown system variable 'v' 6973CREATE PROCEDURE p5() 6974BEGIN 6975DECLARE init_connect INT DEFAULT 0; 6976SET init_connect= 10; 6977SET @@GLOBAL.init_connect= 'SELECT 1'; 6978SET @@SESSION.IDENTITY= 1; 6979SELECT @@SESSION.IDENTITY; 6980SELECT @@GLOBAL.init_connect; 6981SELECT init_connect; 6982END// 6983CREATE PROCEDURE p6() 6984BEGIN 6985DECLARE v INT DEFAULT 0; 6986SET @@v= 0; 6987END// 6988ERROR HY000: Unknown system variable 'v' 6989SET @old_init_connect= @@GLOBAL.init_connect; 6990CALL p5(); 6991@@SESSION.IDENTITY 69921 6993@@GLOBAL.init_connect 6994SELECT 1 6995init_connect 699610 6997SET @@GLOBAL.init_connect= @old_init_connect; 6998DROP PROCEDURE p2; 6999DROP PROCEDURE p5; 7000# 7001# Bug#11840395 (formerly known as bug#60347): 7002# The string "versiondata" seems 7003# to be 'leaking' into the schema name space 7004# 7005DROP DATABASE IF EXISTS mixedCaseDbName; 7006CREATE DATABASE mixedCaseDbName; 7007CREATE PROCEDURE mixedCaseDbName.tryMyProc() begin end| 7008CREATE FUNCTION mixedCaseDbName.tryMyFunc() returns text begin return 'IT WORKS'; end 7009| 7010call mixedCaseDbName.tryMyProc(); 7011select mixedCaseDbName.tryMyFunc(); 7012mixedCaseDbName.tryMyFunc() 7013IT WORKS 7014DROP DATABASE mixedCaseDbName; 7015# 7016# Bug#11766594 59736: SELECT DISTINCT.. INCORRECT RESULT WITH DETERMINISTIC FUNCTION IN WHERE C 7017# 7018CREATE TABLE t1 (a INT, b INT, KEY(b)); 7019CREATE TABLE t2 (c INT, d INT, KEY(c)); 7020INSERT INTO t1 VALUES (1,1),(1,1),(1,2); 7021INSERT INTO t2 VALUES (1,1),(1,2); 7022CREATE FUNCTION f1() RETURNS INT DETERMINISTIC 7023BEGIN 7024DECLARE a int; 7025-- SQL statement inside 7026SELECT 1 INTO a; 7027RETURN a; 7028END $ 7029SELECT COUNT(DISTINCT d) FROM t1, t2 WHERE a = c AND b = f1(); 7030COUNT(DISTINCT d) 70312 7032DROP FUNCTION f1; 7033DROP TABLE t1, t2; 7034# ------------------------------------------------------------------ 7035# -- End of 5.1 tests 7036# ------------------------------------------------------------------ 7037DROP FUNCTION IF EXISTS f1; 7038DROP TABLE IF EXISTS t_non_existing; 7039DROP TABLE IF EXISTS t1; 7040CREATE FUNCTION f1() RETURNS INT 7041BEGIN 7042DECLARE v INT; 7043SELECT a INTO v FROM t_non_existing; 7044RETURN 1; 7045END| 7046CREATE TABLE t1 (a INT) ENGINE = myisam; 7047INSERT INTO t1 VALUES (1); 7048SELECT * FROM t1 WHERE a = f1(); 7049ERROR 42S02: Table 'test.t_non_existing' doesn't exist 7050DROP FUNCTION f1; 7051DROP TABLE t1; 7052DROP PROCEDURE IF EXISTS p1; 7053CREATE PROCEDURE p1(a INT, b CHAR) 7054BEGIN 7055IF a > 0 THEN 7056CALL p1(a-1, 'ab'); 7057ELSE 7058SELECT 1; 7059END IF; 7060END| 7061SET @save_max_sp_recursion= @@max_sp_recursion_depth; 7062SET @@max_sp_recursion_depth= 5; 7063CALL p1(4, 'a'); 70641 70651 7066Warnings: 7067Warning 1265 Data truncated for column 'b' at row 1 7068Warning 1265 Data truncated for column 'b' at row 1 7069Warning 1265 Data truncated for column 'b' at row 1 7070Warning 1265 Data truncated for column 'b' at row 1 7071SET @@max_sp_recursion_depth= @save_max_sp_recursion; 7072DROP PROCEDURE p1; 7073DROP PROCEDURE IF EXISTS p1; 7074CREATE PROCEDURE p1(a CHAR) 7075BEGIN 7076SELECT 1; 7077SELECT CAST('10 ' as UNSIGNED INTEGER); 7078SELECT 1; 7079END| 7080CALL p1('data truncated parameter'); 70811 70821 7083CAST('10 ' as UNSIGNED INTEGER) 708410 70851 70861 7087Warnings: 7088Warning 1265 Data truncated for column 'a' at row 1 7089Warning 1292 Truncated incorrect INTEGER value: '10 ' 7090DROP PROCEDURE p1; 7091DROP PROCEDURE IF EXISTS p1; 7092DROP PROCEDURE IF EXISTS p2; 7093DROP PROCEDURE IF EXISTS p3; 7094DROP PROCEDURE IF EXISTS p4; 7095CREATE PROCEDURE p1() 7096CALL p2()| 7097CREATE PROCEDURE p2() 7098CALL p3()| 7099CREATE PROCEDURE p3() 7100CALL p4()| 7101CREATE PROCEDURE p4() 7102BEGIN 7103SELECT 1; 7104SELECT CAST('10 ' as UNSIGNED INTEGER); 7105SELECT 2; 7106END| 7107CALL p1(); 71081 71091 7110CAST('10 ' as UNSIGNED INTEGER) 711110 71122 71132 7114Warnings: 7115Warning 1292 Truncated incorrect INTEGER value: '10 ' 7116DROP PROCEDURE p1; 7117DROP PROCEDURE p2; 7118DROP PROCEDURE p3; 7119DROP PROCEDURE p4; 7120DROP FUNCTION IF EXISTS f1; 7121DROP FUNCTION IF EXISTS f2; 7122DROP FUNCTION IF EXISTS f3; 7123DROP FUNCTION IF EXISTS f4; 7124DROP TABLE IF EXISTS t1; 7125CREATE TABLE t1 (a CHAR(2)); 7126INSERT INTO t1 VALUES ('aa'); 7127CREATE FUNCTION f1() RETURNS CHAR 7128RETURN (SELECT f2())| 7129CREATE FUNCTION f2() RETURNS CHAR 7130RETURN (SELECT f3())| 7131CREATE FUNCTION f3() RETURNS CHAR 7132RETURN (SELECT f4())| 7133CREATE FUNCTION f4() RETURNS CHAR 7134BEGIN 7135RETURN (SELECT a FROM t1); 7136END| 7137SELECT f1(); 7138f1() 7139a 7140Warnings: 7141Warning 1265 Data truncated for column 'f4()' at row 1 7142DROP FUNCTION f1; 7143DROP FUNCTION f2; 7144DROP FUNCTION f3; 7145DROP FUNCTION f4; 7146DROP TABLE t1; 7147# 7148# Bug#34197: CREATE PROCEDURE fails when COMMENT truncated in non 7149# strict SQL mode 7150# 7151DROP PROCEDURE IF EXISTS p1; 7152CREATE PROCEDURE p1 () 7153COMMENT 7154'12345678901234567890123456789012345678901234567890123456789012345678901234567890' 7155BEGIN 7156END; 7157SELECT comment FROM mysql.proc WHERE name = "p1"; 7158comment 715912345678901234567890123456789012345678901234567890123456789012345678901234567890 7160SELECT routine_comment FROM information_schema.routines WHERE routine_name = "p1"; 7161routine_comment 716212345678901234567890123456789012345678901234567890123456789012345678901234567890 7163DROP PROCEDURE p1; 7164# 7165# Bug #47313 assert in check_key_in_view during CALL procedure 7166# 7167DROP TABLE IF EXISTS t1; 7168DROP VIEW IF EXISTS t1, t2_unrelated; 7169DROP PROCEDURE IF EXISTS p1; 7170CREATE PROCEDURE p1(IN x INT) INSERT INTO t1 VALUES (x); 7171CREATE VIEW t1 AS SELECT 10 AS f1; 7172# t1 refers to the view 7173CALL p1(1); 7174ERROR HY000: The target table t1 of the INSERT is not insertable-into 7175CREATE TEMPORARY TABLE t1 (f1 INT); 7176# t1 still refers to the view since it was inlined 7177CALL p1(2); 7178ERROR HY000: The target table t1 of the INSERT is not insertable-into 7179DROP VIEW t1; 7180# t1 now refers to the temporary table 7181CALL p1(3); 7182# Check which values were inserted into the temp table. 7183SELECT * FROM t1; 7184f1 71853 7186DROP TEMPORARY TABLE t1; 7187DROP PROCEDURE p1; 7188# Now test what happens if the sp cache is invalidated. 7189CREATE PROCEDURE p1(IN x INT) INSERT INTO t1 VALUES (x); 7190CREATE VIEW t1 AS SELECT 10 AS f1; 7191CREATE VIEW v2_unrelated AS SELECT 1 AS r1; 7192# Load the procedure into the sp cache 7193CALL p1(4); 7194ERROR HY000: The target table t1 of the INSERT is not insertable-into 7195CREATE TEMPORARY TABLE t1 (f1 int); 7196ALTER VIEW v2_unrelated AS SELECT 2 AS r1; 7197# Alter view causes the sp cache to be invalidated. 7198# Now t1 refers to the temporary table, not the view. 7199CALL p1(5); 7200# Check which values were inserted into the temp table. 7201SELECT * FROM t1; 7202f1 72035 7204DROP TEMPORARY TABLE t1; 7205DROP VIEW t1, v2_unrelated; 7206DROP PROCEDURE p1; 7207CREATE PROCEDURE p1(IN x INT) INSERT INTO t1 VALUES (x); 7208CREATE TEMPORARY TABLE t1 (f1 INT); 7209# t1 refers to the temporary table 7210CALL p1(6); 7211CREATE VIEW t1 AS SELECT 10 AS f1; 7212# Create view causes the sp cache to be invalidated. 7213# t1 still refers to the temporary table since it shadows the view. 7214CALL p1(7); 7215DROP VIEW t1; 7216# Check which values were inserted into the temp table. 7217SELECT * FROM t1; 7218f1 72196 72207 7221DROP TEMPORARY TABLE t1; 7222DROP PROCEDURE p1; 7223# 7224# Bug #11918 Can't use a declared variable in LIMIT clause 7225# 7226drop table if exists t1; 7227drop procedure if exists p1; 7228create table t1 (c1 int); 7229insert into t1 (c1) values (1), (2), (3), (4), (5); 7230create procedure p1() 7231begin 7232declare a integer; 7233declare b integer; 7234select * from t1 limit a, b; 7235end| 7236# How do we handle NULL limit values? 7237call p1(); 7238c1 7239drop table t1; 7240create table t1 (a int); 7241insert into t1 (a) values (1), (2), (3), (4), (5); 7242# 7243# Do we correctly resolve identifiers in LIMIT? 7244# 7245call p1(); 7246a 7247drop table t1; 7248create table t1 (c1 int); 7249insert into t1 (c1) values (1), (2), (3), (4), (5); 7250drop procedure p1; 7251# Try to create a procedure that 7252# refers to non-existing variables. 7253create procedure p1(p1 integer, p2 integer) 7254select * from t1 limit a, b; 7255ERROR 42000: Undeclared variable: a 7256# 7257# Try to use data types not allowed in LIMIT 7258# 7259create procedure p1(p1 date, p2 date) select * from t1 limit p1, p2; 7260ERROR HY000: A variable of a non-integer based type in LIMIT clause 7261create procedure p1(p1 integer, p2 float) select * from t1 limit p1, p2; 7262ERROR HY000: A variable of a non-integer based type in LIMIT clause 7263create procedure p1(p1 integer, p2 char(1)) select * from t1 limit p1, p2; 7264ERROR HY000: A variable of a non-integer based type in LIMIT clause 7265create procedure p1(p1 varchar(5), p2 char(1)) select * from t1 limit p1, p2; 7266ERROR HY000: A variable of a non-integer based type in LIMIT clause 7267create procedure p1(p1 decimal, p2 decimal) select * from t1 limit p1, p2; 7268ERROR HY000: A variable of a non-integer based type in LIMIT clause 7269create procedure p1(p1 double, p2 double) select * from t1 limit p1, p2; 7270ERROR HY000: A variable of a non-integer based type in LIMIT clause 7271# 7272# Finally, test the valid case. 7273# 7274create procedure p1(p1 integer, p2 integer) 7275select * from t1 limit p1, p2; 7276call p1(NULL, NULL); 7277c1 7278call p1(0, 0); 7279c1 7280call p1(0, -1); 7281c1 72821 72832 72843 72854 72865 7287call p1(-1, 0); 7288c1 7289call p1(-1, -1); 7290c1 7291call p1(0, 1); 7292c1 72931 7294call p1(1, 0); 7295c1 7296call p1(1, 5); 7297c1 72982 72993 73004 73015 7302call p1(3, 2); 7303c1 73044 73055 7306# Try to create a function that 7307# refers to non-existing variables. 7308create function f1(p1 integer, p2 integer) 7309returns int 7310begin 7311declare a int; 7312set a = (select count(*) from t1 limit a, b); 7313return a; 7314end| 7315ERROR 42000: Undeclared variable: b 7316create function f1() 7317returns int 7318begin 7319declare a, b, c int; 7320set a = (select count(*) from t1 limit b, c); 7321return a; 7322end| 7323# How do we handle NULL limit values? 7324select f1(); 7325f1() 7326NULL 7327drop function f1; 7328# 7329# Try to use data types not allowed in LIMIT 7330# 7331create function f1(p1 date, p2 date) 7332returns int 7333begin 7334declare a int; 7335set a = (select count(*) from t1 limit p1, p2); 7336return a; 7337end| 7338ERROR HY000: A variable of a non-integer based type in LIMIT clause 7339create function f1(p1 integer, p2 float) 7340returns int 7341begin 7342declare a int; 7343set a = (select count(*) from t1 limit p1, p2); 7344return a; 7345end| 7346ERROR HY000: A variable of a non-integer based type in LIMIT clause 7347create function f1(p1 integer, p2 char(1)) 7348returns int 7349begin 7350declare a int; 7351set a = (select count(*) from t1 limit p1, p2); 7352return a; 7353end| 7354ERROR HY000: A variable of a non-integer based type in LIMIT clause 7355create function f1(p1 varchar(5), p2 char(1)) 7356returns int 7357begin 7358declare a int; 7359set a = (select count(*) from t1 limit p1, p2); 7360return a; 7361end| 7362ERROR HY000: A variable of a non-integer based type in LIMIT clause 7363create function f1(p1 decimal, p2 decimal) 7364returns int 7365begin 7366declare a int; 7367set a = (select count(*) from t1 limit p1, p2); 7368return a; 7369end| 7370ERROR HY000: A variable of a non-integer based type in LIMIT clause 7371create function f1(p1 double, p2 double) 7372returns int 7373begin 7374declare a int; 7375set a = (select count(*) from t1 limit p1, p2); 7376return a; 7377end| 7378ERROR HY000: A variable of a non-integer based type in LIMIT clause 7379# 7380# Finally, test the valid case. 7381# 7382create function f1(p1 integer, p2 integer) 7383returns int 7384begin 7385declare count int; 7386set count= (select count(*) from (select * from t1 limit p1, p2) t_1); 7387return count; 7388end| 7389select f1(0, 0); 7390f1(0, 0) 73910 7392select f1(0, -1); 7393f1(0, -1) 73945 7395select f1(-1, 0); 7396f1(-1, 0) 73970 7398select f1(-1, -1); 7399f1(-1, -1) 74000 7401select f1(0, 1); 7402f1(0, 1) 74031 7404select f1(1, 0); 7405f1(1, 0) 74060 7407select f1(1, 5); 7408f1(1, 5) 74094 7410select f1(3, 2); 7411f1(3, 2) 74122 7413# Cleanup 7414drop table t1; 7415drop procedure p1; 7416drop function f1; 7417# 7418# BUG#11766234: 59299: ASSERT (TABLE_REF->TABLE || TABLE_REF->VIEW) 7419# FAILS IN SET_FIELD_ITERATOR 7420# 7421CREATE TABLE t1 (a INT); 7422CREATE TABLE t2 (a INT); 7423CREATE VIEW v1 AS SELECT a FROM t2; 7424CREATE PROCEDURE proc() SELECT * FROM t1 NATURAL JOIN v1; 7425ALTER TABLE t2 CHANGE COLUMN a b CHAR; 7426 7427CALL proc(); 7428ERROR HY000: View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them 7429CALL proc(); 7430ERROR HY000: View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them 7431 7432DROP TABLE t1,t2; 7433DROP VIEW v1; 7434DROP PROCEDURE proc; 7435 7436# -- 7437# -- Bug 11765684 - 58674: SP-cache does not detect changes in 7438# -- pre-locking list caused by triggers 7439# --- 7440DROP TABLE IF EXISTS t1; 7441DROP TABLE IF EXISTS t2; 7442DROP TABLE IF EXISTS t3; 7443DROP PROCEDURE IF EXISTS p1; 7444CREATE TABLE t1(a INT); 7445CREATE TABLE t2(a INT); 7446CREATE TABLE t3(a INT); 7447CREATE PROCEDURE p1() 7448INSERT INTO t1(a) VALUES (1); 7449 7450CREATE TRIGGER t1_ai AFTER INSERT ON t1 7451FOR EACH ROW 7452INSERT INTO t2(a) VALUES (new.a); 7453 7454CALL p1(); 7455 7456CREATE TRIGGER t1_bi BEFORE INSERT ON t1 7457FOR EACH ROW 7458INSERT INTO t3(a) VALUES (new.a); 7459 7460CALL p1(); 7461 7462DROP TABLE t1, t2, t3; 7463DROP PROCEDURE p1; 7464 7465 7466# -- 7467# -- Bug#12652769 - 61470: case operator in stored routine retains old 7468# -- value of input parameter 7469# --- 7470DROP TABLE IF EXISTS t1; 7471DROP PROCEDURE IF EXISTS p1; 7472CREATE TABLE t1 (s1 CHAR(5) CHARACTER SET utf8); 7473INSERT INTO t1 VALUES ('a'); 7474CREATE PROCEDURE p1(dt DATETIME, i INT) 7475BEGIN 7476SELECT 7477CASE 7478WHEN i = 1 THEN 2 7479ELSE dt 7480END AS x1; 7481SELECT 7482CASE _latin1'a' 7483 WHEN _utf8'a' THEN 'A' 7484 END AS x2; 7485SELECT 7486CASE _utf8'a' 7487 WHEN _latin1'a' THEN _utf8'A' 7488 END AS x3; 7489SELECT 7490CASE s1 7491WHEN _latin1'a' THEN _latin1'b' 7492 ELSE _latin1'c' 7493 END AS x4 7494FROM t1; 7495END| 7496 7497CALL p1('2011-04-03 05:14:10', 1); 7498x1 74992 7500x2 7501A 7502x3 7503A 7504x4 7505b 7506CALL p1('2011-04-03 05:14:11', 2); 7507x1 75082011-04-03 05:14:11 7509x2 7510A 7511x3 7512A 7513x4 7514b 7515CALL p1('2011-04-03 05:14:12', 2); 7516x1 75172011-04-03 05:14:12 7518x2 7519A 7520x3 7521A 7522x4 7523b 7524CALL p1('2011-04-03 05:14:13', 2); 7525x1 75262011-04-03 05:14:13 7527x2 7528A 7529x3 7530A 7531x4 7532b 7533 7534DROP TABLE t1; 7535DROP PROCEDURE p1; 7536 7537# 7538# Bug#12621017 - Crash if a sp variable is used in the 7539# limit clause of a set statement 7540# 7541DROP TABLE IF EXISTS t1; 7542DROP PROCEDURE IF EXISTS p1; 7543DROP PROCEDURE IF EXISTS p2; 7544CREATE TABLE t1 (c1 INT); 7545INSERT INTO t1 VALUES (1); 7546CREATE PROCEDURE p1() 7547BEGIN 7548DECLARE foo, cnt INT UNSIGNED DEFAULT 1; 7549SET foo = (SELECT MIN(c1) FROM t1 LIMIT cnt); 7550END| 7551CREATE PROCEDURE p2() 7552BEGIN 7553DECLARE iLimit INT; 7554DECLARE iVal INT; 7555DECLARE cur1 CURSOR FOR 7556SELECT c1 FROM t1 7557LIMIT iLimit; 7558SET iLimit=1; 7559OPEN cur1; 7560FETCH cur1 INTO iVal; 7561END| 7562CALL p1(); 7563CALL p2(); 7564DROP PROCEDURE p1; 7565DROP PROCEDURE p2; 7566DROP TABLE t1; 7567 7568# Bug#13805127: Stored program cache produces wrong result in same THD 7569 7570CREATE PROCEDURE p1(x INT UNSIGNED) 7571BEGIN 7572SELECT c1, t2.c2, count(c3) 7573FROM 7574( 7575SELECT 3 as c2 FROM dual WHERE x = 1 7576UNION 7577SELECT 2 FROM dual WHERE x = 1 OR x = 2 7578) AS t1, 7579( 7580SELECT '2012-03-01 01:00:00' AS c1, 3 as c2, 1 as c3 FROM dual 7581UNION 7582SELECT '2012-03-01 02:00:00', 3, 2 FROM dual 7583UNION 7584SELECT '2012-03-01 01:00:00', 2, 1 FROM dual 7585) AS t2 7586WHERE t2.c2 = t1.c2 7587GROUP BY c1, c2 7588; 7589END| 7590 7591CALL p1(1); 7592c1 c2 count(c3) 75932012-03-01 01:00:00 2 1 75942012-03-01 01:00:00 3 1 75952012-03-01 02:00:00 3 1 7596CALL p1(2); 7597c1 c2 count(c3) 75982012-03-01 01:00:00 2 1 7599CALL p1(1); 7600c1 c2 count(c3) 76012012-03-01 01:00:00 2 1 76022012-03-01 01:00:00 3 1 76032012-03-01 02:00:00 3 1 7604DROP PROCEDURE p1; 7605# End of 5.5 test 7606# 7607# Bug#12663165 SP DEAD CODE REMOVAL DOESN'T UNDERSTAND CONTINUE HANDLERS 7608# 7609DROP FUNCTION IF EXISTS f1; 7610CREATE FUNCTION f1() RETURNS INT 7611BEGIN 7612DECLARE CONTINUE HANDLER FOR SQLEXCEPTION BEGIN END; 7613BEGIN 7614DECLARE CONTINUE HANDLER FOR SQLEXCEPTION RETURN f1(); 7615BEGIN 7616DECLARE CONTINUE HANDLER FOR SQLEXCEPTION RETURN f1(); 7617RETURN f1(); 7618END; 7619END; 7620RETURN 1; 7621END $ 7622SELECT f1(); 7623f1() 76241 7625DROP FUNCTION f1; 7626# 7627# Bug#12577230 7628# RERUN OF STORED FUNCTION CAUSES SEGFAULT IN MAKE_JOIN_SELECT 7629# 7630CREATE TABLE t1 (a INT) ENGINE=myisam; 7631INSERT INTO t1 VALUES (1); 7632CREATE VIEW v1 AS SELECT a FROM t1; 7633CREATE PROCEDURE p1() 7634SELECT 1 FROM v1 JOIN t1 ON v1.a 7635WHERE (SELECT 1 FROM t1 WHERE v1.a) 7636; 7637CALL p1(); 76381 76391 7640CALL p1(); 76411 76421 7643DROP PROCEDURE p1; 7644DROP TABLE t1; 7645DROP VIEW v1; 7646# 7647# WL#2111: Add non-reserved ROW_COUNT keyword. 7648# 7649DROP PROCEDURE IF EXISTS p1; 7650CREATE PROCEDURE p1() 7651BEGIN 7652DECLARE row_count INT DEFAULT 1; 7653SELECT row_count; 7654SELECT row_count(); 7655ROW_COUNT: WHILE row_count > 0 DO 7656SET row_count = row_count - 1; 7657END WHILE ROW_COUNT; 7658SELECT ROW_COUNT; 7659END| 7660CALL p1(); 7661row_count 76621 7663row_count() 7664-1 7665ROW_COUNT 76660 7667DROP PROCEDURE p1; 7668# 7669# BUG #11748187 - 35410: STORED FUNCTION: CONFUSING 'ORDER CLAUSE' IN ERROR MESSAGE 7670# 7671DROP FUNCTION if exists f1; 7672CREATE FUNCTION f1 (p_value INT) RETURNS INT DETERMINISTIC RETURN x; 7673SELECT f1(1); 7674ERROR 42S22: Unknown column 'x' in 'field list' 7675DROP FUNCTION f1; 7676# 7677# BUG #12872824 (formerly known as 62125): testing stored function 7678# result for null incorrectly yields 1292 warning. 7679DROP FUNCTION IF EXISTS f1; 7680DROP FUNCTION IF EXISTS f2; 7681DROP FUNCTION IF EXISTS f3; 7682DROP FUNCTION IF EXISTS f4; 7683CREATE FUNCTION f1() RETURNS VARCHAR(1) 7684BEGIN RETURN 'X'; END;/ 7685CREATE FUNCTION f2() RETURNS CHAR(1) 7686BEGIN RETURN 'X'; END;/ 7687CREATE FUNCTION f3() RETURNS VARCHAR(1) 7688BEGIN RETURN NULL; END;/ 7689CREATE FUNCTION f4() RETURNS CHAR(1) 7690BEGIN RETURN NULL; END;/ 7691SELECT f1() IS NULL; 7692f1() IS NULL 76930 7694SELECT f2() IS NULL; 7695f2() IS NULL 76960 7697SELECT f3() IS NULL; 7698f3() IS NULL 76991 7700SELECT f4() IS NULL; 7701f4() IS NULL 77021 7703DROP FUNCTION f1; 7704DROP FUNCTION f2; 7705DROP FUNCTION f3; 7706DROP FUNCTION f4; 7707# 7708# 7709# WL#6230: Remove 'SET = DEFAULT' 7710# 7711CREATE TABLE t1(a INT); 7712CREATE PROCEDURE p(p INT) 7713SET p = DEFAULT| 7714ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 2 7715CREATE PROCEDURE p() 7716BEGIN 7717DECLARE v INT; 7718SET v = DEFAULT; 7719END| 7720ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '; 7721END' at line 4 7722CREATE PROCEDURE p() 7723BEGIN 7724DECLARE v INT DEFAULT 1; 7725SET v = DEFAULT; 7726END| 7727ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '; 7728END' at line 4 7729CREATE PROCEDURE p() 7730BEGIN 7731DECLARE v INT DEFAULT (SELECT * FROM t1); 7732SET v = DEFAULT; 7733END| 7734ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '; 7735END' at line 4 7736CREATE TRIGGER t1_bu BEFORE UPDATE ON t1 FOR EACH ROW 7737BEGIN 7738SET NEW.a = DEFAULT; 7739END| 7740ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '; 7741END' at line 3 7742 7743# Check that setting system variables to DEFAULT still works in SP. 7744 7745CREATE PROCEDURE p1() 7746SET @@default_storage_engine = DEFAULT; 7747SET @default_storage_engine_saved = @@default_storage_engine; 7748SELECT @@default_storage_engine; 7749@@default_storage_engine 7750MyISAM 7751SET @@default_storage_engine = InnoDB; 7752SELECT @@default_storage_engine; 7753@@default_storage_engine 7754InnoDB 7755CALL p1(); 7756SELECT @@default_storage_engine; 7757@@default_storage_engine 7758MyISAM 7759SET @@default_storage_engine = @default_storage_engine_saved; 7760DROP PROCEDURE p1; 7761DROP TABLE t1; 7762 7763# 7764# BUG 16041903: CONTINUE HANDLER NOT INVOKED 7765# IN A STORED FUNCTION AFTER A LOCK WAIT TIMEOUT 7766# 7767 7768# Save and set lock wait timeout 7769SET @lock_wait_timeout_saved= @@lock_wait_timeout; 7770SET @innodb_lock_wait_timeout_saved= @@innodb_lock_wait_timeout; 7771SET @@lock_wait_timeout= 1; 7772SET @@innodb_lock_wait_timeout= 1; 7773 7774# Create a function with exit handler: 7775CREATE FUNCTION f1() RETURNS VARCHAR(20) 7776BEGIN 7777DECLARE EXIT HANDLER FOR SQLSTATE '42S02' RETURN 'No such table'; 7778INSERT INTO no_such_table VALUES (1); 7779END// 7780 7781# Create a function calling f1(): 7782CREATE FUNCTION f2() RETURNS VARCHAR(20) 7783BEGIN 7784RETURN f1(); 7785END// 7786 7787# Create a function provoking deadlock: 7788CREATE FUNCTION f3() RETURNS VARCHAR(20) 7789BEGIN 7790UPDATE t1 SET i= 1 WHERE i= 1; 7791RETURN 'Will never get here'; 7792END// 7793 7794# Create a function calling f3, to create 7795# a deadlock indirectly: 7796CREATE FUNCTION f4() RETURNS VARCHAR(20) 7797BEGIN 7798RETURN f3(); 7799END// 7800 7801# Open another connection, create and initialize a table 7802# to be used for provoking deadlock, put a lock on the table: 7803CREATE TABLE t1 (i INT) ENGINE=InnoDB; 7804INSERT INTO t1 VALUES (1); 7805SET AUTOCOMMIT= 0; 7806UPDATE t1 SET i=1 WHERE i=1; 7807 7808# On the default connection, do an update to provoke a 7809# deadlock, then call the function with handler. This case 7810# fails without the patch (with error ER_NO_SUCH_TABLE): 7811SET AUTOCOMMIT= 0; 7812UPDATE t1 SET i=1 WHERE i=1; 7813ERROR HY000: Lock wait timeout exceeded; try restarting transaction 7814SELECT f1() AS 'f1():'; 7815f1(): 7816No such table 7817 7818# Provoke another deadlock, then call the function with 7819# handler indirectly. This case fails without the patch 7820# (with error ER_NO_SUCH_TABLE): 7821UPDATE t1 SET i= 1 WHERE i= 1; 7822ERROR HY000: Lock wait timeout exceeded; try restarting transaction 7823SELECT f2() AS 'f2():'; 7824f2(): 7825No such table 7826 7827# Provoke yet another deadlock, but now from within a function, 7828# then call the function with handler. This succeeds even 7829# without the patch because is_fatal_sub_stmt_error is reset 7830# in restore_sub_stmt after the failing function has been 7831# executed. The test case is included anyway for better coverage: 7832SELECT f3() AS 'f3():'; 7833ERROR HY000: Lock wait timeout exceeded; try restarting transaction 7834SELECT f1() AS 'f1():'; 7835f1(): 7836No such table 7837# Provoke yet another deadlock, but now from within a function, 7838# calling another function, then call the function with handler. 7839# This succeeds even without the patch because 7840# is_fatal_sub_stmt_error is reset in restore_sub_stmt after 7841# the failing function has been executed. The test case is 7842# included anyway for better coverage: 7843SELECT f4() AS 'f4():'; 7844ERROR HY000: Lock wait timeout exceeded; try restarting transaction 7845SELECT f1() AS 'f1():'; 7846f1(): 7847No such table 7848 7849# Disconnect, drop functions and table: 7850DROP FUNCTION f4; 7851DROP FUNCTION f3; 7852DROP FUNCTION f2; 7853DROP FUNCTION f1; 7854DROP TABLE t1; 7855 7856# Reset lock wait timeouts 7857SET @@lock_wait_timeout= @lock_wait_timeout_saved; 7858SET @@innodb_lock_wait_timeout= @innodb_lock_wait_timeout_saved; 7859# 7860# BUG 16041903: End of test case 7861# 7862# End of 5.6 tests 7863