PageRenderTime 64ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/mysql-test/r/sp-error.result

https://github.com/programmer10110/webscalesql-5.6
Unknown | 2888 lines | 2787 code | 101 blank | 0 comment | 0 complexity | 9e8d454ac3e9c1ef76acd054ff3e94b3 MD5 | raw file
Possible License(s): GPL-2.0
  1. drop table if exists t1, t2;
  2. SELECT * FROM mysql.proc INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/proc.txt';
  3. delete from mysql.proc;
  4. create procedure syntaxerror(t int)|
  5. ERROR 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 1
  6. create procedure syntaxerror(t int)|
  7. ERROR 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 1
  8. create procedure syntaxerror(t int)|
  9. ERROR 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 1
  10. drop table if exists t3|
  11. create table t3 ( x int )|
  12. insert into t3 values (2), (3)|
  13. create procedure bad_into(out param int)
  14. select x from t3 into param|
  15. call bad_into(@x)|
  16. ERROR 42000: Result consisted of more than one row
  17. drop procedure bad_into|
  18. drop table t3|
  19. create procedure proc1()
  20. set @x = 42|
  21. create function func1() returns int
  22. return 42|
  23. create procedure foo()
  24. create procedure bar() set @x=3|
  25. ERROR 2F003: Can't create a PROCEDURE from within another stored routine
  26. create procedure foo()
  27. create function bar() returns double return 2.3|
  28. ERROR 2F003: Can't create a FUNCTION from within another stored routine
  29. create procedure proc1()
  30. set @x = 42|
  31. ERROR 42000: PROCEDURE proc1 already exists
  32. create function func1() returns int
  33. return 42|
  34. ERROR 42000: FUNCTION func1 already exists
  35. drop procedure proc1|
  36. drop function func1|
  37. alter procedure foo|
  38. ERROR 42000: PROCEDURE test.foo does not exist
  39. alter function foo|
  40. ERROR 42000: FUNCTION test.foo does not exist
  41. drop procedure foo|
  42. ERROR 42000: PROCEDURE test.foo does not exist
  43. drop function foo|
  44. ERROR 42000: FUNCTION test.foo does not exist
  45. call foo()|
  46. ERROR 42000: PROCEDURE test.foo does not exist
  47. drop procedure if exists foo|
  48. Warnings:
  49. Note 1305 PROCEDURE test.foo does not exist
  50. show create procedure foo|
  51. ERROR 42000: PROCEDURE foo does not exist
  52. show create function foo|
  53. ERROR 42000: FUNCTION foo does not exist
  54. create procedure foo()
  55. foo: loop
  56. leave bar;
  57. end loop|
  58. ERROR 42000: LEAVE with no matching label: bar
  59. create procedure foo()
  60. foo: loop
  61. iterate bar;
  62. end loop|
  63. ERROR 42000: ITERATE with no matching label: bar
  64. create procedure foo()
  65. foo: begin
  66. iterate foo;
  67. end|
  68. ERROR 42000: ITERATE with no matching label: foo
  69. create procedure foo()
  70. foo: loop
  71. foo: loop
  72. set @x=2;
  73. end loop foo;
  74. end loop foo|
  75. ERROR 42000: Redefining label foo
  76. create procedure foo()
  77. foo: loop
  78. set @x=2;
  79. end loop bar|
  80. ERROR 42000: End-label bar without match
  81. create procedure foo()
  82. return 42|
  83. ERROR 42000: RETURN is only allowed in a FUNCTION
  84. create procedure p(x int)
  85. set @x = x|
  86. create function f(x int) returns int
  87. return x+42|
  88. call p()|
  89. ERROR 42000: Incorrect number of arguments for PROCEDURE test.p; expected 1, got 0
  90. call p(1, 2)|
  91. ERROR 42000: Incorrect number of arguments for PROCEDURE test.p; expected 1, got 2
  92. select f()|
  93. ERROR 42000: Incorrect number of arguments for FUNCTION test.f; expected 1, got 0
  94. select f(1, 2)|
  95. ERROR 42000: Incorrect number of arguments for FUNCTION test.f; expected 1, got 2
  96. drop procedure p|
  97. drop function f|
  98. create procedure p(val int, out res int)
  99. begin
  100. declare x int default 0;
  101. declare continue handler for foo set x = 1;
  102. insert into test.t1 values (val);
  103. if (x) then
  104. set res = 0;
  105. else
  106. set res = 1;
  107. end if;
  108. end|
  109. ERROR 42000: Undefined CONDITION: foo
  110. create procedure p(val int, out res int)
  111. begin
  112. declare x int default 0;
  113. declare foo condition for 1146;
  114. declare continue handler for bar set x = 1;
  115. insert into test.t1 values (val);
  116. if (x) then
  117. set res = 0;
  118. else
  119. set res = 1;
  120. end if;
  121. end|
  122. ERROR 42000: Undefined CONDITION: bar
  123. create function f(val int) returns int
  124. begin
  125. declare x int;
  126. set x = val+3;
  127. end|
  128. ERROR 42000: No RETURN found in FUNCTION test.f
  129. create function f(val int) returns int
  130. begin
  131. declare x int;
  132. set x = val+3;
  133. if x < 4 then
  134. return x;
  135. end if;
  136. end|
  137. select f(10)|
  138. ERROR 2F005: FUNCTION f ended without RETURN
  139. drop function f|
  140. create procedure p()
  141. begin
  142. declare c cursor for insert into test.t1 values ("foo", 42);
  143. open c;
  144. close c;
  145. end|
  146. ERROR 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 'insert into test.t1 values ("foo", 42);
  147. open c;
  148. close c;
  149. end' at line 3
  150. create procedure p()
  151. begin
  152. declare x int;
  153. declare c cursor for select * into x from test.t limit 1;
  154. open c;
  155. close c;
  156. end|
  157. ERROR 42000: Cursor SELECT must not have INTO
  158. create procedure p()
  159. begin
  160. declare c cursor for select * from test.t;
  161. open cc;
  162. close c;
  163. end|
  164. ERROR 42000: Undefined CURSOR: cc
  165. drop table if exists t1|
  166. create table t1 (val int)|
  167. create procedure p()
  168. begin
  169. declare c cursor for select * from test.t1;
  170. open c;
  171. open c;
  172. close c;
  173. end|
  174. call p()|
  175. ERROR 24000: Cursor is already open
  176. drop procedure p|
  177. create procedure p()
  178. begin
  179. declare c cursor for select * from test.t1;
  180. open c;
  181. close c;
  182. close c;
  183. end|
  184. call p()|
  185. ERROR 24000: Cursor is not open
  186. drop procedure p|
  187. alter procedure bar3 sql security invoker|
  188. ERROR 42000: PROCEDURE test.bar3 does not exist
  189. drop table t1|
  190. drop table if exists t1|
  191. create table t1 (val int, x float)|
  192. insert into t1 values (42, 3.1), (19, 1.2)|
  193. create procedure p()
  194. begin
  195. declare x int;
  196. declare c cursor for select * from t1;
  197. open c;
  198. fetch c into x, y;
  199. close c;
  200. end|
  201. ERROR 42000: Undeclared variable: y
  202. create procedure p()
  203. begin
  204. declare x int;
  205. declare c cursor for select * from t1;
  206. open c;
  207. fetch c into x;
  208. close c;
  209. end|
  210. call p()|
  211. ERROR HY000: Incorrect number of FETCH variables
  212. drop procedure p|
  213. create procedure p()
  214. begin
  215. declare x int;
  216. declare y float;
  217. declare z int;
  218. declare c cursor for select * from t1;
  219. open c;
  220. fetch c into x, y, z;
  221. close c;
  222. end|
  223. call p()|
  224. ERROR HY000: Incorrect number of FETCH variables
  225. drop procedure p|
  226. create procedure p(in x int, x char(10))
  227. begin
  228. end|
  229. ERROR 42000: Duplicate parameter: x
  230. create function p(x int, x char(10))
  231. begin
  232. end|
  233. ERROR 42000: Duplicate parameter: x
  234. create procedure p()
  235. begin
  236. declare x float;
  237. declare x int;
  238. end|
  239. ERROR 42000: Duplicate variable: x
  240. create procedure p()
  241. begin
  242. declare c condition for 1064;
  243. declare c condition for 1065;
  244. end|
  245. ERROR 42000: Duplicate condition: c
  246. create procedure p()
  247. begin
  248. declare c cursor for select * from t1;
  249. declare c cursor for select field from t1;
  250. end|
  251. ERROR 42000: Duplicate cursor: c
  252. create procedure u()
  253. use sptmp|
  254. ERROR 0A000: USE is not allowed in stored procedures
  255. create procedure p()
  256. begin
  257. declare c cursor for select * from t1;
  258. declare x int;
  259. end|
  260. ERROR 42000: Variable or condition declaration after cursor or handler declaration
  261. create procedure p()
  262. begin
  263. declare x int;
  264. declare continue handler for sqlstate '42S99' set x = 1;
  265. declare foo condition for sqlstate '42S99';
  266. end|
  267. ERROR 42000: Variable or condition declaration after cursor or handler declaration
  268. create procedure p()
  269. begin
  270. declare x int;
  271. declare continue handler for sqlstate '42S99' set x = 1;
  272. declare c cursor for select * from t1;
  273. end|
  274. ERROR 42000: Cursor declaration after handler declaration
  275. drop procedure if exists p|
  276. create procedure p(in x int, inout y int, out z int)
  277. begin
  278. set y = x+y;
  279. set z = x+y;
  280. end|
  281. set @tmp_x = 42|
  282. set @tmp_y = 3|
  283. set @tmp_z = 0|
  284. call p(@tmp_x, @tmp_y, @tmp_z)|
  285. select @tmp_x, @tmp_y, @tmp_z|
  286. @tmp_x @tmp_y @tmp_z
  287. 42 45 87
  288. call p(42, 43, @tmp_z)|
  289. ERROR 42000: OUT or INOUT argument 2 for routine test.p is not a variable or NEW pseudo-variable in BEFORE trigger
  290. call p(42, @tmp_y, 43)|
  291. ERROR 42000: OUT or INOUT argument 3 for routine test.p is not a variable or NEW pseudo-variable in BEFORE trigger
  292. drop procedure p|
  293. create procedure p() begin end|
  294. lock table t1 read|
  295. call p()|
  296. unlock tables|
  297. drop procedure p|
  298. lock tables t1 read, mysql.proc write|
  299. ERROR HY000: You can't combine write-locking of system tables with other tables or lock types
  300. lock tables mysql.proc write, mysql.user write|
  301. ERROR HY000: You can't combine write-locking of system tables with other tables or lock types
  302. lock tables t1 read, mysql.proc read|
  303. unlock tables|
  304. lock tables mysql.proc write|
  305. unlock tables|
  306. drop function if exists f1|
  307. create function f1(i int) returns int
  308. begin
  309. insert into t1 (val) values (i);
  310. return 0;
  311. end|
  312. select val, f1(val) from t1|
  313. ERROR HY000: Can't update table 't1' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
  314. select val, f1(val) from t1 as tab|
  315. ERROR HY000: Can't update table 't1' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
  316. select * from t1|
  317. val x
  318. 42 3.1
  319. 19 1.2
  320. update t1 set val= f1(val)|
  321. ERROR HY000: Can't update table 't1' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
  322. select * from t1|
  323. val x
  324. 42 3.1
  325. 19 1.2
  326. select f1(17)|
  327. f1(17)
  328. 0
  329. select * from t1|
  330. val x
  331. 42 3.1
  332. 19 1.2
  333. 17 NULL
  334. delete from t1 where val= 17|
  335. drop function f1|
  336. create procedure bug1965()
  337. begin
  338. declare c cursor for select val from t1 order by valname;
  339. open c;
  340. close c;
  341. end|
  342. call bug1965()|
  343. ERROR 42S22: Unknown column 'valname' in 'order clause'
  344. drop procedure bug1965|
  345. select 1 into a|
  346. ERROR 42000: Undeclared variable: a
  347. drop table if exists t3|
  348. create table t3 (column_1_0 int)|
  349. create procedure bug1653()
  350. update t3 set column_1 = 0|
  351. call bug1653()|
  352. ERROR 42S22: Unknown column 'column_1' in 'field list'
  353. drop table t3|
  354. create table t3 (column_1 int)|
  355. call bug1653()|
  356. drop procedure bug1653|
  357. drop table t3|
  358. create procedure bug2259()
  359. begin
  360. declare v1 int;
  361. declare c1 cursor for select s1 from t1;
  362. fetch c1 into v1;
  363. end|
  364. call bug2259()|
  365. ERROR 24000: Cursor is not open
  366. drop procedure bug2259|
  367. create procedure bug2272()
  368. begin
  369. declare v int;
  370. update t1 set v = 42;
  371. end|
  372. insert into t1 values (666, 51.3)|
  373. call bug2272()|
  374. ERROR 42S22: Unknown column 'v' in 'field list'
  375. truncate table t1|
  376. drop procedure bug2272|
  377. create procedure bug2329_1()
  378. begin
  379. declare v int;
  380. insert into t1 (v) values (5);
  381. end|
  382. create procedure bug2329_2()
  383. begin
  384. declare v int;
  385. replace t1 set v = 5;
  386. end|
  387. call bug2329_1()|
  388. ERROR 42S22: Unknown column 'v' in 'field list'
  389. call bug2329_2()|
  390. ERROR 42S22: Unknown column 'v' in 'field list'
  391. drop procedure bug2329_1|
  392. drop procedure bug2329_2|
  393. create function bug3287() returns int
  394. begin
  395. declare v int default null;
  396. case
  397. when v is not null then return 1;
  398. end case;
  399. return 2;
  400. end|
  401. select bug3287()|
  402. ERROR 20000: Case not found for CASE statement
  403. drop function bug3287|
  404. create procedure bug3287(x int)
  405. case x
  406. when 0 then
  407. insert into test.t1 values (x, 0.1);
  408. when 1 then
  409. insert into test.t1 values (x, 1.1);
  410. end case|
  411. call bug3287(2)|
  412. ERROR 20000: Case not found for CASE statement
  413. drop procedure bug3287|
  414. drop table if exists t3|
  415. create table t3 (s1 int, primary key (s1))|
  416. insert into t3 values (5),(6)|
  417. create procedure bug3279(out y int)
  418. begin
  419. declare x int default 0;
  420. begin
  421. declare exit handler for sqlexception set x = x+1;
  422. insert into t3 values (5);
  423. end;
  424. if x < 2 then
  425. set x = x+1;
  426. insert into t3 values (6);
  427. end if;
  428. set y = x;
  429. end|
  430. set @x = 0|
  431. call bug3279(@x)|
  432. ERROR 23000: Duplicate entry '6' for key 'PRIMARY'
  433. select @x|
  434. @x
  435. 0
  436. drop procedure bug3279|
  437. drop table t3|
  438. create procedure nodb.bug3339() begin end|
  439. ERROR 42000: Unknown database 'nodb'
  440. create procedure bug2653_1(a int, out b int)
  441. set b = aa|
  442. create procedure bug2653_2(a int, out b int)
  443. begin
  444. if aa < 0 then
  445. set b = - a;
  446. else
  447. set b = a;
  448. end if;
  449. end|
  450. call bug2653_1(1, @b)|
  451. ERROR 42S22: Unknown column 'aa' in 'field list'
  452. call bug2653_2(2, @b)|
  453. ERROR 42S22: Unknown column 'aa' in 'field list'
  454. drop procedure bug2653_1|
  455. drop procedure bug2653_2|
  456. create procedure bug4344() drop procedure bug4344|
  457. ERROR HY000: Can't drop or alter a PROCEDURE from within another stored routine
  458. create procedure bug4344() drop function bug4344|
  459. ERROR HY000: Can't drop or alter a FUNCTION from within another stored routine
  460. drop procedure if exists bug3294|
  461. create procedure bug3294()
  462. begin
  463. declare continue handler for sqlexception drop table t5;
  464. drop table t5;
  465. drop table t5;
  466. end|
  467. create table t5 (x int)|
  468. call bug3294()|
  469. ERROR 42S02: Unknown table 'test.t5'
  470. drop procedure bug3294|
  471. drop procedure if exists bug8776_1|
  472. drop procedure if exists bug8776_2|
  473. drop procedure if exists bug8776_3|
  474. drop procedure if exists bug8776_4|
  475. create procedure bug8776_1()
  476. begin
  477. declare continue handler for sqlstate '42S0200test' begin end;
  478. begin end;
  479. end|
  480. ERROR 42000: Bad SQLSTATE: '42S0200test'
  481. create procedure bug8776_2()
  482. begin
  483. declare continue handler for sqlstate '4200' begin end;
  484. begin end;
  485. end|
  486. ERROR 42000: Bad SQLSTATE: '4200'
  487. create procedure bug8776_3()
  488. begin
  489. declare continue handler for sqlstate '420000' begin end;
  490. begin end;
  491. end|
  492. ERROR 42000: Bad SQLSTATE: '420000'
  493. create procedure bug8776_4()
  494. begin
  495. declare continue handler for sqlstate '42x00' begin end;
  496. begin end;
  497. end|
  498. ERROR 42000: Bad SQLSTATE: '42x00'
  499. create procedure bug6600()
  500. check table t1|
  501. ERROR 0A000: CHECK is not allowed in stored procedures
  502. create procedure bug6600()
  503. lock table t1 read|
  504. ERROR 0A000: LOCK is not allowed in stored procedures
  505. create procedure bug6600()
  506. unlock table t1|
  507. ERROR 0A000: UNLOCK is not allowed in stored procedures
  508. drop procedure if exists bug9566|
  509. create procedure bug9566()
  510. begin
  511. select * from t1;
  512. end|
  513. lock table t1 read|
  514. alter procedure bug9566 comment 'Some comment'|
  515. ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction
  516. unlock tables|
  517. drop procedure bug9566|
  518. drop procedure if exists bug7299|
  519. create procedure bug7299()
  520. begin
  521. declare v int;
  522. declare c cursor for select val from t1;
  523. declare exit handler for sqlexception select 'Error!';
  524. open c;
  525. fetch c into v;
  526. end|
  527. truncate table t1|
  528. call bug7299()|
  529. ERROR 02000: No data - zero rows fetched, selected, or processed
  530. drop procedure bug7299|
  531. create procedure bug9073()
  532. begin
  533. declare continue handler for sqlexception select 1;
  534. declare continue handler for sqlexception select 2;
  535. end|
  536. ERROR 42000: Duplicate handler declared in the same block
  537. create procedure bug9073()
  538. begin
  539. declare condname1 condition for 1234;
  540. declare continue handler for condname1 select 1;
  541. declare exit handler for condname1 select 2;
  542. end|
  543. ERROR 42000: Duplicate handler declared in the same block
  544. create procedure bug9073()
  545. begin
  546. declare condname1 condition for sqlstate '42000';
  547. declare condname2 condition for sqlstate '42000';
  548. declare exit handler for condname1 select 1;
  549. declare continue handler for condname2 select 2;
  550. end|
  551. ERROR 42000: Duplicate handler declared in the same block
  552. create procedure bug9073()
  553. begin
  554. declare condname1 condition for sqlstate '42000';
  555. declare exit handler for condname1 select 1;
  556. declare exit handler for sqlstate '42000' select 2;
  557. end|
  558. ERROR 42000: Duplicate handler declared in the same block
  559. drop procedure if exists bug9073|
  560. create procedure bug9073()
  561. begin
  562. declare condname1 condition for sqlstate '42000';
  563. declare continue handler for condname1 select 1;
  564. begin
  565. declare exit handler for sqlstate '42000' select 2;
  566. begin
  567. declare continue handler for sqlstate '42000' select 3;
  568. end;
  569. end;
  570. end|
  571. drop procedure bug9073|
  572. create procedure bug7047()
  573. alter procedure bug7047|
  574. ERROR HY000: Can't drop or alter a PROCEDURE from within another stored routine
  575. create function bug7047() returns int
  576. begin
  577. alter function bug7047;
  578. return 0;
  579. end|
  580. ERROR HY000: Can't drop or alter a FUNCTION from within another stored routine
  581. create function bug8408() returns int
  582. begin
  583. select * from t1;
  584. return 0;
  585. end|
  586. ERROR 0A000: Not allowed to return a result set from a function
  587. create function bug8408() returns int
  588. begin
  589. show warnings;
  590. return 0;
  591. end|
  592. ERROR 0A000: Not allowed to return a result set from a function
  593. create function bug8408(a int) returns int
  594. begin
  595. declare b int;
  596. select b;
  597. return b;
  598. end|
  599. ERROR 0A000: Not allowed to return a result set from a function
  600. drop function if exists bug8408_f|
  601. drop procedure if exists bug8408_p|
  602. create function bug8408_f() returns int
  603. begin
  604. call bug8408_p();
  605. return 0;
  606. end|
  607. create procedure bug8408_p()
  608. select * from t1|
  609. call bug8408_p()|
  610. val x
  611. select bug8408_f()|
  612. ERROR 0A000: Not allowed to return a result set from a function
  613. drop procedure bug8408_p|
  614. drop function bug8408_f|
  615. create function bug8408() returns int
  616. begin
  617. declare n int default 0;
  618. select count(*) into n from t1;
  619. return n;
  620. end|
  621. insert into t1 value (2, 2.7), (3, 3.14), (7, 7.0)|
  622. select *,bug8408() from t1|
  623. val x bug8408()
  624. 2 2.7 3
  625. 3 3.14 3
  626. 7 7 3
  627. drop function bug8408|
  628. truncate table t1|
  629. drop procedure if exists bug10537|
  630. create procedure bug10537()
  631. load data local infile '/tmp/somefile' into table t1|
  632. ERROR 0A000: LOAD DATA is not allowed in stored procedures
  633. drop function if exists bug8409|
  634. create function bug8409()
  635. returns int
  636. begin
  637. flush tables;
  638. return 5;
  639. end|
  640. ERROR 0A000: FLUSH is not allowed in stored function or trigger
  641. create function bug8409() returns int begin reset query cache;
  642. return 1; end|
  643. ERROR 0A000: RESET is not allowed in stored function or trigger
  644. create function bug8409() returns int begin reset master;
  645. return 1; end|
  646. ERROR 0A000: RESET is not allowed in stored function or trigger
  647. create function bug8409() returns int begin reset slave;
  648. return 1; end|
  649. ERROR 0A000: RESET is not allowed in stored function or trigger
  650. create function bug8409() returns int begin flush hosts;
  651. return 1; end|
  652. ERROR 0A000: FLUSH is not allowed in stored function or trigger
  653. create function bug8409() returns int begin flush privileges;
  654. return 1; end|
  655. ERROR 0A000: FLUSH is not allowed in stored function or trigger
  656. create function bug8409() returns int begin flush tables with read lock;
  657. return 1; end|
  658. ERROR 0A000: FLUSH is not allowed in stored function or trigger
  659. create function bug8409() returns int begin flush tables;
  660. return 1; end|
  661. ERROR 0A000: FLUSH is not allowed in stored function or trigger
  662. create function bug8409() returns int begin flush logs;
  663. return 1; end|
  664. ERROR 0A000: FLUSH is not allowed in stored function or trigger
  665. create function bug8409() returns int begin flush status;
  666. return 1; end|
  667. ERROR 0A000: FLUSH is not allowed in stored function or trigger
  668. create function bug8409() returns int begin flush des_key_file;
  669. return 1; end|
  670. ERROR 0A000: FLUSH is not allowed in stored function or trigger
  671. create function bug8409() returns int begin flush user_resources;
  672. return 1; end|
  673. ERROR 0A000: FLUSH is not allowed in stored function or trigger
  674. create procedure bug9529_901234567890123456789012345678901234567890123456789012345()
  675. begin
  676. end|
  677. ERROR 42000: Identifier name 'bug9529_901234567890123456789012345678901234567890123456789012345' is too long
  678. drop procedure if exists bug17015_0123456789012345678901234567890123456789012345678901234|
  679. create procedure bug17015_0123456789012345678901234567890123456789012345678901234()
  680. begin
  681. end|
  682. show procedure status like 'bug17015%'|
  683. Db Name Type Definer Modified Created Security_type Comment character_set_client collation_connection Database Collation
  684. test bug17015_0123456789012345678901234567890123456789012345678901234 PROCEDURE root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER latin1 latin1_swedish_ci latin1_swedish_ci
  685. drop procedure bug17015_0123456789012345678901234567890123456789012345678901234|
  686. drop procedure if exists bug10969|
  687. create procedure bug10969()
  688. begin
  689. declare s1 int default 0;
  690. select default(s1) from t30;
  691. end|
  692. ERROR 42000: Incorrect column name 's1'
  693. create procedure bug10969()
  694. begin
  695. declare s1 int default 0;
  696. select default(t30.s1) from t30;
  697. end|
  698. drop procedure bug10969|
  699. drop table t1|
  700. create table t1(f1 int);
  701. create table t2(f1 int);
  702. CREATE PROCEDURE SP001()
  703. P1: BEGIN
  704. DECLARE ENDTABLE INT DEFAULT 0;
  705. DECLARE TEMP_NUM INT;
  706. DECLARE TEMP_SUM INT;
  707. DECLARE C1 CURSOR FOR SELECT F1 FROM t1;
  708. DECLARE C2 CURSOR FOR SELECT F1 FROM t2;
  709. DECLARE CONTINUE HANDLER FOR NOT FOUND SET ENDTABLE = 1;
  710. SET ENDTABLE=0;
  711. SET TEMP_SUM=0;
  712. SET TEMP_NUM=0;
  713. OPEN C1;
  714. FETCH C1 INTO TEMP_NUM;
  715. WHILE ENDTABLE = 0 DO
  716. SET TEMP_SUM=TEMP_NUM+TEMP_SUM;
  717. FETCH C1 INTO TEMP_NUM;
  718. END WHILE;
  719. SELECT TEMP_SUM;
  720. CLOSE C1;
  721. CLOSE C1;
  722. SELECT 'end of proc';
  723. END P1|
  724. call SP001();
  725. TEMP_SUM
  726. 0
  727. ERROR 24000: Cursor is not open
  728. drop procedure SP001;
  729. drop table t1, t2;
  730. drop function if exists bug11394|
  731. drop function if exists bug11394_1|
  732. drop function if exists bug11394_2|
  733. drop procedure if exists bug11394|
  734. create function bug11394(i int) returns int
  735. begin
  736. if i <= 0 then
  737. return 0;
  738. else
  739. return (i in (100, 200, bug11394(i-1), 400));
  740. end if;
  741. end|
  742. select bug11394(2)|
  743. ERROR HY000: Recursive stored functions and triggers are not allowed.
  744. drop function bug11394|
  745. create function bug11394_1(i int) returns int
  746. begin
  747. if i <= 0 then
  748. return 0;
  749. else
  750. return (select bug11394_1(i-1));
  751. end if;
  752. end|
  753. select bug11394_1(2)|
  754. ERROR HY000: Recursive stored functions and triggers are not allowed.
  755. drop function bug11394_1|
  756. create function bug11394_2(i int) returns int return i|
  757. select bug11394_2(bug11394_2(10))|
  758. bug11394_2(bug11394_2(10))
  759. 10
  760. drop function bug11394_2|
  761. create procedure bug11394(i int, j int)
  762. begin
  763. if i > 0 then
  764. call bug11394(i - 1,(select 1));
  765. end if;
  766. end|
  767. call bug11394(2, 1)|
  768. ERROR HY000: Recursive limit 0 (as set by the max_sp_recursion_depth variable) was exceeded for routine bug11394
  769. set @@max_sp_recursion_depth=10|
  770. call bug11394(2, 1)|
  771. set @@max_sp_recursion_depth=default|
  772. drop procedure bug11394|
  773. CREATE PROCEDURE BUG_12490() HELP CONTENTS;
  774. ERROR 0A000: HELP is not allowed in stored procedures
  775. CREATE FUNCTION BUG_12490() RETURNS INT HELP CONTENTS;
  776. ERROR 0A000: HELP is not allowed in stored procedures
  777. CREATE TABLE t_bug_12490(a int);
  778. CREATE TRIGGER BUG_12490 BEFORE UPDATE ON t_bug_12490 FOR EACH ROW HELP CONTENTS;
  779. ERROR 0A000: HELP is not allowed in stored procedures
  780. DROP TABLE t_bug_12490;
  781. drop function if exists bug11834_1;
  782. drop function if exists bug11834_2;
  783. create function bug11834_1() returns int return 10;
  784. create function bug11834_2() returns int return bug11834_1();
  785. prepare stmt from "select bug11834_2()";
  786. execute stmt;
  787. bug11834_2()
  788. 10
  789. execute stmt;
  790. bug11834_2()
  791. 10
  792. drop function bug11834_1;
  793. execute stmt;
  794. ERROR 42000: FUNCTION test.bug11834_1 does not exist
  795. deallocate prepare stmt;
  796. drop function bug11834_2;
  797. DROP FUNCTION IF EXISTS bug12953|
  798. CREATE FUNCTION bug12953() RETURNS INT
  799. BEGIN
  800. OPTIMIZE TABLE t1;
  801. RETURN 1;
  802. END|
  803. ERROR 0A000: Not allowed to return a result set from a function
  804. DROP FUNCTION IF EXISTS bug12995|
  805. CREATE FUNCTION bug12995() RETURNS INT
  806. BEGIN
  807. HANDLER t1 OPEN;
  808. RETURN 1;
  809. END|
  810. ERROR 0A000: HANDLER is not allowed in stored procedures
  811. CREATE FUNCTION bug12995() RETURNS INT
  812. BEGIN
  813. HANDLER t1 READ FIRST;
  814. RETURN 1;
  815. END|
  816. ERROR 0A000: HANDLER is not allowed in stored procedures
  817. CREATE FUNCTION bug12995() RETURNS INT
  818. BEGIN
  819. HANDLER t1 CLOSE;
  820. RETURN 1;
  821. END|
  822. ERROR 0A000: HANDLER is not allowed in stored procedures
  823. SELECT bug12995()|
  824. ERROR 42000: FUNCTION test.bug12995 does not exist
  825. drop procedure if exists bug12712;
  826. drop function if exists bug12712;
  827. create procedure bug12712()
  828. set session autocommit = 0;
  829. select @@autocommit;
  830. @@autocommit
  831. 1
  832. set @au = @@autocommit;
  833. call bug12712();
  834. select @@autocommit;
  835. @@autocommit
  836. 0
  837. set session autocommit = @au;
  838. create function bug12712()
  839. returns int
  840. begin
  841. call bug12712();
  842. return 0;
  843. end|
  844. set @x = bug12712()|
  845. ERROR HY000: Not allowed to set autocommit from a stored function or trigger
  846. drop procedure bug12712|
  847. drop function bug12712|
  848. create function bug12712()
  849. returns int
  850. begin
  851. set session autocommit = 0;
  852. return 0;
  853. end|
  854. ERROR HY000: Not allowed to set autocommit from a stored function or trigger
  855. create function bug12712()
  856. returns int
  857. begin
  858. set @@autocommit = 0;
  859. return 0;
  860. end|
  861. ERROR HY000: Not allowed to set autocommit from a stored function or trigger
  862. create function bug12712()
  863. returns int
  864. begin
  865. set local autocommit = 0;
  866. return 0;
  867. end|
  868. ERROR HY000: Not allowed to set autocommit from a stored function or trigger
  869. create trigger bug12712
  870. before insert on t1 for each row set session autocommit = 0;
  871. ERROR HY000: Not allowed to set autocommit from a stored function or trigger
  872. drop procedure if exists bug13510_1|
  873. drop procedure if exists bug13510_2|
  874. drop procedure if exists bug13510_3|
  875. drop procedure if exists bug13510_4|
  876. create procedure bug13510_1()
  877. begin
  878. declare password varchar(10);
  879. set password = 'foo1';
  880. select password;
  881. end|
  882. ERROR 42000: Variable 'password' must be quoted with `...`, or renamed
  883. set names='foo2'|
  884. ERROR 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 1
  885. create procedure bug13510_2()
  886. begin
  887. declare names varchar(10);
  888. set names = 'foo2';
  889. select names;
  890. end|
  891. ERROR 42000: Variable 'names' must be quoted with `...`, or renamed
  892. create procedure bug13510_3()
  893. begin
  894. declare password varchar(10);
  895. set `password` = 'foo3';
  896. select password;
  897. end|
  898. create procedure bug13510_4()
  899. begin
  900. declare names varchar(10);
  901. set `names` = 'foo4';
  902. select names;
  903. end|
  904. call bug13510_3()|
  905. password
  906. foo3
  907. call bug13510_4()|
  908. names
  909. foo4
  910. drop procedure bug13510_3|
  911. drop procedure bug13510_4|
  912. drop function if exists bug_13627_f|
  913. CREATE TABLE t1 (a int)|
  914. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN DROP TRIGGER test1; END |
  915. ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger.
  916. CREATE FUNCTION bug_13627_f() returns int BEGIN DROP TRIGGER test1; return 1; END |
  917. ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger.
  918. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN create table t2 (a int); END |
  919. ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger.
  920. CREATE FUNCTION bug_13627_f() returns int BEGIN create table t2 (a int); return 1; END |
  921. ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger.
  922. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN create index t1_i on t1 (a); END |
  923. ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger.
  924. CREATE FUNCTION bug_13627_f() returns int BEGIN create index t1_i on t1 (a); return 1; END |
  925. ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger.
  926. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN alter table t1 add column b int; END |
  927. ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger.
  928. CREATE FUNCTION bug_13627_f() returns int BEGIN alter table t1 add column b int; return 1; END |
  929. ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger.
  930. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN rename table t1 to t2; END |
  931. ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger.
  932. CREATE FUNCTION bug_13627_f() returns int BEGIN rename table t1 to t2; return 1; END |
  933. ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger.
  934. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN truncate table t1; END |
  935. ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger.
  936. CREATE FUNCTION bug_13627_f() returns int BEGIN truncate table t1; return 1; END |
  937. ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger.
  938. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN drop table t1; END |
  939. ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger.
  940. CREATE FUNCTION bug_13627_f() returns int BEGIN drop table t1; return 1; END |
  941. ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger.
  942. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN drop index t1_i on t1; END |
  943. ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger.
  944. CREATE FUNCTION bug_13627_f() returns int BEGIN drop index t1_i on t1; return 1; END |
  945. ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger.
  946. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN unlock tables; END |
  947. ERROR 0A000: UNLOCK is not allowed in stored procedures
  948. CREATE FUNCTION bug_13627_f() returns int BEGIN unlock tables; return 1; END |
  949. ERROR 0A000: UNLOCK is not allowed in stored procedures
  950. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN LOCK TABLE t1 READ; END |
  951. ERROR 0A000: LOCK is not allowed in stored procedures
  952. CREATE FUNCTION bug_13627_f() returns int BEGIN LOCK TABLE t1 READ; return 1; END |
  953. ERROR 0A000: LOCK is not allowed in stored procedures
  954. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN create database mysqltest; END |
  955. ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger.
  956. CREATE FUNCTION bug_13627_f() returns int BEGIN create database mysqltest; return 1; END |
  957. ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger.
  958. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN drop database mysqltest; END |
  959. ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger.
  960. CREATE FUNCTION bug_13627_f() returns int BEGIN drop database mysqltest; return 1; END |
  961. ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger.
  962. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN create user 'mysqltest_1'; END |
  963. ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger.
  964. CREATE FUNCTION bug_13627_f() returns int BEGIN create user 'mysqltest_1'; return 1; END |
  965. ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger.
  966. CREATE TRIGGER bug21975 BEFORE INSERT ON t1 FOR EACH ROW BEGIN grant select on t1 to 'mysqltest_1'; END |
  967. ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger.
  968. CREATE FUNCTION bug21975() returns int BEGIN grant select on t1 to 'mysqltest_1'; return 1; END |
  969. ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger.
  970. CREATE TRIGGER bug21975 BEFORE INSERT ON t1 FOR EACH ROW BEGIN revoke select on t1 from 'mysqltest_1'; END |
  971. ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger.
  972. CREATE FUNCTION bug21975() returns int BEGIN revoke select on t1 from 'mysqltest_1'; return 1; END |
  973. ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger.
  974. CREATE TRIGGER bug21975 BEFORE INSERT ON t1 FOR EACH ROW BEGIN revoke all privileges on *.* from 'mysqltest_1'; END |
  975. ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger.
  976. CREATE FUNCTION bug21975() returns int BEGIN revoke all privileges on *.* from 'mysqltest_1'; return 1; END |
  977. ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger.
  978. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN drop user 'mysqltest_1'; END |
  979. ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger.
  980. CREATE FUNCTION bug_13627_f() returns int BEGIN drop user 'mysqltest_1'; return 1; END |
  981. ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger.
  982. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN rename user 'mysqltest_2' to 'mysqltest_1'; END |
  983. ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger.
  984. CREATE FUNCTION bug_13627_f() returns int BEGIN rename user 'mysqltest_2' to 'mysqltest_1'; return 1; END |
  985. ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger.
  986. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN create view v1 as select 1; END |
  987. ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger.
  988. CREATE FUNCTION bug_13627_f() returns int BEGIN create view v1 as select 1; return 1; END |
  989. ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger.
  990. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN alter view v1 as select 1; END |
  991. ERROR 0A000: ALTER VIEW is not allowed in stored procedures
  992. CREATE FUNCTION bug_13627_f() returns int BEGIN alter view v1 as select 1; return 1; END |
  993. ERROR 0A000: ALTER VIEW is not allowed in stored procedures
  994. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN drop view v1; END |
  995. ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger.
  996. CREATE FUNCTION bug_13627_f() returns int BEGIN drop view v1; return 1; END |
  997. ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger.
  998. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN create trigger tr2 before insert on t1 for each row do select 1; END |
  999. ERROR 2F003: Can't create a TRIGGER from within another stored routine
  1000. CREATE FUNCTION bug_13627_f() returns int BEGIN create trigger tr2 before insert on t1 for each row do select 1; return 1; END |
  1001. ERROR 2F003: Can't create a TRIGGER from within another stored routine
  1002. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN drop function bug_13627_f; END |
  1003. ERROR HY000: Can't drop or alter a FUNCTION from within another stored routine
  1004. CREATE FUNCTION bug_13627_f() returns int BEGIN drop function bug_13627_f; return 1; END |
  1005. ERROR HY000: Can't drop or alter a FUNCTION from within another stored routine
  1006. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN create function f2 () returns int return 1; END |
  1007. ERROR 2F003: Can't create a FUNCTION from within another stored routine
  1008. CREATE FUNCTION bug_13627_f() returns int BEGIN create function f2 () returns int return 1; return 1; END |
  1009. ERROR 2F003: Can't create a FUNCTION from within another stored routine
  1010. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW
  1011. BEGIN
  1012. CREATE TEMPORARY TABLE t2 (a int);
  1013. DROP TEMPORARY TABLE t2;
  1014. END |
  1015. CREATE FUNCTION bug_13627_f() returns int
  1016. BEGIN
  1017. CREATE TEMPORARY TABLE t2 (a int);
  1018. DROP TEMPORARY TABLE t2;
  1019. return 1;
  1020. END |
  1021. drop table t1|
  1022. drop function bug_13627_f|
  1023. drop function if exists bug12329;
  1024. Warnings:
  1025. Note 1305 FUNCTION test.bug12329 does not exist
  1026. create table t1 as select 1 a;
  1027. create table t2 as select 1 a;
  1028. create function bug12329() returns int return (select a from t1);
  1029. prepare stmt1 from 'select bug12329()';
  1030. execute stmt1;
  1031. bug12329()
  1032. 1
  1033. drop function bug12329;
  1034. create function bug12329() returns int return (select a+100 from t2);
  1035. select bug12329();
  1036. bug12329()
  1037. 101
  1038. execute stmt1;
  1039. bug12329()
  1040. 101
  1041. deallocate prepare stmt1;
  1042. drop function bug12329;
  1043. drop table t1, t2;
  1044. create database mysqltest1;
  1045. use mysqltest1;
  1046. drop database mysqltest1;
  1047. create function f1() returns int return 1;
  1048. ERROR 3D000: No database selected
  1049. create procedure p1(out param1 int)
  1050. begin
  1051. select count(*) into param1 from t3;
  1052. end|
  1053. ERROR 3D000: No database selected
  1054. use test;
  1055. DROP PROCEDURE IF EXISTS bug13037_p1;
  1056. DROP PROCEDURE IF EXISTS bug13037_p2;
  1057. DROP PROCEDURE IF EXISTS bug13037_p3;
  1058. CREATE PROCEDURE bug13037_p1()
  1059. BEGIN
  1060. IF bug13037_foo THEN
  1061. SELECT 1;
  1062. END IF;
  1063. END|
  1064. CREATE PROCEDURE bug13037_p2()
  1065. BEGIN
  1066. SET @bug13037_foo = bug13037_bar;
  1067. END|
  1068. CREATE PROCEDURE bug13037_p3()
  1069. BEGIN
  1070. SELECT bug13037_foo;
  1071. END|
  1072. CALL bug13037_p1();
  1073. ERROR 42S22: Unknown column 'bug13037_foo' in 'field list'
  1074. CALL bug13037_p2();
  1075. ERROR 42S22: Unknown column 'bug13037_bar' in 'field list'
  1076. CALL bug13037_p3();
  1077. ERROR 42S22: Unknown column 'bug13037_foo' in 'field list'
  1078. CALL bug13037_p1();
  1079. ERROR 42S22: Unknown column 'bug13037_foo' in 'field list'
  1080. CALL bug13037_p2();
  1081. ERROR 42S22: Unknown column 'bug13037_bar' in 'field list'
  1082. CALL bug13037_p3();
  1083. ERROR 42S22: Unknown column 'bug13037_foo' in 'field list'
  1084. DROP PROCEDURE bug13037_p1;
  1085. DROP PROCEDURE bug13037_p2;
  1086. DROP PROCEDURE bug13037_p3;
  1087. create database mysqltest1;
  1088. create database mysqltest2;
  1089. use mysqltest1;
  1090. drop database mysqltest1;
  1091. create procedure mysqltest2.p1() select version();
  1092. create procedure p2() select version();
  1093. ERROR 3D000: No database selected
  1094. use mysqltest2;
  1095. show procedure status;
  1096. Db Name Type Definer Modified Created Security_type Comment character_set_client collation_connection Database Collation
  1097. mysqltest2 p1 PROCEDURE root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER latin1 latin1_swedish_ci latin1_swedish_ci
  1098. drop database mysqltest2;
  1099. use test;
  1100. DROP FUNCTION IF EXISTS bug13012|
  1101. CREATE FUNCTION bug13012() RETURNS INT
  1102. BEGIN
  1103. REPAIR TABLE t1;
  1104. RETURN 1;
  1105. END|
  1106. ERROR 0A000: Not allowed to return a result set from a function
  1107. create table t1 (a int)|
  1108. CREATE PROCEDURE bug13012_1() REPAIR TABLE t1|
  1109. CREATE FUNCTION bug13012_2() RETURNS INT
  1110. BEGIN
  1111. CALL bug13012_1();
  1112. RETURN 1;
  1113. END|
  1114. SELECT bug13012_2()|
  1115. ERROR 0A000: Not allowed to return a result set from a function
  1116. drop table t1|
  1117. drop procedure bug13012_1|
  1118. drop function bug13012_2|
  1119. drop function if exists bug11555_1;
  1120. drop function if exists bug11555_2;
  1121. drop view if exists v1, v2, v3, v4;
  1122. create function bug11555_1() returns int return (select max(i) from t1);
  1123. create function bug11555_2() returns int return bug11555_1();
  1124. create view v1 as select bug11555_1();
  1125. drop view v1;
  1126. create view v2 as select bug11555_2();
  1127. drop view v2;
  1128. create table t1 (i int);
  1129. create view v1 as select bug11555_1();
  1130. create view v2 as select bug11555_2();
  1131. create view v3 as select * from v1;
  1132. drop table t1;
  1133. select * from v1;
  1134. ERROR HY000: View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
  1135. select * from v2;
  1136. ERROR HY000: View 'test.v2' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
  1137. select * from v3;
  1138. ERROR HY000: View 'test.v3' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
  1139. create view v4 as select * from v1;
  1140. drop view v1, v2, v3, v4;
  1141. drop function bug11555_1;
  1142. drop function bug11555_2;
  1143. create table t1 (i int);
  1144. create table t2 (i int);
  1145. create trigger t1_ai after insert on t1 for each row insert into t2 values (new.i);
  1146. create view v1 as select * from t1;
  1147. drop table t2;
  1148. insert into v1 values (1);
  1149. ERROR 42S02: Table 'test.t2' doesn't exist
  1150. drop trigger t1_ai;
  1151. create function bug11555_1() returns int return (select max(i) from t2);
  1152. create trigger t1_ai after insert on t1 for each row set @a:=bug11555_1();
  1153. insert into v1 values (2);
  1154. ERROR 42S02: Table 'test.t2' doesn't exist
  1155. drop function bug11555_1;
  1156. drop table t1;
  1157. drop view v1;
  1158. drop procedure if exists ` bug15658`;
  1159. create procedure ``() select 1;
  1160. ERROR 42000: Incorrect routine name ''
  1161. create procedure ` `() select 1;
  1162. ERROR 42000: Incorrect routine name ' '
  1163. create procedure `bug15658 `() select 1;
  1164. ERROR 42000: Incorrect routine name 'bug15658 '
  1165. create procedure ``.bug15658() select 1;
  1166. ERROR 42000: Incorrect database name ''
  1167. create procedure `x `.bug15658() select 1;
  1168. ERROR 42000: Incorrect database name 'x '
  1169. create procedure ` bug15658`() select 1;
  1170. call ` bug15658`();
  1171. 1
  1172. 1
  1173. show procedure status;
  1174. Db Name Type Definer Modified Created Security_type Comment character_set_client collation_connection Database Collation
  1175. test bug15658 PROCEDURE root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER latin1 latin1_swedish_ci latin1_swedish_ci
  1176. drop procedure ` bug15658`;
  1177. drop function if exists bug14270;
  1178. drop table if exists t1;
  1179. create table t1 (s1 int primary key);
  1180. create function bug14270() returns int
  1181. begin
  1182. load index into cache t1;
  1183. return 1;
  1184. end|
  1185. ERROR 0A000: Not allowed to return a result set from a function
  1186. create function bug14270() returns int
  1187. begin
  1188. cache index t1 key (`primary`) in keycache1;
  1189. return 1;
  1190. end|
  1191. ERROR 0A000: Not allowed to return a result set from a function
  1192. drop table t1;
  1193. drop procedure if exists bug15091;
  1194. create procedure bug15091()
  1195. begin
  1196. declare selectstr varchar(6000) default ' ';
  1197. declare conditionstr varchar(5000) default '';
  1198. set selectstr = concat(selectstr,
  1199. ' and ',
  1200. c.operatorid,
  1201. 'in (',conditionstr, ')');
  1202. end|
  1203. call bug15091();
  1204. ERROR 42S02: Unknown table 'c' in field list
  1205. drop procedure bug15091;
  1206. drop function if exists bug16896;
  1207. create aggregate function bug16896() returns int return 1;
  1208. ERROR 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 '() returns int return 1' at line 1
  1209. DROP PROCEDURE IF EXISTS bug14702;
  1210. CREATE IF NOT EXISTS PROCEDURE bug14702()
  1211. BEGIN
  1212. END;
  1213. ERROR 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 'IF NOT EXISTS PROCEDURE bug14702()
  1214. BEGIN
  1215. END' at line 1
  1216. CREATE PROCEDURE IF NOT EXISTS bug14702()
  1217. BEGIN
  1218. END;
  1219. ERROR 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 'IF NOT EXISTS bug14702()
  1220. BEGIN
  1221. END' at line 1
  1222. DROP TABLE IF EXISTS t1;
  1223. CREATE TABLE t1 (i INT);
  1224. CREATE PROCEDURE bug20953() CREATE VIEW v AS SELECT 1 INTO @a;
  1225. ERROR HY000: View's SELECT contains a 'INTO' clause
  1226. CREATE PROCEDURE bug20953() CREATE VIEW v AS SELECT 1 INTO DUMPFILE "file";
  1227. ERROR HY000: View's SELECT contains a 'INTO' clause
  1228. CREATE PROCEDURE bug20953() CREATE VIEW v AS SELECT 1 INTO OUTFILE "file";
  1229. ERROR HY000: View's SELECT contains a 'INTO' clause
  1230. CREATE PROCEDURE bug20953()
  1231. CREATE VIEW v AS SELECT i FROM t1 PROCEDURE ANALYSE();
  1232. ERROR HY000: View's SELECT contains a 'PROCEDURE' clause
  1233. CREATE PROCEDURE bug20953() CREATE VIEW v AS SELECT 1 FROM (SELECT 1) AS d1;
  1234. ERROR HY000: View's SELECT contains a subquery in the FROM clause
  1235. CREATE PROCEDURE bug20953(i INT) CREATE VIEW v AS SELECT i;
  1236. ERROR HY000: View's SELECT contains a variable or parameter
  1237. CREATE PROCEDURE bug20953()
  1238. BEGIN
  1239. DECLARE i INT;
  1240. CREATE VIEW v AS SELECT i;
  1241. END |
  1242. ERROR HY000: View's SELECT contains a variable or parameter
  1243. PREPARE stmt FROM "CREATE VIEW v AS SELECT ?";
  1244. ERROR HY000: View's SELECT contains a variable or parameter
  1245. DROP TABLE t1;
  1246. drop tables if exists t1;
  1247. drop procedure if exists bug24491;
  1248. create table t1 (id int primary key auto_increment, value varchar(10));
  1249. insert into t1 (id, value) values (1, 'FIRST'), (2, 'SECOND'), (3, 'THIRD');
  1250. create procedure bug24491()
  1251. insert into t1 (id, value) select * from (select 4 as i, 'FOURTH' as v) as y on duplicate key update v = 'DUP';
  1252. call bug24491();
  1253. ERROR 42S22: Unknown column 'v' in 'field list'
  1254. call bug24491();
  1255. ERROR 42S22: Unknown column 'v' in 'field list'
  1256. drop procedure bug24491;
  1257. create procedure bug24491()
  1258. insert into t1 (id, value) select * from (select 4 as id, 'FOURTH' as value) as y on duplicate key update y.value = 'DUP';
  1259. call bug24491();
  1260. ERROR 42S22: Unknown column 'y.value' in 'field list'
  1261. call bug24491();
  1262. ERROR 42S22: Unknown column 'y.value' in 'field list'
  1263. drop procedure bug24491;
  1264. drop tables t1;
  1265. DROP FUNCTION IF EXISTS bug18914_f1;
  1266. DROP FUNCTION IF EXISTS bug18914_f2;
  1267. DROP PROCEDURE IF EXISTS bug18914_p1;
  1268. DROP PROCEDURE IF EXISTS bug18914_p2;
  1269. DROP TABLE IF EXISTS t1, t2;
  1270. CREATE TABLE t1 (i INT);
  1271. CREATE PROCEDURE bug18914_p1() CREATE TABLE t2 (i INT);
  1272. CREATE PROCEDURE bug18914_p2() DROP TABLE IF EXISTS no_such_table;
  1273. CREATE FUNCTION bug18914_f1() RETURNS INT
  1274. BEGIN
  1275. CALL bug18914_p1();
  1276. RETURN 1;
  1277. END |
  1278. CREATE FUNCTION bug18914_f2() RETURNS INT
  1279. BEGIN
  1280. CALL bug18914_p2();
  1281. RETURN 1;
  1282. END |
  1283. CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW
  1284. CALL bug18914_p1();
  1285. INSERT INTO t1 VALUES (1);
  1286. ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger.
  1287. SELECT bug18914_f1();
  1288. ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger.
  1289. SELECT bug18914_f2();
  1290. ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger.
  1291. SELECT * FROM t2;
  1292. ERROR 42S02: Table 'test.t2' doesn't exist
  1293. DROP FUNCTION bug18914_f1;
  1294. DROP FUNCTION bug18914_f2;
  1295. DROP PROCEDURE bug18914_p1;
  1296. DROP PROCEDURE bug18914_p2;
  1297. DROP TABLE t1;
  1298. drop table if exists bogus_table_20713;
  1299. drop function if exists func_20713_a;
  1300. drop function if exists func_20713_b;
  1301. create table bogus_table_20713( id int(10) not null primary key);
  1302. insert into bogus_table_20713 values (1), (2), (3);
  1303. create function func_20713_a() returns int(11)
  1304. begin
  1305. declare id int;
  1306. declare continue handler for sqlexception set id=null;
  1307. set @in_func := 1;
  1308. set id = (select id from bogus_table_20713 where id = 3);
  1309. set @in_func := 2;
  1310. return id;
  1311. end//
  1312. create function func_20713_b() returns int(11)
  1313. begin
  1314. declare id int;
  1315. declare continue handler for sqlstate value '42S02' set id=null;
  1316. set @in_func := 1;
  1317. set id = (select id from bogus_table_20713 where id = 3);
  1318. set @in_func := 2;
  1319. return id;
  1320. end//
  1321. set @in_func := 0;
  1322. select func_20713_a();
  1323. func_20713_a()
  1324. NULL
  1325. select @in_func;
  1326. @in_func
  1327. 2
  1328. set @in_func := 0;
  1329. select func_20713_b();
  1330. func_20713_b()
  1331. NULL
  1332. select @in_func;
  1333. @in_func
  1334. 2
  1335. drop table bogus_table_20713;
  1336. set @in_func := 0;
  1337. select func_20713_a();
  1338. func_20713_a()
  1339. NULL
  1340. select @in_func;
  1341. @in_func
  1342. 2
  1343. set @in_func := 0;
  1344. select func_20713_b();
  1345. func_20713_b()
  1346. NULL
  1347. select @in_func;
  1348. @in_func
  1349. 2
  1350. drop function if exists func_20713_a;
  1351. drop function if exists func_20713_b;
  1352. drop table if exists table_25345_a;
  1353. drop table if exists table_25345_b;
  1354. drop procedure if exists proc_25345;
  1355. drop function if exists func_25345;
  1356. drop function if exists func_25345_b;
  1357. create table table_25345_a (a int);
  1358. create table table_25345_b (b int);
  1359. create procedure proc_25345()
  1360. begin
  1361. declare c1 cursor for select a from table_25345_a;
  1362. declare c2 cursor for select b from table_25345_b;
  1363. select 1 as result;
  1364. end ||
  1365. create function func_25345() returns int(11)
  1366. begin
  1367. call proc_25345();
  1368. return 1;
  1369. end ||
  1370. create function func_25345_b() returns int(11)
  1371. begin
  1372. declare c1 cursor for select a from table_25345_a;
  1373. declare c2 cursor for select b from table_25345_b;
  1374. return 1;
  1375. end ||
  1376. call proc_25345();
  1377. result
  1378. 1
  1379. select func_25345();
  1380. ERROR 0A000: Not allowed to return a result set from a function
  1381. select func_25345_b();
  1382. func_25345_b()
  1383. 1
  1384. drop table table_25345_a;
  1385. call proc_25345();
  1386. result
  1387. 1
  1388. select func_25345();
  1389. ERROR 0A000: Not allowed to return a result set from a function
  1390. select func_25345_b();
  1391. func_25345_b()
  1392. 1
  1393. drop table table_25345_b;
  1394. drop procedure proc_25345;
  1395. drop function func_25345;
  1396. drop function func_25345_b;
  1397. End of 5.0 tests
  1398. drop function if exists bug20701;
  1399. create function bug20701() returns varchar(25) binary return "test";
  1400. ERROR 42000: This version of MySQL doesn't yet support 'return value collation'
  1401. create function bug20701() returns varchar(25) return "test";
  1402. drop function bug20701;
  1403. create procedure proc_26503_error_1()
  1404. begin
  1405. retry:
  1406. repeat
  1407. begin
  1408. declare continue handler for sqlexception
  1409. begin
  1410. iterate retry;
  1411. end
  1412. select "do something";
  1413. end
  1414. until true end repeat retry;
  1415. end//
  1416. ERROR 42000: ITERATE with no matching label: retry
  1417. create procedure proc_26503_error_2()
  1418. begin
  1419. retry:
  1420. repeat
  1421. begin
  1422. declare continue handler for sqlexception
  1423. iterate retry;
  1424. select "do something";
  1425. end
  1426. until true end repeat retry;
  1427. end//
  1428. ERROR 42000: ITERATE with no matching label: retry
  1429. create procedure proc_26503_error_3()
  1430. begin
  1431. retry:
  1432. repeat
  1433. begin
  1434. declare continue handler for sqlexception
  1435. begin
  1436. leave retry;
  1437. end
  1438. select "do something";
  1439. end
  1440. until true end repeat retry;
  1441. end//
  1442. ERROR 42000: LEAVE with no matching label: retry
  1443. create procedure proc_26503_error_4()
  1444. begin
  1445. retry:
  1446. repeat
  1447. begin
  1448. declare continue handler for sqlexception
  1449. leave retry;
  1450. select "do something";
  1451. end
  1452. until true end repeat retry;
  1453. end//
  1454. ERROR 42000: LEAVE with no matching label: retry
  1455. drop procedure if exists proc_28360;
  1456. drop function if exists func_28360;
  1457. CREATE PROCEDURE proc_28360()
  1458. BEGIN
  1459. ALTER DATABASE `#mysql50#upgrade-me` UPGRADE DATA DIRECTORY NAME;
  1460. END//
  1461. ERROR HY000: Can't drop or alter a DATABASE from within another stored routine
  1462. CREATE FUNCTION func_28360() RETURNS int
  1463. BEGIN
  1464. ALTER DATABASE `#mysql50#upgrade-me` UPGRADE DATA DIRECTORY NAME;
  1465. RETURN 0;
  1466. END//
  1467. ERROR HY000: Can't drop or alter a DATABASE from within another stored routine
  1468. DROP PROCEDURE IF EXISTS p1;
  1469. CREATE PROCEDURE p1()
  1470. BEGIN
  1471. DECLARE c char(100);
  1472. DECLARE cur1 CURSOR FOR SHOW TABLES;
  1473. OPEN cur1;
  1474. FETCH cur1 INTO c;
  1475. select c;
  1476. CLOSE cur1;
  1477. END|
  1478. ERROR 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 'SHOW TABLES;
  1479. OPEN cur1;
  1480. FETCH cur1 INTO c;
  1481. select c;
  1482. CLOSE cur1;
  1483. END' at line 4
  1484. DROP DATABASE IF EXISTS mysqltest;
  1485. CREATE DATABASE mysqltest;
  1486. USE mysqltest;
  1487. DROP DATABASE mysqltest;
  1488. SELECT inexistent(), 1 + ,;
  1489. ERROR 42000: FUNCTION inexistent does not exist
  1490. SELECT inexistent();
  1491. ERROR 42000: FUNCTION inexistent does not exist
  1492. SELECT .inexistent();
  1493. ERROR 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 1
  1494. SELECT ..inexistent();
  1495. ERROR 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 '.inexistent()' at line 1
  1496. USE test;
  1497. create function f1() returns int
  1498. begin
  1499. set @test = 1, password = password('foo');
  1500. return 1;
  1501. end|
  1502. ERROR HY000: Not allowed to set autocommit from a stored function or trigger
  1503. create trigger t1
  1504. before insert on t2 for each row set password = password('foo');|
  1505. ERROR HY000: Not allowed to set autocommit from a stored function or trigger
  1506. drop function if exists f1;
  1507. drop function if exists f2;
  1508. drop table if exists t1, t2;
  1509. create function f1() returns int
  1510. begin
  1511. drop temporary table t1;
  1512. return 1;
  1513. end|
  1514. create temporary table t1 as select f1();
  1515. ERROR HY000: Can't reopen table: 't1'
  1516. create function f2() returns int
  1517. begin
  1518. create temporary table t2 as select f1();
  1519. return 1;
  1520. end|
  1521. create temporary table t1 as select f2();
  1522. ERROR HY000: Can't reopen table: 't1'
  1523. drop function f1;
  1524. drop function f2;
  1525. create function f1() returns int
  1526. begin
  1527. drop temporary table t2,t1;
  1528. return 1;
  1529. end|
  1530. create function f2() returns int
  1531. begin
  1532. create temporary table t2 as select f1();
  1533. return 1;
  1534. end|
  1535. create temporary table t1 as select f2();
  1536. ERROR HY000: Can't reopen table: 't2'
  1537. drop function f1;
  1538. drop function f2;
  1539. create temporary table t2(a int);
  1540. select * from t2;
  1541. a
  1542. create function f2() returns int
  1543. begin
  1544. drop temporary table t2;
  1545. return 1;
  1546. end|
  1547. select f2();
  1548. f2()
  1549. 1
  1550. drop function f2;
  1551. drop table t2;
  1552. ERROR 42S02: Unknown table 'test.t2'
  1553. End of 5.1 tests
  1554. drop procedure if exists proc_33983_a;
  1555. drop procedure if exists proc_33983_b;
  1556. drop procedure if exists proc_33983_c;
  1557. drop procedure if exists proc_33983_d;
  1558. create procedure proc_33983_a()
  1559. begin
  1560. label1:
  1561. begin
  1562. label2:
  1563. begin
  1564. select 1;
  1565. end label1;
  1566. end;
  1567. end|
  1568. ERROR 42000: End-label label1 without match
  1569. create procedure proc_33983_b()
  1570. begin
  1571. label1:
  1572. repeat
  1573. label2:
  1574. repeat
  1575. select 1;
  1576. until FALSE end repeat label1;
  1577. until FALSE end repeat;
  1578. end|
  1579. ERROR 42000: End-label label1 without match
  1580. create procedure proc_33983_c()
  1581. begin
  1582. label1:
  1583. while TRUE do
  1584. label2:
  1585. while TRUE do
  1586. select 1;
  1587. end while label1;
  1588. end while;
  1589. end|
  1590. ERROR 42000: End-label label1 without match
  1591. create procedure proc_33983_d()
  1592. begin
  1593. label1:
  1594. loop
  1595. label2:
  1596. loop
  1597. select 1;
  1598. end loop label1;
  1599. end loop;
  1600. end|
  1601. ERROR 42000: End-label label1 without match
  1602. CREATE TABLE t1 (a INT)|
  1603. INSERT INTO t1 VALUES (1),(2)|
  1604. CREATE PROCEDURE p1(a INT) BEGIN END|
  1605. CALL p1((SELECT * FROM t1))|
  1606. ERROR 21000: Subquery returns more than 1 row
  1607. DROP PROCEDURE IF EXISTS p1|
  1608. DROP TABLE t1|
  1609. drop procedure if exists p1;
  1610. create procedure p1()
  1611. begin
  1612. create table t1 (a int) engine=MyISAM;
  1613. drop table t1;
  1614. end|
  1615. call p1();
  1616. call p1();
  1617. drop procedure p1;
  1618. drop procedure if exists proc_8759;
  1619. create procedure proc_8759()
  1620. begin
  1621. declare should_be_illegal condition for sqlstate '00000';
  1622. declare continue handler for should_be_illegal set @x=0;
  1623. end$$
  1624. ERROR 42000: Bad SQLSTATE: '00000'
  1625. create procedure proc_8759()
  1626. begin
  1627. declare continue handler for sqlstate '00000' set @x=0;
  1628. end$$
  1629. ERROR 42000: Bad SQLSTATE: '00000'
  1630. drop procedure if exists proc_36510;
  1631. create procedure proc_36510()
  1632. begin
  1633. declare should_be_illegal condition for sqlstate '00123';
  1634. declare continue handler for should_be_illegal set @x=0;
  1635. end$$
  1636. ERROR 42000: Bad SQLSTATE: '00123'
  1637. create procedure proc_36510()
  1638. begin
  1639. declare continue handler for sqlstate '00123' set @x=0;
  1640. end$$
  1641. ERROR 42000: Bad SQLSTATE: '00123'
  1642. create procedure proc_36510()
  1643. begin
  1644. declare should_be_illegal condition for 0;
  1645. declare continue handler for should_be_illegal set @x=0;
  1646. end$$
  1647. ERROR HY000: Incorrect CONDITION value: '0'
  1648. create procedure proc_36510()
  1649. begin
  1650. declare continue handler for 0 set @x=0;
  1651. end$$
  1652. ERROR HY000: Incorrect CONDITION value: '0'
  1653. drop procedure if exists p1;
  1654. set @old_recursion_depth = @@max_sp_recursion_depth;
  1655. set @@max_sp_recursion_depth = 255;
  1656. create procedure p1(a int)
  1657. begin
  1658. declare continue handler for 1436 -- ER_STACK_OVERRUN_NEED_MORE
  1659. select 'exception';
  1660. call p1(a+1);
  1661. end|
  1662. call p1(1);
  1663. set @@max_sp_recursion_depth = @old_recursion_depth;
  1664. drop procedure p1;
  1665. LOAD DATA INFILE '../../tmp/proc.txt' INTO TABLE mysql.proc;
  1666. CREATE TABLE t1 (a INT, b INT);
  1667. INSERT INTO t1 VALUES (1,1), (2,2);
  1668. SELECT MAX (a) FROM t1 WHERE b = 999999;
  1669. ERROR 42000: FUNCTION test.MAX does not exist. Check the 'Function Name Parsing and Resolution' section in the Reference Manual
  1670. SELECT AVG (a) FROM t1 WHERE b = 999999;
  1671. AVG (a)
  1672. NULL
  1673. SELECT non_existent (a) FROM t1 WHERE b = 999999;
  1674. ERROR 42000: FUNCTION test.non_existent does not exist
  1675. DROP TABLE t1;
  1676. CREATE TABLE t1 ( f2 INTEGER, f3 INTEGER );
  1677. INSERT INTO t1 VALUES ( 1, 1 );
  1678. CREATE FUNCTION func_1 () RETURNS INTEGER
  1679. BEGIN
  1680. INSERT INTO t1 SELECT * FROM t1 ;
  1681. RETURN 1 ;
  1682. END|
  1683. INSERT INTO t1 SELECT * FROM (SELECT 2 AS f1, 2 AS f2) AS A WHERE func_1() = 5;
  1684. ERROR HY000: Can't update table 't1' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
  1685. DROP FUNCTION func_1;
  1686. DROP TABLE t1;
  1687. #
  1688. # Bug #47788: Crash in TABLE_LIST::hide_view_error on UPDATE + VIEW +
  1689. # SP + MERGE + ALTER
  1690. #
  1691. CREATE TABLE t1 (pk INT, b INT, KEY (b));
  1692. CREATE ALGORITHM = TEMPTABLE VIEW v1 AS SELECT * FROM t1;
  1693. CREATE PROCEDURE p1 (a int) UPDATE IGNORE v1 SET b = a;
  1694. CALL p1(5);
  1695. ERROR HY000: The target table v1 of the UPDATE is not updatable
  1696. ALTER TABLE t1 CHANGE COLUMN b b2 INT;
  1697. CALL p1(7);
  1698. ERROR HY000: View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
  1699. DROP PROCEDURE p1;
  1700. DROP VIEW v1;
  1701. DROP TABLE t1;
  1702. #
  1703. # Bug#12428824 - PARSER STACK OVERFLOW AND CRASH IN SP_ADD_USED_ROUTINE
  1704. # WITH OBSCURE QUERY
  1705. #
  1706. SELECT very_long_fn_name_1111111111111111111111111111111111111111111111111111111111111111111111111222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222225555555555555555555555555577777777777777777777777777777777777777777777777777777777777777777777777788888888999999999999999999999();
  1707. ERROR 42000: Identifier name 'very_long_fn_name_1111111111111111111111111111111111111111111111111111111111111111111111111222222222' is too long
  1708. CALL very_long_pr_name_1111111111111111111111111111111111111111111111111111111111111111111111111222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222225555555555555555555555555577777777777777777777777777777777777777777777777777777777777777777777777788888888999999999999999999999();
  1709. ERROR 42000: Identifier name 'very_long_pr_name_1111111111111111111111111111111111111111111111111111111111111111111111111222222222' is too long
  1710. SELECT very_long_db_name_1111111111111111111111111111111111111111111111111111111111111111111111111222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222225555555555555555555555555577777777777777777777777777777777777777777777777777777777777777777777777788888888999999999999999999999.simple_func();
  1711. ERROR 42000: Incorrect database name 'very_long_db_name_1111111111111111111111111111111111111111111111111111111111111111111111111222222222'
  1712. CALL very_long_db_name_1111111111111111111111111111111111111111111111111111111111111111111111111222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222225555555555555555555555555577777777777777777777777777777777777777777777777777777777777777777777777788888888999999999999999999999.simple_proc();
  1713. ERROR 42000: Incorrect database name 'very_long_db_name_1111111111111111111111111111111111111111111111111111111111111111111111111222222222'
  1714. SELECT db_name.very_long_fn_name_111111111111111111111111111111111111111111111111111111111111111111111111122222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999999999999999999();
  1715. ERROR 42000: Identifier name 'very_long_fn_name_1111111111111111111111111111111111111111111111111111111111111111111111111222222222' is too long
  1716. CALL db_name.very_long_pr_name_111111111111111111111111111111111111111111111111111111111111111111111111122222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999999999999999999();
  1717. ERROR 42000: Identifier name 'very_long_pr_name_1111111111111111111111111111111111111111111111111111111111111111111111111222222222' is too long
  1718. End of 5.1 tests
  1719. #
  1720. # Bug#23032: Handlers declared in a SP do not handle warnings generated in sub-SP
  1721. #
  1722. # - Case 1
  1723. DROP PROCEDURE IF EXISTS p1;
  1724. DROP PROCEDURE IF EXISTS p2;
  1725. DROP PROCEDURE IF EXISTS p3;
  1726. DROP PROCEDURE IF EXISTS p4;
  1727. DROP PROCEDURE IF EXISTS p5;
  1728. DROP PROCEDURE IF EXISTS p6;
  1729. CREATE PROCEDURE p1()
  1730. BEGIN
  1731. SELECT CAST('10 ' as unsigned integer);
  1732. SELECT 1;
  1733. CALL p2();
  1734. END|
  1735. CREATE PROCEDURE p2()
  1736. BEGIN
  1737. SELECT CAST('10 ' as unsigned integer);
  1738. END|
  1739. CALL p1();
  1740. CAST('10 ' as unsigned integer)
  1741. 10
  1742. 1
  1743. 1
  1744. CAST('10 ' as unsigned integer)
  1745. 10
  1746. Warnings:
  1747. Warning 1292 Truncated incorrect INTEGER value: '10 '
  1748. DROP PROCEDURE p1;
  1749. DROP PROCEDURE p2;
  1750. # - Case 2
  1751. DROP TABLE IF EXISTS t1;
  1752. CREATE TABLE t1(a INT);
  1753. CREATE PROCEDURE p1()
  1754. BEGIN
  1755. DECLARE c INT DEFAULT 0;
  1756. DECLARE CONTINUE HANDLER FOR SQLWARNING
  1757. BEGIN
  1758. SET c = c + 1;
  1759. SELECT 'Warning caught!' AS Msg;
  1760. END;
  1761. CALL p2(); # 1 warning
  1762. CALL p3(); # 1 warning
  1763. CALL p4(); # No warnings
  1764. CALL p5(); # 1 warning
  1765. SELECT c;
  1766. SELECT @@warning_count;
  1767. SHOW WARNINGS;
  1768. END|
  1769. CREATE PROCEDURE p2()
  1770. BEGIN
  1771. SELECT CAST('2 ' as unsigned integer);
  1772. END|
  1773. CREATE PROCEDURE p3()
  1774. BEGIN
  1775. SELECT CAST('3 ' as unsigned integer);
  1776. SELECT 1; # does not clear the warning
  1777. END|
  1778. CREATE PROCEDURE p4()
  1779. BEGIN
  1780. SELECT CAST('4 ' as unsigned integer);
  1781. INSERT INTO t1 VALUES(1); # Clears the warning
  1782. END|
  1783. CREATE PROCEDURE p5()
  1784. BEGIN
  1785. SELECT CAST('5 ' as unsigned integer);
  1786. CALL p2();
  1787. END|
  1788. CREATE PROCEDURE p6()
  1789. BEGIN
  1790. SELECT CAST('6 ' as unsigned integer);
  1791. SHOW WARNINGS;
  1792. END|
  1793. CREATE PROCEDURE p7()
  1794. BEGIN
  1795. DECLARE c INT DEFAULT 0;
  1796. DECLARE CONTINUE HANDLER FOR SQLWARNING
  1797. BEGIN
  1798. SET c = c + 1;
  1799. SELECT 'Warning caught!' AS Msg;
  1800. END;
  1801. CALL p6();
  1802. SELECT c;
  1803. END|
  1804. CALL p1();
  1805. CAST('2 ' as unsigned integer)
  1806. 2
  1807. Msg
  1808. Warning caught!
  1809. CAST('3 ' as unsigned integer)
  1810. 3
  1811. 1
  1812. 1
  1813. Msg
  1814. Warning caught!
  1815. CAST('4 ' as unsigned integer)
  1816. 4
  1817. CAST('5 ' as unsigned integer)
  1818. 5
  1819. CAST('2 ' as unsigned integer)
  1820. 2
  1821. Msg
  1822. Warning caught!
  1823. c
  1824. 3
  1825. @@warning_count
  1826. 0
  1827. Level Code Message
  1828. CALL p7();
  1829. CAST('6 ' as unsigned integer)
  1830. 6
  1831. Level Code Message
  1832. Warning 1292 Truncated incorrect INTEGER value: '6 '
  1833. Msg
  1834. Warning caught!
  1835. c
  1836. 1
  1837. DROP PROCEDURE p1;
  1838. DROP PROCEDURE p2;
  1839. DROP PROCEDURE p3;
  1840. DROP PROCEDURE p4;
  1841. DROP PROCEDURE p5;
  1842. DROP PROCEDURE p6;
  1843. DROP PROCEDURE p7;
  1844. DROP TABLE t1;
  1845. # - Case 3: check that "Exception trumps No Data".
  1846. DROP TABLE IF EXISTS t1;
  1847. CREATE TABLE t1(a INT);
  1848. INSERT INTO t1 VALUES (1), (2), (3);
  1849. CREATE PROCEDURE p1()
  1850. BEGIN
  1851. DECLARE c CURSOR FOR SELECT a FROM t1;
  1852. OPEN c;
  1853. BEGIN
  1854. DECLARE v1 INT;
  1855. DECLARE v2 INT;
  1856. DECLARE EXIT HANDLER FOR SQLEXCEPTION
  1857. SELECT "Error caught (expected)";
  1858. DECLARE EXIT HANDLER FOR NOT FOUND
  1859. SELECT "End of Result Set found!";
  1860. WHILE TRUE DO
  1861. FETCH c INTO v1, v2;
  1862. END WHILE;
  1863. END;
  1864. CLOSE c;
  1865. SELECT a INTO @foo FROM t1 LIMIT 1; # Clear warning stack
  1866. END|
  1867. CALL p1();
  1868. Error caught (expected)
  1869. Error caught (expected)
  1870. DROP PROCEDURE p1;
  1871. DROP TABLE t1;
  1872. #
  1873. # Bug#36185: Incorrect precedence for warning and exception handlers
  1874. #
  1875. DROP TABLE IF EXISTS t1;
  1876. DROP PROCEDURE IF EXISTS p1;
  1877. CREATE TABLE t1 (a INT, b INT NOT NULL);
  1878. CREATE PROCEDURE p1()
  1879. BEGIN
  1880. DECLARE CONTINUE HANDLER FOR SQLWARNING SELECT 'warning';
  1881. DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SELECT 'exception';
  1882. INSERT INTO t1 VALUES (CAST('10 ' AS SIGNED), NULL);
  1883. END|
  1884. CALL p1();
  1885. exception
  1886. exception
  1887. DROP TABLE t1;
  1888. DROP PROCEDURE p1;
  1889. #
  1890. # Bug#5889: Exit handler for a warning doesn't hide the warning in trigger
  1891. #
  1892. CREATE TABLE t1(a INT, b INT);
  1893. INSERT INTO t1 VALUES (1, 2);
  1894. CREATE TRIGGER t1_bu BEFORE UPDATE ON t1 FOR EACH ROW
  1895. BEGIN
  1896. DECLARE EXIT HANDLER FOR SQLWARNING
  1897. SET NEW.a = 10;
  1898. SET NEW.a = 99999999999;
  1899. END|
  1900. UPDATE t1 SET b = 20;
  1901. SHOW WARNINGS;
  1902. Level Code Message
  1903. SELECT * FROM t1;
  1904. a b
  1905. 10 20
  1906. DROP TRIGGER t1_bu;
  1907. DROP TABLE t1;
  1908. #
  1909. # Bug#9857: Stored procedures: handler for sqlwarning ignored
  1910. #
  1911. SET @sql_mode_saved = @@sql_mode;
  1912. SET sql_mode = traditional;
  1913. CREATE PROCEDURE p1()
  1914. BEGIN
  1915. DECLARE CONTINUE HANDLER FOR SQLWARNING
  1916. SELECT 'warning caught (expected)';
  1917. SELECT 5 / 0;
  1918. END|
  1919. CREATE PROCEDURE p2()
  1920. BEGIN
  1921. DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
  1922. SELECT 'error caught (unexpected)';
  1923. SELECT 5 / 0;
  1924. END|
  1925. CALL p1();
  1926. 5 / 0
  1927. NULL
  1928. warning caught (expected)
  1929. warning caught (expected)
  1930. SHOW WARNINGS;
  1931. Level Code Message
  1932. CALL p2();
  1933. 5 / 0
  1934. NULL
  1935. Warnings:
  1936. Warning 1365 Division by 0
  1937. SHOW WARNINGS;
  1938. Level Code Message
  1939. Warning 1365 Division by 0
  1940. DROP PROCEDURE p1;
  1941. DROP PROCEDURE p2;
  1942. SET sql_mode = @sql_mode_saved;
  1943. #
  1944. # Bug#55850: Trigger warnings not cleared.
  1945. #
  1946. DROP TABLE IF EXISTS t1;
  1947. DROP TABLE IF EXISTS t2;
  1948. DROP PROCEDURE IF EXISTS p1;
  1949. CREATE TABLE t1(x SMALLINT, y SMALLINT, z SMALLINT);
  1950. CREATE TABLE t2(a SMALLINT, b SMALLINT, c SMALLINT,
  1951. d SMALLINT, e SMALLINT, f SMALLINT);
  1952. CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW
  1953. INSERT INTO t2(a, b, c) VALUES(99999, 99999, 99999);
  1954. CREATE TRIGGER t1_ai AFTER INSERT ON t1 FOR EACH ROW
  1955. INSERT INTO t2(d, e, f) VALUES(99999, 99999, 99999);
  1956. CREATE PROCEDURE p1()
  1957. INSERT INTO t1 VALUES(99999, 99999, 99999);
  1958. CALL p1();
  1959. Warnings:
  1960. Warning 1264 Out of range value for column 'x' at row 1
  1961. Warning 1264 Out of range value for column 'y' at row 1
  1962. Warning 1264 Out of range value for column 'z' at row 1
  1963. SHOW WARNINGS;
  1964. Level Code Message
  1965. Warning 1264 Out of range value for column 'x' at row 1
  1966. Warning 1264 Out of range value for column 'y' at row 1
  1967. Warning 1264 Out of range value for column 'z' at row 1
  1968. DROP TABLE t1;
  1969. DROP TABLE t2;
  1970. DROP PROCEDURE p1;
  1971. # ----------------------------------------------------------------------
  1972. CREATE TABLE t1(x SMALLINT, y SMALLINT, z SMALLINT);
  1973. CREATE TABLE t2(a SMALLINT, b SMALLINT, c SMALLINT NOT NULL);
  1974. CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW
  1975. BEGIN
  1976. INSERT INTO t2 VALUES(
  1977. CAST('111111 ' AS SIGNED),
  1978. CAST('222222 ' AS SIGNED),
  1979. NULL);
  1980. END|
  1981. CREATE PROCEDURE p1()
  1982. INSERT INTO t1 VALUES(99999, 99999, 99999);
  1983. CALL p1();
  1984. ERROR 23000: Column 'c' cannot be null
  1985. SHOW WARNINGS;
  1986. Level Code Message
  1987. Warning 1264 Out of range value for column 'x' at row 1
  1988. Warning 1264 Out of range value for column 'y' at row 1
  1989. Warning 1264 Out of range value for column 'z' at row 1
  1990. Warning 1292 Truncated incorrect INTEGER value: '111111 '
  1991. Warning 1264 Out of range value for column 'a' at row 1
  1992. Warning 1292 Truncated incorrect INTEGER value: '222222 '
  1993. Warning 1264 Out of range value for column 'b' at row 1
  1994. Error 1048 Column 'c' cannot be null
  1995. DROP TABLE t1;
  1996. DROP TABLE t2;
  1997. DROP PROCEDURE p1;
  1998. ###################################################################
  1999. # Tests for the following bugs:
  2000. # - Bug#11763171: 55852 - Possibly inappropriate handler activation.
  2001. # - Bug#11749343: 38806 - Wrong scope for SQL HANDLERS in SP.
  2002. ###################################################################
  2003. # -- Check that SQL-conditions thrown by Statement-blocks are
  2004. # -- handled by Handler-decl blocks properly.
  2005. CREATE PROCEDURE p1()
  2006. BEGIN
  2007. DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
  2008. SELECT 'H1' AS HandlerId;
  2009. DECLARE CONTINUE HANDLER FOR SQLWARNING
  2010. SELECT 'H2' AS HandlerId;
  2011. SIGNAL SQLSTATE '01000'; # Should be handled by H2.
  2012. END|
  2013. CALL p1()|
  2014. HandlerId
  2015. H2
  2016. # -- Check that SQL-conditions thrown by Statement-blocks are
  2017. # -- handled by Handler-decl blocks properly in case of nested
  2018. # -- SQL-blocks.
  2019. CREATE PROCEDURE p2()
  2020. BEGIN
  2021. DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
  2022. SELECT 'H1' AS HandlerId;
  2023. DECLARE CONTINUE HANDLER FOR SQLWARNING
  2024. SELECT 'H2' AS HandlerId;
  2025. BEGIN
  2026. SELECT 'B1' AS BlockId;
  2027. BEGIN
  2028. SELECT 'B2' AS BlockId;
  2029. BEGIN
  2030. SELECT 'B3' AS BlockId;
  2031. SIGNAL SQLSTATE '01000'; # Should be handled by H2.
  2032. END;
  2033. END;
  2034. END;
  2035. END|
  2036. CALL p2()|
  2037. BlockId
  2038. B1
  2039. BlockId
  2040. B2
  2041. BlockId
  2042. B3
  2043. HandlerId
  2044. H2
  2045. # -- Check SQL-handler resolution rules.
  2046. CREATE PROCEDURE p3()
  2047. BEGIN
  2048. DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
  2049. SELECT 'H1' AS HandlerId;
  2050. DECLARE CONTINUE HANDLER FOR SQLWARNING
  2051. SELECT 'H2' AS HandlerId;
  2052. DECLARE CONTINUE HANDLER FOR SQLSTATE '01000'
  2053. SELECT 'H3' AS HandlerId;
  2054. SIGNAL SQLSTATE '01000'; # Should be handled by H3.
  2055. END|
  2056. CALL p3()|
  2057. HandlerId
  2058. H3
  2059. CREATE PROCEDURE p4()
  2060. BEGIN
  2061. DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
  2062. SELECT 'H1' AS HandlerId;
  2063. DECLARE CONTINUE HANDLER FOR SQLSTATE '01000'
  2064. SELECT 'H2' AS HandlerId;
  2065. DECLARE CONTINUE HANDLER FOR SQLWARNING
  2066. SELECT 'H3' AS HandlerId;
  2067. SIGNAL SQLSTATE '01000'; # Should be handled by H2.
  2068. END|
  2069. CALL p4()|
  2070. HandlerId
  2071. H2
  2072. CREATE PROCEDURE p5()
  2073. BEGIN
  2074. DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
  2075. SELECT 'H1' AS HandlerId;
  2076. DECLARE CONTINUE HANDLER FOR SQLSTATE '01000'
  2077. SELECT 'H2' AS HandlerId;
  2078. BEGIN
  2079. DECLARE CONTINUE HANDLER FOR SQLWARNING
  2080. SELECT 'H3' AS HandlerId;
  2081. SIGNAL SQLSTATE '01000'; # Should be handled by H3.
  2082. END;
  2083. END|
  2084. CALL p5()|
  2085. HandlerId
  2086. H3
  2087. # -- Check that handlers don't handle its own exceptions.
  2088. CREATE PROCEDURE p6()
  2089. BEGIN
  2090. DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
  2091. BEGIN
  2092. SELECT 'H1' AS HandlerId;
  2093. SIGNAL SQLSTATE 'HY000'; # Should *not* be handled by H1.
  2094. END;
  2095. SELECT 'S1' AS SignalId;
  2096. SIGNAL SQLSTATE 'HY000'; # Should be handled by H1.
  2097. END|
  2098. CALL p6()|
  2099. SignalId
  2100. S1
  2101. HandlerId
  2102. H1
  2103. ERROR HY000: Unhandled user-defined exception condition
  2104. # -- Check that handlers don't handle its own warnings.
  2105. CREATE PROCEDURE p7()
  2106. BEGIN
  2107. DECLARE CONTINUE HANDLER FOR SQLWARNING
  2108. BEGIN
  2109. SELECT 'H1' AS HandlerId;
  2110. SIGNAL SQLSTATE '01000'; # Should *not* be handled by H1.
  2111. END;
  2112. SELECT 'S1' AS SignalId;
  2113. SIGNAL SQLSTATE '01000'; # Should be handled by H1.
  2114. END|
  2115. CALL p7()|
  2116. SignalId
  2117. S1
  2118. HandlerId
  2119. H1
  2120. Warnings:
  2121. Warning 1642 Unhandled user-defined warning condition
  2122. # -- Check that conditions for handlers are not handled by the handlers
  2123. # -- from the same block.
  2124. CREATE PROCEDURE p8()
  2125. BEGIN
  2126. DECLARE CONTINUE HANDLER FOR SQLWARNING
  2127. SELECT 'H1' AS HandlerId;
  2128. DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
  2129. BEGIN
  2130. SELECT 'H2' AS HandlerId;
  2131. SIGNAL SQLSTATE '01000'; # Should *not* be handled by H1.
  2132. END;
  2133. SELECT 'S1' AS SignalId;
  2134. SIGNAL SQLSTATE 'HY000'; # Should be handled by H2.
  2135. END|
  2136. CALL p8()|
  2137. SignalId
  2138. S1
  2139. HandlerId
  2140. H2
  2141. Warnings:
  2142. Warning 1642 Unhandled user-defined warning condition
  2143. # -- Check that conditions for handlers are not handled by the handlers
  2144. # -- from the same block even if they are thrown deep down the stack.
  2145. CREATE PROCEDURE p9()
  2146. BEGIN
  2147. DECLARE CONTINUE HANDLER FOR SQLSTATE '01000'
  2148. SELECT 'Wrong:H1:1' AS HandlerId;
  2149. DECLARE CONTINUE HANDLER FOR SQLWARNING
  2150. SELECT 'Wrong:H1:2' AS HandlerId;
  2151. DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
  2152. BEGIN
  2153. DECLARE CONTINUE HANDLER FOR SQLSTATE '01000'
  2154. SELECT 'Wrong:H2:1' AS HandlerId;
  2155. DECLARE CONTINUE HANDLER FOR SQLWARNING
  2156. SELECT 'Wrong:H2:2' AS HandlerId;
  2157. DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
  2158. BEGIN
  2159. DECLARE CONTINUE HANDLER FOR SQLSTATE '01000'
  2160. SELECT 'Wrong:H3:1' AS HandlerId;
  2161. DECLARE CONTINUE HANDLER FOR SQLWARNING
  2162. SELECT 'Wrong:H3:2' AS HandlerId;
  2163. DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
  2164. BEGIN
  2165. DECLARE CONTINUE HANDLER FOR SQLSTATE '01000'
  2166. SELECT 'Wrong:H4:1' AS HandlerId;
  2167. DECLARE CONTINUE HANDLER FOR SQLWARNING
  2168. SELECT 'Wrong:H4:2' AS HandlerId;
  2169. DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
  2170. BEGIN
  2171. DECLARE CONTINUE HANDLER FOR SQLSTATE '01000'
  2172. SELECT 'Wrong:H5:1' AS HandlerId;
  2173. DECLARE CONTINUE HANDLER FOR SQLWARNING
  2174. SELECT 'Wrong:H5:2' AS HandlerId;
  2175. DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
  2176. BEGIN
  2177. DECLARE CONTINUE HANDLER FOR SQLSTATE '01000'
  2178. SELECT 'Wrong:H6:1' AS HandlerId;
  2179. DECLARE CONTINUE HANDLER FOR SQLWARNING
  2180. SELECT 'Wrong:H6:2' AS HandlerId;
  2181. DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
  2182. BEGIN
  2183. SELECT 'H2' AS HandlerId;
  2184. SIGNAL SQLSTATE '01000'; # Should *not* be handled by H1.
  2185. END;
  2186. SELECT 'S6' AS SignalId;
  2187. SIGNAL SQLSTATE 'HY000';
  2188. END;
  2189. SELECT 'S5' AS SignalId;
  2190. SIGNAL SQLSTATE 'HY000';
  2191. END;
  2192. SELECT 'S4' AS SignalId;
  2193. SIGNAL SQLSTATE 'HY000';
  2194. END;
  2195. SELECT 'S3' AS SignalId;
  2196. SIGNAL SQLSTATE 'HY000';
  2197. END;
  2198. SELECT 'S2' AS SignalId;
  2199. SIGNAL SQLSTATE 'HY000';
  2200. END;
  2201. SELECT 'S1' AS SignalId;
  2202. SIGNAL SQLSTATE 'HY000'; # Should be handled by H2.
  2203. END|
  2204. CALL p9()|
  2205. SignalId
  2206. S1
  2207. SignalId
  2208. S2
  2209. SignalId
  2210. S3
  2211. SignalId
  2212. S4
  2213. SignalId
  2214. S5
  2215. SignalId
  2216. S6
  2217. HandlerId
  2218. H2
  2219. Warnings:
  2220. Warning 1642 Unhandled user-defined warning condition
  2221. # -- Check that handlers are choosen properly in case of deep stack and
  2222. # -- nested SQL-blocks.
  2223. CREATE PROCEDURE p10()
  2224. BEGIN
  2225. DECLARE CONTINUE HANDLER FOR SQLSTATE '01000'
  2226. SELECT 'H1' AS HandlerId;
  2227. DECLARE CONTINUE HANDLER FOR SQLWARNING
  2228. SELECT 'H2' AS HandlerId;
  2229. BEGIN
  2230. BEGIN
  2231. BEGIN
  2232. DECLARE CONTINUE HANDLER FOR SQLSTATE '01000'
  2233. SELECT 'Wrong:H1:1' AS HandlerId;
  2234. DECLARE CONTINUE HANDLER FOR SQLWARNING
  2235. SELECT 'Wrong:H1:2' AS HandlerId;
  2236. DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
  2237. BEGIN
  2238. DECLARE CONTINUE HANDLER FOR SQLSTATE '01000'
  2239. SELECT 'Wrong:H2:1' AS HandlerId;
  2240. DECLARE CONTINUE HANDLER FOR SQLWARNING
  2241. SELECT 'Wrong:H2:2' AS HandlerId;
  2242. DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
  2243. BEGIN
  2244. DECLARE CONTINUE HANDLER FOR SQLSTATE '01000'
  2245. SELECT 'Wrong:H3:1' AS HandlerId;
  2246. DECLARE CONTINUE HANDLER FOR SQLWARNING
  2247. SELECT 'Wrong:H3:2' AS HandlerId;
  2248. DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
  2249. BEGIN
  2250. DECLARE CONTINUE HANDLER FOR SQLSTATE '01000'
  2251. SELECT 'Wrong:H4:1' AS HandlerId;
  2252. DECLARE CONTINUE HANDLER FOR SQLWARNING
  2253. SELECT 'Wrong:H4:2' AS HandlerId;
  2254. DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
  2255. BEGIN
  2256. DECLARE CONTINUE HANDLER FOR SQLSTATE '01000'
  2257. SELECT 'Wrong:H5:1' AS HandlerId;
  2258. DECLARE CONTINUE HANDLER FOR SQLWARNING
  2259. SELECT 'Wrong:H5:2' AS HandlerId;
  2260. DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
  2261. BEGIN
  2262. DECLARE CONTINUE HANDLER FOR SQLSTATE '01000'
  2263. SELECT 'Wrong:H6:1' AS HandlerId;
  2264. DECLARE CONTINUE HANDLER FOR SQLWARNING
  2265. SELECT 'Wrong:H6:2' AS HandlerId;
  2266. DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
  2267. BEGIN
  2268. SELECT 'H2' AS HandlerId;
  2269. SIGNAL SQLSTATE '01000'; # Should be handled by H1.
  2270. END;
  2271. SELECT 'S6' AS SignalId;
  2272. SIGNAL SQLSTATE 'HY000';
  2273. END;
  2274. SELECT 'S5' AS SignalId;
  2275. SIGNAL SQLSTATE 'HY000';
  2276. END;
  2277. SELECT 'S4' AS SignalId;
  2278. SIGNAL SQLSTATE 'HY000';
  2279. END;
  2280. SELECT 'S3' AS SignalId;
  2281. SIGNAL SQLSTATE 'HY000';
  2282. END;
  2283. SELECT 'S2' AS SignalId;
  2284. SIGNAL SQLSTATE 'HY000';
  2285. END;
  2286. SELECT 'S1' AS SignalId;
  2287. SIGNAL SQLSTATE 'HY000'; # Should be handled by H2.
  2288. END;
  2289. END;
  2290. END;
  2291. END|
  2292. CALL p10()|
  2293. SignalId
  2294. S1
  2295. SignalId
  2296. S2
  2297. SignalId
  2298. S3
  2299. SignalId
  2300. S4
  2301. SignalId
  2302. S5
  2303. SignalId
  2304. S6
  2305. HandlerId
  2306. H2
  2307. HandlerId
  2308. H1
  2309. # -- Test stored procedure from Peter's mail.
  2310. CREATE PROCEDURE p11()
  2311. BEGIN
  2312. DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
  2313. SELECT 'H1' AS HandlerId;
  2314. DECLARE CONTINUE HANDLER FOR SQLWARNING
  2315. SELECT 'H2' AS HandlerId;
  2316. BEGIN
  2317. DECLARE CONTINUE HANDLER FOR SQLSTATE '01000', 1249
  2318. BEGIN
  2319. DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
  2320. SELECT 'H3' AS HandlerId;
  2321. DECLARE CONTINUE HANDLER FOR SQLWARNING
  2322. SELECT 'H4' AS HandlerId;
  2323. BEGIN
  2324. SELECT 'H5' AS HandlerId;
  2325. SELECT 'S3' AS SignalId;
  2326. SIGNAL SQLSTATE 'HY000'; # H3
  2327. SELECT 'S4' AS SignalId;
  2328. SIGNAL SQLSTATE '22003'; # H3
  2329. SELECT 'S5' AS SignalId;
  2330. SIGNAL SQLSTATE '01000' SET MYSQL_ERRNO = 1249; # H4
  2331. END;
  2332. END;
  2333. SELECT 'S6' AS SignalId;
  2334. SIGNAL SQLSTATE 'HY000'; # H1
  2335. SELECT 'S7' AS SignalId;
  2336. SIGNAL SQLSTATE '22003'; # H1
  2337. SELECT 'S8' AS SignalId;
  2338. SIGNAL SQLSTATE '01000' SET MYSQL_ERRNO = 1249; # H5
  2339. END;
  2340. SELECT 'S1' AS SignalId;
  2341. SIGNAL SQLSTATE 'HY000'; # H1
  2342. SELECT 'S2' AS SignalId;
  2343. SIGNAL SQLSTATE '01000' SET MYSQL_ERRNO = 1249; # H2
  2344. END|
  2345. CALL p11()|
  2346. SignalId
  2347. S6
  2348. HandlerId
  2349. H1
  2350. SignalId
  2351. S7
  2352. HandlerId
  2353. H1
  2354. SignalId
  2355. S8
  2356. HandlerId
  2357. H5
  2358. SignalId
  2359. S3
  2360. HandlerId
  2361. H3
  2362. SignalId
  2363. S4
  2364. HandlerId
  2365. H3
  2366. SignalId
  2367. S5
  2368. HandlerId
  2369. H4
  2370. SignalId
  2371. S1
  2372. HandlerId
  2373. H1
  2374. SignalId
  2375. S2
  2376. HandlerId
  2377. H2
  2378. # -- Check that runtime stack-trace can be deeper than parsing-time one.
  2379. CREATE PROCEDURE p12()
  2380. BEGIN
  2381. DECLARE CONTINUE HANDLER FOR SQLSTATE '01001'
  2382. BEGIN
  2383. DECLARE CONTINUE HANDLER FOR SQLSTATE '01001'
  2384. BEGIN
  2385. DECLARE CONTINUE HANDLER FOR SQLSTATE '01001'
  2386. BEGIN
  2387. DECLARE CONTINUE HANDLER FOR SQLSTATE '01001'
  2388. BEGIN
  2389. DECLARE CONTINUE HANDLER FOR SQLSTATE '01001'
  2390. BEGIN
  2391. SELECT 'H1:5' AS HandlerId;
  2392. SIGNAL SQLSTATE '01002';
  2393. END;
  2394. SELECT 'H1:4' AS HandlerId;
  2395. SIGNAL SQLSTATE '01001';
  2396. END;
  2397. SELECT 'H1:3' AS HandlerId;
  2398. SIGNAL SQLSTATE '01001';
  2399. END;
  2400. SELECT 'H1:2' AS HandlerId;
  2401. SIGNAL SQLSTATE '01001';
  2402. END;
  2403. SELECT 'H1:1' AS HandlerId;
  2404. SIGNAL SQLSTATE '01001';
  2405. END;
  2406. #########################################################
  2407. DECLARE CONTINUE HANDLER FOR SQLSTATE '01002'
  2408. SELECT 'OK' AS Msg;
  2409. #########################################################
  2410. BEGIN
  2411. DECLARE CONTINUE HANDLER FOR SQLWARNING
  2412. BEGIN
  2413. DECLARE CONTINUE HANDLER FOR SQLWARNING
  2414. BEGIN
  2415. DECLARE CONTINUE HANDLER FOR SQLWARNING
  2416. BEGIN
  2417. DECLARE CONTINUE HANDLER FOR SQLWARNING
  2418. BEGIN
  2419. DECLARE CONTINUE HANDLER FOR SQLWARNING
  2420. BEGIN
  2421. SELECT 'H2:5' AS HandlerId;
  2422. SIGNAL SQLSTATE '01001';
  2423. END;
  2424. SELECT 'H2:4' AS HandlerId;
  2425. SIGNAL SQLSTATE '01000';
  2426. END;
  2427. SELECT 'H2:3' AS HandlerId;
  2428. SIGNAL SQLSTATE '01000';
  2429. END;
  2430. SELECT 'H2:2' AS HandlerId;
  2431. SIGNAL SQLSTATE '01000';
  2432. END;
  2433. SELECT 'H2:1' AS HandlerId;
  2434. SIGNAL SQLSTATE '01000';
  2435. END;
  2436. #######################################################
  2437. SELECT 'Throw 01000' AS Msg;
  2438. SIGNAL SQLSTATE '01000';
  2439. END;
  2440. END|
  2441. CALL p12()|
  2442. Msg
  2443. Throw 01000
  2444. HandlerId
  2445. H2:1
  2446. HandlerId
  2447. H2:2
  2448. HandlerId
  2449. H2:3
  2450. HandlerId
  2451. H2:4
  2452. HandlerId
  2453. H2:5
  2454. HandlerId
  2455. H1:1
  2456. HandlerId
  2457. H1:2
  2458. HandlerId
  2459. H1:3
  2460. HandlerId
  2461. H1:4
  2462. HandlerId
  2463. H1:5
  2464. Warnings:
  2465. Warning 1642 Unhandled user-defined warning condition
  2466. # -- Check that handler-call-frames are removed properly for EXIT
  2467. # -- handlers.
  2468. CREATE PROCEDURE p13()
  2469. BEGIN
  2470. DECLARE CONTINUE HANDLER FOR SQLWARNING
  2471. BEGIN
  2472. DECLARE CONTINUE HANDLER FOR SQLWARNING
  2473. BEGIN
  2474. DECLARE EXIT HANDLER FOR SQLWARNING
  2475. BEGIN
  2476. SELECT 'EXIT handler 3' AS Msg;
  2477. END;
  2478. SELECT 'CONTINUE handler 2: 1' AS Msg;
  2479. SIGNAL SQLSTATE '01000';
  2480. SELECT 'CONTINUE handler 2: 2' AS Msg;
  2481. END;
  2482. SELECT 'CONTINUE handler 1: 1' AS Msg;
  2483. SIGNAL SQLSTATE '01000';
  2484. SELECT 'CONTINUE handler 1: 2' AS Msg;
  2485. END;
  2486. SELECT 'Throw 01000' AS Msg;
  2487. SIGNAL SQLSTATE '01000';
  2488. END|
  2489. CALL p13()|
  2490. Msg
  2491. Throw 01000
  2492. Msg
  2493. CONTINUE handler 1: 1
  2494. Msg
  2495. CONTINUE handler 2: 1
  2496. Msg
  2497. EXIT handler 3
  2498. Msg
  2499. CONTINUE handler 1: 2
  2500. # That's it. Cleanup.
  2501. DROP PROCEDURE p1;
  2502. DROP PROCEDURE p2;
  2503. DROP PROCEDURE p3;
  2504. DROP PROCEDURE p4;
  2505. DROP PROCEDURE p5;
  2506. DROP PROCEDURE p6;
  2507. DROP PROCEDURE p7;
  2508. DROP PROCEDURE p8;
  2509. DROP PROCEDURE p9;
  2510. DROP PROCEDURE p10;
  2511. DROP PROCEDURE p11;
  2512. DROP PROCEDURE p12;
  2513. DROP PROCEDURE p13;
  2514. # Bug#12731619: NESTED SP HANDLERS CAN TRIGGER ASSERTION
  2515. DROP FUNCTION IF EXISTS f1;
  2516. DROP TABLE IF EXISTS t1;
  2517. CREATE TABLE t1(msg VARCHAR(255));
  2518. CREATE FUNCTION f1() RETURNS INT
  2519. BEGIN
  2520. DECLARE CONTINUE HANDLER FOR SQLEXCEPTION # handler 1
  2521. BEGIN
  2522. DECLARE CONTINUE HANDLER FOR SQLEXCEPTION # handler 2
  2523. BEGIN
  2524. INSERT INTO t1 VALUE('WRONG: Inside H2');
  2525. RETURN 2;
  2526. END;
  2527. INSERT INTO t1 VALUE('CORRECT: Inside H1');
  2528. RETURN 1;
  2529. END;
  2530. BEGIN
  2531. DECLARE CONTINUE HANDLER FOR SQLWARNING # handler 3
  2532. BEGIN
  2533. INSERT INTO t1 VALUE('WRONG: Inside H3');
  2534. RETURN 3;
  2535. END;
  2536. INSERT INTO t1 VALUE('CORRECT: Calling f1()');
  2537. RETURN f1(); # -- exception here
  2538. END;
  2539. INSERT INTO t1 VALUE('WRONG: Returning 10');
  2540. RETURN 10;
  2541. END|
  2542. SELECT f1();
  2543. f1()
  2544. 1
  2545. SELECT * FROM t1;
  2546. msg
  2547. CORRECT: Calling f1()
  2548. CORRECT: Inside H1
  2549. DROP FUNCTION f1;
  2550. DROP TABLE t1;
  2551. # Check that handled SQL-conditions are properly cleared from DA.
  2552. DROP TABLE IF EXISTS t1;
  2553. DROP TABLE IF EXISTS t2;
  2554. DROP PROCEDURE IF EXISTS p1;
  2555. DROP PROCEDURE IF EXISTS p2;
  2556. DROP PROCEDURE IF EXISTS p3;
  2557. DROP PROCEDURE IF EXISTS p4;
  2558. DROP PROCEDURE IF EXISTS p5;
  2559. CREATE TABLE t1(a CHAR, b CHAR, c CHAR);
  2560. CREATE TABLE t2(a SMALLINT, b SMALLINT, c SMALLINT);
  2561. # Check that SQL-conditions for which SQL-handler has been invoked,
  2562. # are cleared from the Diagnostics Area. Note, there might be several
  2563. # SQL-conditions, but SQL-handler must be invoked only once.
  2564. CREATE PROCEDURE p1()
  2565. BEGIN
  2566. DECLARE EXIT HANDLER FOR SQLWARNING
  2567. SELECT 'Warning caught' AS msg;
  2568. # The INSERT below raises 3 SQL-conditions (warnings). The EXIT HANDLER
  2569. # above must be invoked once (for one condition), but all three conditions
  2570. # must be cleared from the Diagnostics Area.
  2571. INSERT INTO t1 VALUES('qqqq', 'ww', 'eee');
  2572. # The following INSERT will not be executed, because of the EXIT HANDLER.
  2573. INSERT INTO t1 VALUES('zzz', 'xx', 'yyyy');
  2574. END|
  2575. CALL p1()|
  2576. msg
  2577. Warning caught
  2578. SELECT * FROM t1|
  2579. a b c
  2580. q w e
  2581. # Check that SQL-conditions for which SQL-handler has *not* been
  2582. # invoked, are *still* cleared from the Diagnostics Area.
  2583. CREATE PROCEDURE p2()
  2584. BEGIN
  2585. DECLARE CONTINUE HANDLER FOR 1292
  2586. SELECT 'Warning 1292 caught' AS msg;
  2587. # The following INSERT raises 6 SQL-warnings with code 1292,
  2588. # and 3 SQL-warnings with code 1264. The CONTINUE HANDLER above must be
  2589. # invoked once, and all nine SQL-warnings must be cleared from
  2590. # the Diagnostics Area.
  2591. INSERT INTO t2
  2592. SELECT
  2593. CAST(CONCAT(CAST('1 ' AS UNSIGNED INTEGER), '999999 ') AS SIGNED INTEGER),
  2594. CAST(CONCAT(CAST('2 ' AS UNSIGNED INTEGER), '999999 ') AS SIGNED INTEGER),
  2595. CAST(CONCAT(CAST('3 ' AS UNSIGNED INTEGER), '999999 ') AS SIGNED INTEGER);
  2596. END|
  2597. CALL p2()|
  2598. msg
  2599. Warning 1292 caught
  2600. # Check that if there are two equally ranked SQL-handlers to handle
  2601. # SQL-conditions from SQL-statement, only one of them will be invoked.
  2602. CREATE PROCEDURE p3()
  2603. BEGIN
  2604. DECLARE CONTINUE HANDLER FOR 1292
  2605. SELECT 'Warning 1292 caught' AS msg;
  2606. DECLARE CONTINUE HANDLER FOR 1264
  2607. SELECT 'Warning 1264 caught' AS msg;
  2608. # The following INSERT raises 6 SQL-warnings with code 1292,
  2609. # and 3 SQL-warnings with code 1264. Only one of the CONTINUE HANDLERs above
  2610. # must be called, and only once. The SQL Standard does not define, which one
  2611. # should be invoked.
  2612. INSERT INTO t2
  2613. SELECT
  2614. CAST(CONCAT(CAST('1 ' AS UNSIGNED INTEGER), '999999 ') AS SIGNED INTEGER),
  2615. CAST(CONCAT(CAST('2 ' AS UNSIGNED INTEGER), '999999 ') AS SIGNED INTEGER),
  2616. CAST(CONCAT(CAST('3 ' AS UNSIGNED INTEGER), '999999 ') AS SIGNED INTEGER);
  2617. END|
  2618. CALL p3()|
  2619. msg
  2620. Warning 1264 caught
  2621. # The same as p3, but 1264 comes first.
  2622. CREATE PROCEDURE p4()
  2623. BEGIN
  2624. DECLARE CONTINUE HANDLER FOR 1292
  2625. SELECT 'Warning 1292 caught' AS msg;
  2626. DECLARE CONTINUE HANDLER FOR 1264
  2627. SELECT 'Warning 1264 caught' AS msg;
  2628. # The following INSERT raises 4 SQL-warnings with code 1292,
  2629. # and 3 SQL-warnings with code 1264. Only one of the CONTINUE HANDLERs above
  2630. # must be called, and only once. The SQL Standard does not define, which one
  2631. # should be invoked.
  2632. INSERT INTO t2
  2633. SELECT
  2634. CAST(999999 AS SIGNED INTEGER),
  2635. CAST(CONCAT(CAST('2 ' AS UNSIGNED INTEGER), '999999 ') AS SIGNED INTEGER),
  2636. CAST(CONCAT(CAST('3 ' AS UNSIGNED INTEGER), '999999 ') AS SIGNED INTEGER);
  2637. END|
  2638. CALL p4()|
  2639. msg
  2640. Warning 1264 caught
  2641. # Check that if a SQL-handler raised its own SQL-conditions, there are
  2642. # preserved after handler exit.
  2643. CREATE PROCEDURE p5()
  2644. BEGIN
  2645. DECLARE EXIT HANDLER FOR 1292
  2646. BEGIN
  2647. SELECT 'Handler for 1292 (1)' AS Msg;
  2648. SIGNAL SQLSTATE '01000' SET MYSQL_ERRNO = 1234;
  2649. SHOW WARNINGS;
  2650. SELECT 'Handler for 1292 (2)' AS Msg;
  2651. END;
  2652. INSERT INTO t2
  2653. SELECT
  2654. CAST(999999 AS SIGNED INTEGER),
  2655. CAST(CONCAT(CAST('2 ' AS UNSIGNED INTEGER), '999999 ') AS SIGNED INTEGER),
  2656. CAST(CONCAT(CAST('3 ' AS UNSIGNED INTEGER), '999999 ') AS SIGNED INTEGER);
  2657. END|
  2658. CALL p5()|
  2659. Msg
  2660. Handler for 1292 (1)
  2661. Level Code Message
  2662. Warning 1234 Unhandled user-defined warning condition
  2663. Msg
  2664. Handler for 1292 (2)
  2665. Warnings:
  2666. Warning 1234 Unhandled user-defined warning condition
  2667. # Check that SQL-conditions are available inside the handler, but
  2668. # cleared after the handler exits.
  2669. CREATE PROCEDURE p6()
  2670. BEGIN
  2671. DECLARE CONTINUE HANDLER FOR 1292
  2672. BEGIN
  2673. SHOW WARNINGS;
  2674. SELECT 'Handler for 1292' Msg;
  2675. END;
  2676. INSERT INTO t2
  2677. SELECT
  2678. CAST(CONCAT(CAST('1 ' AS UNSIGNED INTEGER), '999999 ') AS SIGNED INTEGER),
  2679. CAST(CONCAT(CAST('2 ' AS UNSIGNED INTEGER), '999999 ') AS SIGNED INTEGER),
  2680. CAST(CONCAT(CAST('3 ' AS UNSIGNED INTEGER), '999999 ') AS SIGNED INTEGER);
  2681. END|
  2682. CALL p6()|
  2683. Level Code Message
  2684. Warning 1292 Truncated incorrect INTEGER value: '1 '
  2685. Warning 1292 Truncated incorrect INTEGER value: '1999999 '
  2686. Warning 1264 Out of range value for column 'a' at row 1
  2687. Warning 1292 Truncated incorrect INTEGER value: '2 '
  2688. Warning 1292 Truncated incorrect INTEGER value: '2999999 '
  2689. Warning 1264 Out of range value for column 'b' at row 1
  2690. Warning 1292 Truncated incorrect INTEGER value: '3 '
  2691. Warning 1292 Truncated incorrect INTEGER value: '3999999 '
  2692. Warning 1264 Out of range value for column 'c' at row 1
  2693. Msg
  2694. Handler for 1292
  2695. DROP PROCEDURE p1;
  2696. DROP PROCEDURE p2;
  2697. DROP PROCEDURE p3;
  2698. DROP PROCEDURE p4;
  2699. DROP PROCEDURE p5;
  2700. DROP PROCEDURE p6;
  2701. DROP TABLE t1;
  2702. DROP TABLE t2;
  2703. # Bug#13059316: ASSERTION FAILURE IN SP_RCONTEXT.CC
  2704. # Check DECLARE statements that raise conditions before handlers
  2705. # are declared.
  2706. DROP PROCEDURE IF EXISTS p1;
  2707. DROP PROCEDURE IF EXISTS p2;
  2708. CREATE PROCEDURE p1()
  2709. BEGIN
  2710. DECLARE var1 INTEGER DEFAULT 'string';
  2711. DECLARE EXIT HANDLER FOR SQLWARNING SELECT 'H1';
  2712. END|
  2713. CALL p1()|
  2714. Warnings:
  2715. Warning 1366 Incorrect integer value: 'string' for column 'var1' at row 1
  2716. CREATE PROCEDURE p2()
  2717. BEGIN
  2718. DECLARE EXIT HANDLER FOR SQLWARNING SELECT 'H2';
  2719. CALL p1();
  2720. END|
  2721. CALL p2()|
  2722. H2
  2723. H2
  2724. DROP PROCEDURE p1;
  2725. DROP PROCEDURE p2;
  2726. #
  2727. # Bug#13113222 RQG_SIGNAL_RESIGNAL FAILED WITH ASSERTION.
  2728. #
  2729. DROP PROCEDURE IF EXISTS p1;
  2730. DROP PROCEDURE IF EXISTS p2;
  2731. CREATE PROCEDURE p1()
  2732. BEGIN
  2733. DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SELECT 'triggered p1';
  2734. # This will trigger an error.
  2735. SIGNAL SQLSTATE 'HY000';
  2736. END|
  2737. CREATE PROCEDURE p2()
  2738. BEGIN
  2739. DECLARE CONTINUE HANDLER FOR SQLWARNING SELECT 'triggered p2';
  2740. # This will trigger a warning.
  2741. SIGNAL SQLSTATE '01000';
  2742. END|
  2743. SET @old_max_error_count= @@session.max_error_count;
  2744. SET SESSION max_error_count= 0;
  2745. CALL p1();
  2746. triggered p1
  2747. triggered p1
  2748. CALL p2();
  2749. SET SESSION max_error_count= @old_max_error_count;
  2750. DROP PROCEDURE p1;
  2751. DROP PROCEDURE p2;
  2752. # Bug#12652873: 61392: Continue handler for NOT FOUND being triggered
  2753. # from internal stored function.
  2754. DROP FUNCTION IF EXISTS f1;
  2755. DROP FUNCTION IF EXISTS f2;
  2756. DROP TABLE IF EXISTS t1;
  2757. CREATE TABLE t1 (a INT, b INT);
  2758. INSERT INTO t1 VALUES (1, 2);
  2759. # f1() raises NOT_FOUND condition.
  2760. # Raising NOT_FOUND can not be simulated by SIGNAL,
  2761. # because SIGNAL would raise SQL-error in that case.
  2762. CREATE FUNCTION f1() RETURNS INTEGER
  2763. BEGIN
  2764. DECLARE v VARCHAR(5) DEFAULT -1;
  2765. SELECT b FROM t1 WHERE a = 2 INTO v;
  2766. RETURN v;
  2767. END|
  2768. # Here we check that the NOT_FOUND condition raised in f1()
  2769. # is not visible in the outer function (f2), i.e. the continue
  2770. # handler in f2() will not be called.
  2771. CREATE FUNCTION f2() RETURNS INTEGER
  2772. BEGIN
  2773. DECLARE v INTEGER;
  2774. DECLARE CONTINUE HANDLER FOR NOT FOUND
  2775. SET @msg = 'Handler activated.';
  2776. SELECT f1() INTO v;
  2777. RETURN v;
  2778. END|
  2779. SET @msg = '';
  2780. SELECT f2();
  2781. f2()
  2782. -1
  2783. SELECT @msg;
  2784. @msg
  2785. DROP FUNCTION f1;
  2786. DROP FUNCTION f2;
  2787. DROP TABLE t1;