PageRenderTime 54ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/mysql-server/mysql/mysql-test/t/sp-error.test

http://isiworld.googlecode.com/
Unknown | 2839 lines | 2379 code | 460 blank | 0 comment | 0 complexity | b1026a79251386140169cf5ecd9e1e4d MD5 | raw file
Possible License(s): GPL-2.0
  1. #
  2. # Stored PROCEDURE error tests
  3. #
  4. --disable_warnings
  5. drop table if exists t1, t2;
  6. --enable_warnings
  7. # Backup the mysql.proc table
  8. --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
  9. eval SELECT * FROM mysql.proc INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/proc.txt';
  10. # Make sure we don't have any procedures left.
  11. delete from mysql.proc;
  12. delimiter |;
  13. # This should give three syntax errors (sometimes crashed; bug #643)
  14. # (Unfortunately, this is not a 100% test, on some platforms this
  15. # passed despite the bug.)
  16. --error 1064
  17. create procedure syntaxerror(t int)|
  18. --error 1064
  19. create procedure syntaxerror(t int)|
  20. --error 1064
  21. create procedure syntaxerror(t int)|
  22. # Check that we get the right error, i.e. UDF declaration parses correctly,
  23. # but foo.so doesn't exist.
  24. # This generates an error message containing a misleading errno which
  25. # might vary between systems (it usually doesn't have anything to do with
  26. # the actual failing dlopen()).
  27. #--error 1126
  28. #create function foo returns real soname "foo.so"|
  29. --disable_warnings
  30. drop table if exists t3|
  31. --enable_warnings
  32. create table t3 ( x int )|
  33. insert into t3 values (2), (3)|
  34. create procedure bad_into(out param int)
  35. select x from t3 into param|
  36. --error 1172
  37. call bad_into(@x)|
  38. drop procedure bad_into|
  39. drop table t3|
  40. create procedure proc1()
  41. set @x = 42|
  42. create function func1() returns int
  43. return 42|
  44. # Can't create recursively
  45. --error 1303
  46. create procedure foo()
  47. create procedure bar() set @x=3|
  48. --error 1303
  49. create procedure foo()
  50. create function bar() returns double return 2.3|
  51. # Already exists
  52. --error 1304
  53. create procedure proc1()
  54. set @x = 42|
  55. --error 1304
  56. create function func1() returns int
  57. return 42|
  58. drop procedure proc1|
  59. drop function func1|
  60. # Does not exist
  61. --error 1305
  62. alter procedure foo|
  63. --error 1305
  64. alter function foo|
  65. --error 1305
  66. drop procedure foo|
  67. --error 1305
  68. drop function foo|
  69. --error 1305
  70. call foo()|
  71. drop procedure if exists foo|
  72. --error 1305
  73. show create procedure foo|
  74. --error 1305
  75. show create function foo|
  76. # LEAVE/ITERATE with no match
  77. --error 1308
  78. create procedure foo()
  79. foo: loop
  80. leave bar;
  81. end loop|
  82. --error 1308
  83. create procedure foo()
  84. foo: loop
  85. iterate bar;
  86. end loop|
  87. --error 1308
  88. create procedure foo()
  89. foo: begin
  90. iterate foo;
  91. end|
  92. # Redefining label
  93. --error 1309
  94. create procedure foo()
  95. foo: loop
  96. foo: loop
  97. set @x=2;
  98. end loop foo;
  99. end loop foo|
  100. # End label mismatch
  101. --error 1310
  102. create procedure foo()
  103. foo: loop
  104. set @x=2;
  105. end loop bar|
  106. # RETURN in FUNCTION only
  107. --error 1313
  108. create procedure foo()
  109. return 42|
  110. # Wrong number of arguments
  111. create procedure p(x int)
  112. set @x = x|
  113. create function f(x int) returns int
  114. return x+42|
  115. --error 1318
  116. call p()|
  117. --error 1318
  118. call p(1, 2)|
  119. --error 1318
  120. select f()|
  121. --error 1318
  122. select f(1, 2)|
  123. drop procedure p|
  124. drop function f|
  125. --error 1319
  126. create procedure p(val int, out res int)
  127. begin
  128. declare x int default 0;
  129. declare continue handler for foo set x = 1;
  130. insert into test.t1 values (val);
  131. if (x) then
  132. set res = 0;
  133. else
  134. set res = 1;
  135. end if;
  136. end|
  137. --error 1319
  138. create procedure p(val int, out res int)
  139. begin
  140. declare x int default 0;
  141. declare foo condition for 1146;
  142. declare continue handler for bar set x = 1;
  143. insert into test.t1 values (val);
  144. if (x) then
  145. set res = 0;
  146. else
  147. set res = 1;
  148. end if;
  149. end|
  150. --error 1320
  151. create function f(val int) returns int
  152. begin
  153. declare x int;
  154. set x = val+3;
  155. end|
  156. create function f(val int) returns int
  157. begin
  158. declare x int;
  159. set x = val+3;
  160. if x < 4 then
  161. return x;
  162. end if;
  163. end|
  164. --error 1321
  165. select f(10)|
  166. drop function f|
  167. --error ER_PARSE_ERROR
  168. create procedure p()
  169. begin
  170. declare c cursor for insert into test.t1 values ("foo", 42);
  171. open c;
  172. close c;
  173. end|
  174. --error 1323
  175. create procedure p()
  176. begin
  177. declare x int;
  178. declare c cursor for select * into x from test.t limit 1;
  179. open c;
  180. close c;
  181. end|
  182. --error 1324
  183. create procedure p()
  184. begin
  185. declare c cursor for select * from test.t;
  186. open cc;
  187. close c;
  188. end|
  189. --disable_warnings
  190. drop table if exists t1|
  191. --enable_warnings
  192. create table t1 (val int)|
  193. create procedure p()
  194. begin
  195. declare c cursor for select * from test.t1;
  196. open c;
  197. open c;
  198. close c;
  199. end|
  200. --error 1325
  201. call p()|
  202. drop procedure p|
  203. create procedure p()
  204. begin
  205. declare c cursor for select * from test.t1;
  206. open c;
  207. close c;
  208. close c;
  209. end|
  210. --error 1326
  211. call p()|
  212. drop procedure p|
  213. --error 1305
  214. alter procedure bar3 sql security invoker|
  215. drop table t1|
  216. --disable_warnings
  217. drop table if exists t1|
  218. --enable_warnings
  219. create table t1 (val int, x float)|
  220. insert into t1 values (42, 3.1), (19, 1.2)|
  221. --error 1327
  222. create procedure p()
  223. begin
  224. declare x int;
  225. declare c cursor for select * from t1;
  226. open c;
  227. fetch c into x, y;
  228. close c;
  229. end|
  230. create procedure p()
  231. begin
  232. declare x int;
  233. declare c cursor for select * from t1;
  234. open c;
  235. fetch c into x;
  236. close c;
  237. end|
  238. --error 1328
  239. call p()|
  240. drop procedure p|
  241. create procedure p()
  242. begin
  243. declare x int;
  244. declare y float;
  245. declare z int;
  246. declare c cursor for select * from t1;
  247. open c;
  248. fetch c into x, y, z;
  249. close c;
  250. end|
  251. --error 1328
  252. call p()|
  253. drop procedure p|
  254. --error 1330
  255. create procedure p(in x int, x char(10))
  256. begin
  257. end|
  258. --error 1330
  259. create function p(x int, x char(10))
  260. begin
  261. end|
  262. --error 1331
  263. create procedure p()
  264. begin
  265. declare x float;
  266. declare x int;
  267. end|
  268. --error 1332
  269. create procedure p()
  270. begin
  271. declare c condition for 1064;
  272. declare c condition for 1065;
  273. end|
  274. --error 1333
  275. create procedure p()
  276. begin
  277. declare c cursor for select * from t1;
  278. declare c cursor for select field from t1;
  279. end|
  280. # USE is not allowed
  281. --error ER_SP_BADSTATEMENT
  282. create procedure u()
  283. use sptmp|
  284. # Enforced standard order of declarations
  285. --error 1337
  286. create procedure p()
  287. begin
  288. declare c cursor for select * from t1;
  289. declare x int;
  290. end|
  291. --error 1337
  292. create procedure p()
  293. begin
  294. declare x int;
  295. declare continue handler for sqlstate '42S99' set x = 1;
  296. declare foo condition for sqlstate '42S99';
  297. end|
  298. --error 1338
  299. create procedure p()
  300. begin
  301. declare x int;
  302. declare continue handler for sqlstate '42S99' set x = 1;
  303. declare c cursor for select * from t1;
  304. end|
  305. # Check in and inout arguments.
  306. --disable_warnings
  307. drop procedure if exists p|
  308. --enable_warnings
  309. create procedure p(in x int, inout y int, out z int)
  310. begin
  311. set y = x+y;
  312. set z = x+y;
  313. end|
  314. set @tmp_x = 42|
  315. set @tmp_y = 3|
  316. set @tmp_z = 0|
  317. # For reference: this is ok
  318. call p(@tmp_x, @tmp_y, @tmp_z)|
  319. select @tmp_x, @tmp_y, @tmp_z|
  320. --error ER_SP_NOT_VAR_ARG
  321. call p(42, 43, @tmp_z)|
  322. --error ER_SP_NOT_VAR_ARG
  323. call p(42, @tmp_y, 43)|
  324. drop procedure p|
  325. #
  326. # Let us test that we can access mysql.proc table for routines
  327. # definitions lookup without locking it explicitly.
  328. #
  329. create procedure p() begin end|
  330. lock table t1 read|
  331. # This should succeed
  332. call p()|
  333. unlock tables|
  334. drop procedure p|
  335. # Let us check restrictions which this ability puts on mysql.proc locking.
  336. --error ER_WRONG_LOCK_OF_SYSTEM_TABLE
  337. lock tables t1 read, mysql.proc write|
  338. --error ER_WRONG_LOCK_OF_SYSTEM_TABLE
  339. lock tables mysql.proc write, mysql.user write|
  340. # Locking for read should be OK
  341. lock tables t1 read, mysql.proc read|
  342. unlock tables|
  343. # You also should be able lock only mysql.proc for write
  344. lock tables mysql.proc write|
  345. unlock tables|
  346. #
  347. # Check that in functions we don't allow to update tables which
  348. # are used by statements which invoke these functions.
  349. #
  350. --disable_warnings
  351. drop function if exists f1|
  352. --enable_warnings
  353. create function f1(i int) returns int
  354. begin
  355. insert into t1 (val) values (i);
  356. return 0;
  357. end|
  358. --error ER_CANT_UPDATE_USED_TABLE_IN_SF_OR_TRG
  359. select val, f1(val) from t1|
  360. # Table alias should not matter
  361. --error ER_CANT_UPDATE_USED_TABLE_IN_SF_OR_TRG
  362. select val, f1(val) from t1 as tab|
  363. select * from t1|
  364. --error ER_CANT_UPDATE_USED_TABLE_IN_SF_OR_TRG
  365. update t1 set val= f1(val)|
  366. select * from t1|
  367. # But this should be OK
  368. select f1(17)|
  369. select * from t1|
  370. # Cleanup
  371. delete from t1 where val= 17|
  372. drop function f1|
  373. #
  374. # BUG#1965
  375. #
  376. create procedure bug1965()
  377. begin
  378. declare c cursor for select val from t1 order by valname;
  379. open c;
  380. close c;
  381. end|
  382. --error 1054
  383. call bug1965()|
  384. drop procedure bug1965|
  385. #
  386. # BUG#1966
  387. #
  388. --error 1327
  389. select 1 into a|
  390. #
  391. # BUG#1653
  392. #
  393. --disable_warnings
  394. drop table if exists t3|
  395. --enable_warnings
  396. create table t3 (column_1_0 int)|
  397. create procedure bug1653()
  398. update t3 set column_1 = 0|
  399. --error 1054
  400. call bug1653()|
  401. drop table t3|
  402. create table t3 (column_1 int)|
  403. call bug1653()|
  404. drop procedure bug1653|
  405. drop table t3|
  406. #
  407. # BUG#2259
  408. #
  409. # Note: When this bug existed, it did not necessarily cause a crash
  410. # in all builds, but valgrind did give warnings.
  411. create procedure bug2259()
  412. begin
  413. declare v1 int;
  414. declare c1 cursor for select s1 from t1;
  415. fetch c1 into v1;
  416. end|
  417. --error 1326
  418. call bug2259()|
  419. drop procedure bug2259|
  420. #
  421. # BUG#2272
  422. #
  423. create procedure bug2272()
  424. begin
  425. declare v int;
  426. update t1 set v = 42;
  427. end|
  428. insert into t1 values (666, 51.3)|
  429. --error 1054
  430. call bug2272()|
  431. truncate table t1|
  432. drop procedure bug2272|
  433. #
  434. # BUG#2329
  435. #
  436. create procedure bug2329_1()
  437. begin
  438. declare v int;
  439. insert into t1 (v) values (5);
  440. end|
  441. create procedure bug2329_2()
  442. begin
  443. declare v int;
  444. replace t1 set v = 5;
  445. end|
  446. --error 1054
  447. call bug2329_1()|
  448. --error 1054
  449. call bug2329_2()|
  450. drop procedure bug2329_1|
  451. drop procedure bug2329_2|
  452. #
  453. # BUG#3287
  454. #
  455. create function bug3287() returns int
  456. begin
  457. declare v int default null;
  458. case
  459. when v is not null then return 1;
  460. end case;
  461. return 2;
  462. end|
  463. --error 1339
  464. select bug3287()|
  465. drop function bug3287|
  466. create procedure bug3287(x int)
  467. case x
  468. when 0 then
  469. insert into test.t1 values (x, 0.1);
  470. when 1 then
  471. insert into test.t1 values (x, 1.1);
  472. end case|
  473. --error 1339
  474. call bug3287(2)|
  475. drop procedure bug3287|
  476. #
  477. # BUG#3297
  478. #
  479. --disable_warnings
  480. drop table if exists t3|
  481. --enable_warnings
  482. create table t3 (s1 int, primary key (s1))|
  483. insert into t3 values (5),(6)|
  484. create procedure bug3279(out y int)
  485. begin
  486. declare x int default 0;
  487. begin
  488. declare exit handler for sqlexception set x = x+1;
  489. insert into t3 values (5);
  490. end;
  491. if x < 2 then
  492. set x = x+1;
  493. insert into t3 values (6);
  494. end if;
  495. set y = x;
  496. end|
  497. set @x = 0|
  498. --error ER_DUP_ENTRY
  499. call bug3279(@x)|
  500. select @x|
  501. drop procedure bug3279|
  502. drop table t3|
  503. #
  504. # BUG#3339
  505. #
  506. --error 1049
  507. create procedure nodb.bug3339() begin end|
  508. #
  509. # BUG#2653
  510. #
  511. create procedure bug2653_1(a int, out b int)
  512. set b = aa|
  513. create procedure bug2653_2(a int, out b int)
  514. begin
  515. if aa < 0 then
  516. set b = - a;
  517. else
  518. set b = a;
  519. end if;
  520. end|
  521. --error 1054
  522. call bug2653_1(1, @b)|
  523. --error 1054
  524. call bug2653_2(2, @b)|
  525. drop procedure bug2653_1|
  526. drop procedure bug2653_2|
  527. #
  528. # BUG#4344
  529. #
  530. --error 1357
  531. create procedure bug4344() drop procedure bug4344|
  532. --error 1357
  533. create procedure bug4344() drop function bug4344|
  534. #
  535. # BUG#3294: Stored procedure crash if table dropped before use
  536. # (Actually, when an error occurs within an error handler.)
  537. --disable_warnings
  538. drop procedure if exists bug3294|
  539. --enable_warnings
  540. create procedure bug3294()
  541. begin
  542. declare continue handler for sqlexception drop table t5;
  543. drop table t5;
  544. drop table t5;
  545. end|
  546. create table t5 (x int)|
  547. --error 1051
  548. call bug3294()|
  549. drop procedure bug3294|
  550. #
  551. # BUG#876: Stored Procedures: Invalid SQLSTATE is allowed in
  552. # a DECLARE ? HANDLER FOR stmt.
  553. #
  554. --disable_warnings
  555. drop procedure if exists bug8776_1|
  556. drop procedure if exists bug8776_2|
  557. drop procedure if exists bug8776_3|
  558. drop procedure if exists bug8776_4|
  559. --enable_warnings
  560. --error ER_SP_BAD_SQLSTATE
  561. create procedure bug8776_1()
  562. begin
  563. declare continue handler for sqlstate '42S0200test' begin end;
  564. begin end;
  565. end|
  566. --error ER_SP_BAD_SQLSTATE
  567. create procedure bug8776_2()
  568. begin
  569. declare continue handler for sqlstate '4200' begin end;
  570. begin end;
  571. end|
  572. --error ER_SP_BAD_SQLSTATE
  573. create procedure bug8776_3()
  574. begin
  575. declare continue handler for sqlstate '420000' begin end;
  576. begin end;
  577. end|
  578. --error ER_SP_BAD_SQLSTATE
  579. create procedure bug8776_4()
  580. begin
  581. declare continue handler for sqlstate '42x00' begin end;
  582. begin end;
  583. end|
  584. #
  585. # BUG#6600: Stored procedure crash after repeated calls with check table
  586. #
  587. --error ER_SP_BADSTATEMENT
  588. create procedure bug6600()
  589. check table t1|
  590. # Check these two as well, while we're at it. (Although it isn't really
  591. # related to the bug report, but to the fix.)
  592. --error ER_SP_BADSTATEMENT
  593. create procedure bug6600()
  594. lock table t1 read|
  595. --error ER_SP_BADSTATEMENT
  596. create procedure bug6600()
  597. unlock table t1|
  598. #
  599. # BUG#9566: explicit LOCK TABLE and store procedures result in illegal state
  600. #
  601. # We should not think that mysql.proc table does not exist if we are unable
  602. # to open it under LOCK TABLE or in prelocked mode.
  603. #
  604. --disable_warnings
  605. drop procedure if exists bug9566|
  606. --enable_warnings
  607. create procedure bug9566()
  608. begin
  609. select * from t1;
  610. end|
  611. lock table t1 read|
  612. # This should fail since we forgot to lock mysql.proc for writing
  613. # explicitly, and we can't open mysql.proc for _writing_ if there
  614. # are locked tables.
  615. --error ER_LOCK_OR_ACTIVE_TRANSACTION
  616. alter procedure bug9566 comment 'Some comment'|
  617. unlock tables|
  618. # This should succeed
  619. drop procedure bug9566|
  620. #
  621. # BUG#7299: Stored procedures: exception handler catches not-found conditions
  622. #
  623. --disable_warnings
  624. drop procedure if exists bug7299|
  625. --enable_warnings
  626. create procedure bug7299()
  627. begin
  628. declare v int;
  629. declare c cursor for select val from t1;
  630. declare exit handler for sqlexception select 'Error!';
  631. open c;
  632. fetch c into v;
  633. end|
  634. truncate table t1|
  635. --error ER_SP_FETCH_NO_DATA
  636. call bug7299()|
  637. drop procedure bug7299|
  638. #
  639. # BUG#9073: Able to declare two handlers for same condition in same scope
  640. #
  641. --error ER_SP_DUP_HANDLER
  642. create procedure bug9073()
  643. begin
  644. declare continue handler for sqlexception select 1;
  645. declare continue handler for sqlexception select 2;
  646. end|
  647. --error ER_SP_DUP_HANDLER
  648. create procedure bug9073()
  649. begin
  650. declare condname1 condition for 1234;
  651. declare continue handler for condname1 select 1;
  652. declare exit handler for condname1 select 2;
  653. end|
  654. --error ER_SP_DUP_HANDLER
  655. create procedure bug9073()
  656. begin
  657. declare condname1 condition for sqlstate '42000';
  658. declare condname2 condition for sqlstate '42000';
  659. declare exit handler for condname1 select 1;
  660. declare continue handler for condname2 select 2;
  661. end|
  662. --error ER_SP_DUP_HANDLER
  663. create procedure bug9073()
  664. begin
  665. declare condname1 condition for sqlstate '42000';
  666. declare exit handler for condname1 select 1;
  667. declare exit handler for sqlstate '42000' select 2;
  668. end|
  669. # This should still work.
  670. --disable_warnings
  671. drop procedure if exists bug9073|
  672. --enable_warnings
  673. create procedure bug9073()
  674. begin
  675. declare condname1 condition for sqlstate '42000';
  676. declare continue handler for condname1 select 1;
  677. begin
  678. declare exit handler for sqlstate '42000' select 2;
  679. begin
  680. declare continue handler for sqlstate '42000' select 3;
  681. end;
  682. end;
  683. end|
  684. drop procedure bug9073|
  685. #
  686. # BUG#7047: Stored procedure crash if alter procedure
  687. #
  688. --error ER_SP_NO_DROP_SP
  689. create procedure bug7047()
  690. alter procedure bug7047|
  691. --error ER_SP_NO_DROP_SP
  692. create function bug7047() returns int
  693. begin
  694. alter function bug7047;
  695. return 0;
  696. end|
  697. #
  698. # BUG#8408: Stored procedure crash if function contains SHOW
  699. # BUG#9058: Stored Procedures: Crash if function included SELECT
  700. #
  701. # Some things are caught when parsing
  702. --error ER_SP_NO_RETSET
  703. create function bug8408() returns int
  704. begin
  705. select * from t1;
  706. return 0;
  707. end|
  708. --error ER_SP_NO_RETSET
  709. create function bug8408() returns int
  710. begin
  711. show warnings;
  712. return 0;
  713. end|
  714. --error ER_SP_NO_RETSET
  715. create function bug8408(a int) returns int
  716. begin
  717. declare b int;
  718. select b;
  719. return b;
  720. end|
  721. --disable_warnings
  722. drop function if exists bug8408_f|
  723. drop procedure if exists bug8408_p|
  724. --enable_warnings
  725. # Some things must be caught at invokation time
  726. create function bug8408_f() returns int
  727. begin
  728. call bug8408_p();
  729. return 0;
  730. end|
  731. create procedure bug8408_p()
  732. select * from t1|
  733. call bug8408_p()|
  734. --error ER_SP_NO_RETSET
  735. select bug8408_f()|
  736. drop procedure bug8408_p|
  737. drop function bug8408_f|
  738. # But this is ok
  739. create function bug8408() returns int
  740. begin
  741. declare n int default 0;
  742. select count(*) into n from t1;
  743. return n;
  744. end|
  745. insert into t1 value (2, 2.7), (3, 3.14), (7, 7.0)|
  746. select *,bug8408() from t1|
  747. drop function bug8408|
  748. truncate table t1|
  749. #
  750. # BUG#10537: Server crashes while loading data file into table through
  751. # procedure.
  752. # Disable load until it's PS and SP safe
  753. --disable_warnings
  754. drop procedure if exists bug10537|
  755. --enable_warnings
  756. --error ER_SP_BADSTATEMENT
  757. create procedure bug10537()
  758. load data local infile '/tmp/somefile' into table t1|
  759. #
  760. # BUG#8409: Stored procedure crash if function contains FLUSH
  761. #
  762. --disable_warnings
  763. drop function if exists bug8409|
  764. --enable_warnings
  765. --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
  766. create function bug8409()
  767. returns int
  768. begin
  769. flush tables;
  770. return 5;
  771. end|
  772. --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
  773. create function bug8409() returns int begin reset query cache;
  774. return 1; end|
  775. --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
  776. create function bug8409() returns int begin reset master;
  777. return 1; end|
  778. --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
  779. create function bug8409() returns int begin reset slave;
  780. return 1; end|
  781. --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
  782. create function bug8409() returns int begin flush hosts;
  783. return 1; end|
  784. --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
  785. create function bug8409() returns int begin flush privileges;
  786. return 1; end|
  787. --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
  788. create function bug8409() returns int begin flush tables with read lock;
  789. return 1; end|
  790. --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
  791. create function bug8409() returns int begin flush tables;
  792. return 1; end|
  793. --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
  794. create function bug8409() returns int begin flush logs;
  795. return 1; end|
  796. --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
  797. create function bug8409() returns int begin flush status;
  798. return 1; end|
  799. --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
  800. create function bug8409() returns int begin flush slave;
  801. return 1; end|
  802. --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
  803. create function bug8409() returns int begin flush master;
  804. return 1; end|
  805. --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
  806. create function bug8409() returns int begin flush des_key_file;
  807. return 1; end|
  808. --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
  809. create function bug8409() returns int begin flush user_resources;
  810. return 1; end|
  811. #
  812. # BUG#9529: Stored Procedures: No Warning on truncation of procedure name
  813. # during creation.
  814. # BUG#17015: Routine name truncation not an error
  815. # When we started using utf8 for mysql.proc, this limit appeared
  816. # to be higher, but in reality the names were truncated.
  817. --error ER_TOO_LONG_IDENT
  818. create procedure bug9529_901234567890123456789012345678901234567890123456789012345()
  819. begin
  820. end|
  821. --disable_warnings
  822. drop procedure if exists bug17015_0123456789012345678901234567890123456789012345678901234|
  823. --enable_warnings
  824. # Check the upper limit, just to make sure.
  825. create procedure bug17015_0123456789012345678901234567890123456789012345678901234()
  826. begin
  827. end|
  828. --replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00'
  829. show procedure status like 'bug17015%'|
  830. drop procedure bug17015_0123456789012345678901234567890123456789012345678901234|
  831. #
  832. # BUG#10969: Stored procedures: crash if default() function
  833. #
  834. --disable_warnings
  835. drop procedure if exists bug10969|
  836. --enable_warnings
  837. --error ER_WRONG_COLUMN_NAME
  838. create procedure bug10969()
  839. begin
  840. declare s1 int default 0;
  841. select default(s1) from t30;
  842. end|
  843. # This should work
  844. create procedure bug10969()
  845. begin
  846. declare s1 int default 0;
  847. select default(t30.s1) from t30;
  848. end|
  849. drop procedure bug10969|
  850. drop table t1|
  851. delimiter ;|
  852. # BUG#9814: Closing a cursor that is not open
  853. create table t1(f1 int);
  854. create table t2(f1 int);
  855. delimiter |;
  856. CREATE PROCEDURE SP001()
  857. P1: BEGIN
  858. DECLARE ENDTABLE INT DEFAULT 0;
  859. DECLARE TEMP_NUM INT;
  860. DECLARE TEMP_SUM INT;
  861. DECLARE C1 CURSOR FOR SELECT F1 FROM t1;
  862. DECLARE C2 CURSOR FOR SELECT F1 FROM t2;
  863. DECLARE CONTINUE HANDLER FOR NOT FOUND SET ENDTABLE = 1;
  864. SET ENDTABLE=0;
  865. SET TEMP_SUM=0;
  866. SET TEMP_NUM=0;
  867. OPEN C1;
  868. FETCH C1 INTO TEMP_NUM;
  869. WHILE ENDTABLE = 0 DO
  870. SET TEMP_SUM=TEMP_NUM+TEMP_SUM;
  871. FETCH C1 INTO TEMP_NUM;
  872. END WHILE;
  873. SELECT TEMP_SUM;
  874. CLOSE C1;
  875. CLOSE C1;
  876. SELECT 'end of proc';
  877. END P1|
  878. delimiter ;|
  879. --error 1326
  880. call SP001();
  881. drop procedure SP001;
  882. drop table t1, t2;
  883. # Bug #11394 "Recursion in SP crash server" and bug #11600 "Stored
  884. # procedures: crash with function calling itself".
  885. # We have to disable recursion since in many cases LEX and many
  886. # Item's can't be used in reentrant way nowdays.
  887. delimiter |;
  888. --disable_warnings
  889. drop function if exists bug11394|
  890. drop function if exists bug11394_1|
  891. drop function if exists bug11394_2|
  892. drop procedure if exists bug11394|
  893. --enable_warnings
  894. create function bug11394(i int) returns int
  895. begin
  896. if i <= 0 then
  897. return 0;
  898. else
  899. return (i in (100, 200, bug11394(i-1), 400));
  900. end if;
  901. end|
  902. # If we allow recursive functions without additional modifications
  903. # this will crash server since Item for "IN" is not reenterable.
  904. --error 1424
  905. select bug11394(2)|
  906. drop function bug11394|
  907. create function bug11394_1(i int) returns int
  908. begin
  909. if i <= 0 then
  910. return 0;
  911. else
  912. return (select bug11394_1(i-1));
  913. end if;
  914. end|
  915. # The following statement will crash because some LEX members responsible
  916. # for selects cannot be used in reentrant fashion.
  917. --error 1424
  918. select bug11394_1(2)|
  919. drop function bug11394_1|
  920. # Note that the following should be allowed since it does not contains
  921. # recursion
  922. create function bug11394_2(i int) returns int return i|
  923. select bug11394_2(bug11394_2(10))|
  924. drop function bug11394_2|
  925. create procedure bug11394(i int, j int)
  926. begin
  927. if i > 0 then
  928. call bug11394(i - 1,(select 1));
  929. end if;
  930. end|
  931. --error ER_SP_RECURSION_LIMIT
  932. call bug11394(2, 1)|
  933. set @@max_sp_recursion_depth=10|
  934. call bug11394(2, 1)|
  935. set @@max_sp_recursion_depth=default|
  936. drop procedure bug11394|
  937. delimiter ;|
  938. #
  939. # BUG 12490 (Packets out of order if calling HELP CONTENTS from Stored Procedure)
  940. #
  941. --error ER_SP_BADSTATEMENT
  942. CREATE PROCEDURE BUG_12490() HELP CONTENTS;
  943. --error ER_SP_BADSTATEMENT
  944. CREATE FUNCTION BUG_12490() RETURNS INT HELP CONTENTS;
  945. CREATE TABLE t_bug_12490(a int);
  946. --error ER_SP_BADSTATEMENT
  947. CREATE TRIGGER BUG_12490 BEFORE UPDATE ON t_bug_12490 FOR EACH ROW HELP CONTENTS;
  948. DROP TABLE t_bug_12490;
  949. #
  950. # Bug#11834 "Re-execution of prepared statement with dropped function
  951. # crashes server". Also tests handling of prepared stmts which use
  952. # stored functions but does not require prelocking.
  953. #
  954. --disable_warnings
  955. drop function if exists bug11834_1;
  956. drop function if exists bug11834_2;
  957. --enable_warnings
  958. create function bug11834_1() returns int return 10;
  959. create function bug11834_2() returns int return bug11834_1();
  960. prepare stmt from "select bug11834_2()";
  961. execute stmt;
  962. # Re-execution of statement should not crash server.
  963. execute stmt;
  964. drop function bug11834_1;
  965. # Attempt to execute statement should return proper error and
  966. # should not crash server.
  967. # NOTE! The error we get from the below query indicates that the sp bug11834_2
  968. # does not exist(this is wrong but can be accepted)
  969. # This behaviour has been reported as bug#21294
  970. --error ER_SP_DOES_NOT_EXIST
  971. execute stmt;
  972. deallocate prepare stmt;
  973. drop function bug11834_2;
  974. #
  975. # Bug#12953 "Stored procedures: crash if OPTIMIZE TABLE in function"
  976. #
  977. delimiter |;
  978. --disable_warnings
  979. DROP FUNCTION IF EXISTS bug12953|
  980. --enable_warnings
  981. --error ER_SP_NO_RETSET
  982. CREATE FUNCTION bug12953() RETURNS INT
  983. BEGIN
  984. OPTIMIZE TABLE t1;
  985. RETURN 1;
  986. END|
  987. delimiter ;|
  988. #
  989. # Bug##12995 "Inside function "Table 't4' was not locked with LOCK TABLES"
  990. #
  991. delimiter |;
  992. --disable_warnings
  993. DROP FUNCTION IF EXISTS bug12995|
  994. --enable_warnings
  995. --error ER_SP_BADSTATEMENT
  996. CREATE FUNCTION bug12995() RETURNS INT
  997. BEGIN
  998. HANDLER t1 OPEN;
  999. RETURN 1;
  1000. END|
  1001. --error ER_SP_BADSTATEMENT
  1002. CREATE FUNCTION bug12995() RETURNS INT
  1003. BEGIN
  1004. HANDLER t1 READ FIRST;
  1005. RETURN 1;
  1006. END|
  1007. --error ER_SP_BADSTATEMENT
  1008. CREATE FUNCTION bug12995() RETURNS INT
  1009. BEGIN
  1010. HANDLER t1 CLOSE;
  1011. RETURN 1;
  1012. END|
  1013. --error 1305
  1014. SELECT bug12995()|
  1015. delimiter ;|
  1016. #
  1017. # BUG#12712: SET AUTOCOMMIT should fail within SP/functions/triggers
  1018. #
  1019. --disable_warnings
  1020. drop procedure if exists bug12712;
  1021. drop function if exists bug12712;
  1022. --enable_warnings
  1023. # Can...
  1024. create procedure bug12712()
  1025. set session autocommit = 0;
  1026. select @@autocommit;
  1027. set @au = @@autocommit;
  1028. call bug12712();
  1029. select @@autocommit;
  1030. set session autocommit = @au;
  1031. delimiter |;
  1032. create function bug12712()
  1033. returns int
  1034. begin
  1035. call bug12712();
  1036. return 0;
  1037. end|
  1038. # Can't...
  1039. --error ER_SP_CANT_SET_AUTOCOMMIT
  1040. set @x = bug12712()|
  1041. drop procedure bug12712|
  1042. drop function bug12712|
  1043. --error ER_SP_CANT_SET_AUTOCOMMIT
  1044. create function bug12712()
  1045. returns int
  1046. begin
  1047. set session autocommit = 0;
  1048. return 0;
  1049. end|
  1050. --error ER_SP_CANT_SET_AUTOCOMMIT
  1051. create function bug12712()
  1052. returns int
  1053. begin
  1054. set @@autocommit = 0;
  1055. return 0;
  1056. end|
  1057. --error ER_SP_CANT_SET_AUTOCOMMIT
  1058. create function bug12712()
  1059. returns int
  1060. begin
  1061. set local autocommit = 0;
  1062. return 0;
  1063. end|
  1064. delimiter ;|
  1065. --error ER_SP_CANT_SET_AUTOCOMMIT
  1066. create trigger bug12712
  1067. before insert on t1 for each row set session autocommit = 0;
  1068. #
  1069. # BUG#9367: Stored procedures: client hang after "show warnings"
  1070. #
  1071. --disable_parsing
  1072. --disable_warnings
  1073. drop procedure if exists bug9367;
  1074. --enable_warnings
  1075. create table t1 (s1 int);
  1076. select s1 from t1;
  1077. delimiter |;
  1078. create procedure bug9367()
  1079. begin
  1080. declare v int;
  1081. declare c cursor for select s1 from t1;
  1082. open c;
  1083. show warnings;
  1084. fetch c into v;
  1085. select v;
  1086. end|
  1087. delimiter ;|
  1088. call bug9367();
  1089. drop procedure bug9367;
  1090. drop table t1;
  1091. --enable_parsing
  1092. #
  1093. # BUG#13510: Setting password local variable changes current password
  1094. #
  1095. delimiter |;
  1096. --disable_warnings
  1097. drop procedure if exists bug13510_1|
  1098. drop procedure if exists bug13510_2|
  1099. drop procedure if exists bug13510_3|
  1100. drop procedure if exists bug13510_4|
  1101. --enable_warnings
  1102. --error ER_SP_BAD_VAR_SHADOW
  1103. create procedure bug13510_1()
  1104. begin
  1105. declare password varchar(10);
  1106. set password = 'foo1';
  1107. select password;
  1108. end|
  1109. # Check that an error message is sent
  1110. --error ER_PARSE_ERROR
  1111. set names='foo2'|
  1112. --error ER_SP_BAD_VAR_SHADOW
  1113. create procedure bug13510_2()
  1114. begin
  1115. declare names varchar(10);
  1116. set names = 'foo2';
  1117. select names;
  1118. end|
  1119. create procedure bug13510_3()
  1120. begin
  1121. declare password varchar(10);
  1122. set `password` = 'foo3';
  1123. select password;
  1124. end|
  1125. create procedure bug13510_4()
  1126. begin
  1127. declare names varchar(10);
  1128. set `names` = 'foo4';
  1129. select names;
  1130. end|
  1131. call bug13510_3()|
  1132. call bug13510_4()|
  1133. drop procedure bug13510_3|
  1134. drop procedure bug13510_4|
  1135. #
  1136. # Test that statements which implicitly commit transaction are prohibited
  1137. # in stored function and triggers. Attempt to create function or trigger
  1138. # containing such statement should produce error (includes test for
  1139. # bug #13627).
  1140. #
  1141. --disable_warnings
  1142. drop function if exists bug_13627_f|
  1143. --enable_warnings
  1144. CREATE TABLE t1 (a int)|
  1145. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1146. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN DROP TRIGGER test1; END |
  1147. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1148. CREATE FUNCTION bug_13627_f() returns int BEGIN DROP TRIGGER test1; return 1; END |
  1149. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1150. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN create table t2 (a int); END |
  1151. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1152. CREATE FUNCTION bug_13627_f() returns int BEGIN create table t2 (a int); return 1; END |
  1153. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1154. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN create index t1_i on t1 (a); END |
  1155. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1156. CREATE FUNCTION bug_13627_f() returns int BEGIN create index t1_i on t1 (a); return 1; END |
  1157. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1158. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN alter table t1 add column b int; END |
  1159. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1160. CREATE FUNCTION bug_13627_f() returns int BEGIN alter table t1 add column b int; return 1; END |
  1161. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1162. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN rename table t1 to t2; END |
  1163. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1164. CREATE FUNCTION bug_13627_f() returns int BEGIN rename table t1 to t2; return 1; END |
  1165. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1166. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN truncate table t1; END |
  1167. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1168. CREATE FUNCTION bug_13627_f() returns int BEGIN truncate table t1; return 1; END |
  1169. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1170. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN drop table t1; END |
  1171. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1172. CREATE FUNCTION bug_13627_f() returns int BEGIN drop table t1; return 1; END |
  1173. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1174. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN drop index t1_i on t1; END |
  1175. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1176. CREATE FUNCTION bug_13627_f() returns int BEGIN drop index t1_i on t1; return 1; END |
  1177. -- error ER_SP_BADSTATEMENT
  1178. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN unlock tables; END |
  1179. -- error ER_SP_BADSTATEMENT
  1180. CREATE FUNCTION bug_13627_f() returns int BEGIN unlock tables; return 1; END |
  1181. -- error ER_SP_BADSTATEMENT
  1182. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN LOCK TABLE t1 READ; END |
  1183. -- error ER_SP_BADSTATEMENT
  1184. CREATE FUNCTION bug_13627_f() returns int BEGIN LOCK TABLE t1 READ; return 1; END |
  1185. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1186. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN create database mysqltest; END |
  1187. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1188. CREATE FUNCTION bug_13627_f() returns int BEGIN create database mysqltest; return 1; END |
  1189. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1190. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN drop database mysqltest; END |
  1191. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1192. CREATE FUNCTION bug_13627_f() returns int BEGIN drop database mysqltest; return 1; END |
  1193. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1194. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN create user 'mysqltest_1'; END |
  1195. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1196. CREATE FUNCTION bug_13627_f() returns int BEGIN create user 'mysqltest_1'; return 1; END |
  1197. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1198. CREATE TRIGGER bug21975 BEFORE INSERT ON t1 FOR EACH ROW BEGIN grant select on t1 to 'mysqltest_1'; END |
  1199. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1200. CREATE FUNCTION bug21975() returns int BEGIN grant select on t1 to 'mysqltest_1'; return 1; END |
  1201. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1202. CREATE TRIGGER bug21975 BEFORE INSERT ON t1 FOR EACH ROW BEGIN revoke select on t1 from 'mysqltest_1'; END |
  1203. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1204. CREATE FUNCTION bug21975() returns int BEGIN revoke select on t1 from 'mysqltest_1'; return 1; END |
  1205. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1206. CREATE TRIGGER bug21975 BEFORE INSERT ON t1 FOR EACH ROW BEGIN revoke all privileges on *.* from 'mysqltest_1'; END |
  1207. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1208. CREATE FUNCTION bug21975() returns int BEGIN revoke all privileges on *.* from 'mysqltest_1'; return 1; END |
  1209. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1210. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN drop user 'mysqltest_1'; END |
  1211. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1212. CREATE FUNCTION bug_13627_f() returns int BEGIN drop user 'mysqltest_1'; return 1; END |
  1213. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1214. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN rename user 'mysqltest_2' to 'mysqltest_1'; END |
  1215. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1216. CREATE FUNCTION bug_13627_f() returns int BEGIN rename user 'mysqltest_2' to 'mysqltest_1'; return 1; END |
  1217. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1218. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN create view v1 as select 1; END |
  1219. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1220. CREATE FUNCTION bug_13627_f() returns int BEGIN create view v1 as select 1; return 1; END |
  1221. -- error ER_SP_BADSTATEMENT
  1222. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN alter view v1 as select 1; END |
  1223. -- error ER_SP_BADSTATEMENT
  1224. CREATE FUNCTION bug_13627_f() returns int BEGIN alter view v1 as select 1; return 1; END |
  1225. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1226. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN drop view v1; END |
  1227. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1228. CREATE FUNCTION bug_13627_f() returns int BEGIN drop view v1; return 1; END |
  1229. -- error ER_SP_NO_RECURSIVE_CREATE
  1230. 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 |
  1231. -- error ER_SP_NO_RECURSIVE_CREATE
  1232. CREATE FUNCTION bug_13627_f() returns int BEGIN create trigger tr2 before insert on t1 for each row do select 1; return 1; END |
  1233. -- error ER_SP_NO_DROP_SP
  1234. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN drop function bug_13627_f; END |
  1235. -- error ER_SP_NO_DROP_SP
  1236. CREATE FUNCTION bug_13627_f() returns int BEGIN drop function bug_13627_f; return 1; END |
  1237. -- error ER_SP_NO_RECURSIVE_CREATE
  1238. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN create function f2 () returns int return 1; END |
  1239. -- error ER_SP_NO_RECURSIVE_CREATE
  1240. CREATE FUNCTION bug_13627_f() returns int BEGIN create function f2 () returns int return 1; return 1; END |
  1241. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW
  1242. BEGIN
  1243. CREATE TEMPORARY TABLE t2 (a int);
  1244. DROP TEMPORARY TABLE t2;
  1245. END |
  1246. CREATE FUNCTION bug_13627_f() returns int
  1247. BEGIN
  1248. CREATE TEMPORARY TABLE t2 (a int);
  1249. DROP TEMPORARY TABLE t2;
  1250. return 1;
  1251. END |
  1252. drop table t1|
  1253. drop function bug_13627_f|
  1254. delimiter ;|
  1255. # BUG#12329: "Bogus error msg when executing PS with stored procedure after
  1256. # SP was re-created". See also test for related bug#13399 in trigger.test
  1257. drop function if exists bug12329;
  1258. --enable_warnings
  1259. create table t1 as select 1 a;
  1260. create table t2 as select 1 a;
  1261. create function bug12329() returns int return (select a from t1);
  1262. prepare stmt1 from 'select bug12329()';
  1263. execute stmt1;
  1264. drop function bug12329;
  1265. create function bug12329() returns int return (select a+100 from t2);
  1266. select bug12329();
  1267. execute stmt1;
  1268. deallocate prepare stmt1;
  1269. drop function bug12329;
  1270. drop table t1, t2;
  1271. #
  1272. # Bug#13514 "server crash when create a stored procedure before choose a
  1273. # database" and
  1274. # Bug#13587 "Server crash when SP is created without database
  1275. # selected"
  1276. #
  1277. create database mysqltest1;
  1278. use mysqltest1;
  1279. drop database mysqltest1;
  1280. --error ER_NO_DB_ERROR
  1281. create function f1() returns int return 1;
  1282. delimiter |;
  1283. --error ER_NO_DB_ERROR
  1284. create procedure p1(out param1 int)
  1285. begin
  1286. select count(*) into param1 from t3;
  1287. end|
  1288. delimiter ;|
  1289. use test;
  1290. #
  1291. # BUG#13037: undefined variable in IF cause erroneous error-message
  1292. #
  1293. --disable_warnings
  1294. DROP PROCEDURE IF EXISTS bug13037_p1;
  1295. DROP PROCEDURE IF EXISTS bug13037_p2;
  1296. DROP PROCEDURE IF EXISTS bug13037_p3;
  1297. --enable_warnings
  1298. delimiter |;
  1299. CREATE PROCEDURE bug13037_p1()
  1300. BEGIN
  1301. IF bug13037_foo THEN
  1302. SELECT 1;
  1303. END IF;
  1304. END|
  1305. CREATE PROCEDURE bug13037_p2()
  1306. BEGIN
  1307. SET @bug13037_foo = bug13037_bar;
  1308. END|
  1309. CREATE PROCEDURE bug13037_p3()
  1310. BEGIN
  1311. SELECT bug13037_foo;
  1312. END|
  1313. delimiter ;|
  1314. --echo
  1315. --error 1054
  1316. CALL bug13037_p1();
  1317. --error 1054
  1318. CALL bug13037_p2();
  1319. --error 1054
  1320. CALL bug13037_p3();
  1321. --error 1054
  1322. CALL bug13037_p1();
  1323. --error 1054
  1324. CALL bug13037_p2();
  1325. --error 1054
  1326. CALL bug13037_p3();
  1327. DROP PROCEDURE bug13037_p1;
  1328. DROP PROCEDURE bug13037_p2;
  1329. DROP PROCEDURE bug13037_p3;
  1330. #
  1331. # Bug#14569 "editing a stored procedure kills mysqld-nt"
  1332. #
  1333. create database mysqltest1;
  1334. create database mysqltest2;
  1335. use mysqltest1;
  1336. drop database mysqltest1;
  1337. create procedure mysqltest2.p1() select version();
  1338. --error ER_NO_DB_ERROR
  1339. create procedure p2() select version();
  1340. use mysqltest2;
  1341. --replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00'
  1342. show procedure status;
  1343. drop database mysqltest2;
  1344. use test;
  1345. #
  1346. # Bug#13012 "SP: REPAIR/BACKUP/RESTORE TABLE crashes the server"
  1347. #
  1348. delimiter |;
  1349. --disable_warnings
  1350. DROP FUNCTION IF EXISTS bug13012|
  1351. --enable_warnings
  1352. --error ER_SP_NO_RETSET
  1353. CREATE FUNCTION bug13012() RETURNS INT
  1354. BEGIN
  1355. REPAIR TABLE t1;
  1356. RETURN 1;
  1357. END|
  1358. create table t1 (a int)|
  1359. CREATE PROCEDURE bug13012_1() REPAIR TABLE t1|
  1360. CREATE FUNCTION bug13012_2() RETURNS INT
  1361. BEGIN
  1362. CALL bug13012_1();
  1363. RETURN 1;
  1364. END|
  1365. --error ER_SP_NO_RETSET
  1366. SELECT bug13012_2()|
  1367. drop table t1|
  1368. drop procedure bug13012_1|
  1369. drop function bug13012_2|
  1370. delimiter ;|
  1371. #
  1372. # BUG#11555 "Stored procedures: current SP tables locking make
  1373. # impossible view security". We should not expose names of tables
  1374. # which are implicitly used by view (via stored routines/triggers).
  1375. #
  1376. # Note that SQL standard assumes that you simply won't be able drop table
  1377. # and leave some objects (routines/views/triggers) which were depending on
  1378. # it. Such objects should be dropped in advance (by default) or will be
  1379. # dropped simultaneously with table (DROP TABLE with CASCADE clause).
  1380. # So these tests probably should go away once we will implement standard
  1381. # behavior.
  1382. --disable_warnings
  1383. drop function if exists bug11555_1;
  1384. drop function if exists bug11555_2;
  1385. drop view if exists v1, v2, v3, v4;
  1386. --enable_warnings
  1387. create function bug11555_1() returns int return (select max(i) from t1);
  1388. create function bug11555_2() returns int return bug11555_1();
  1389. # It is OK to report name of implicitly used table which is missing
  1390. # when we create view.
  1391. # For stored functions however, because of exceptions handlers, there is
  1392. # no easy way to find out if a missing table makes the view invalid.
  1393. create view v1 as select bug11555_1();
  1394. drop view v1;
  1395. create view v2 as select bug11555_2();
  1396. drop view v2;
  1397. # But we should hide name of missing implicitly used table when we use view
  1398. create table t1 (i int);
  1399. create view v1 as select bug11555_1();
  1400. create view v2 as select bug11555_2();
  1401. create view v3 as select * from v1;
  1402. drop table t1;
  1403. --error ER_VIEW_INVALID
  1404. select * from v1;
  1405. --error ER_VIEW_INVALID
  1406. select * from v2;
  1407. --error ER_VIEW_INVALID
  1408. select * from v3;
  1409. # Note that creation of view which depends on broken view is yet
  1410. # another form of view usage.
  1411. create view v4 as select * from v1;
  1412. drop view v1, v2, v3, v4;
  1413. # We also should hide details about broken triggers which are
  1414. # invoked for view.
  1415. drop function bug11555_1;
  1416. drop function bug11555_2;
  1417. create table t1 (i int);
  1418. create table t2 (i int);
  1419. create trigger t1_ai after insert on t1 for each row insert into t2 values (new.i);
  1420. create view v1 as select * from t1;
  1421. drop table t2;
  1422. # Limitation, the desired error is ER_VIEW_INVALID
  1423. --error ER_NO_SUCH_TABLE
  1424. insert into v1 values (1);
  1425. drop trigger t1_ai;
  1426. create function bug11555_1() returns int return (select max(i) from t2);
  1427. create trigger t1_ai after insert on t1 for each row set @a:=bug11555_1();
  1428. # Limitation, the desired error is ER_VIEW_INVALID
  1429. --error ER_NO_SUCH_TABLE
  1430. insert into v1 values (2);
  1431. drop function bug11555_1;
  1432. drop table t1;
  1433. drop view v1;
  1434. #
  1435. # BUG#15658: Server crashes after creating function as empty string
  1436. #
  1437. --disable_warnings
  1438. drop procedure if exists ` bug15658`;
  1439. --enable_warnings
  1440. --error ER_SP_WRONG_NAME
  1441. create procedure ``() select 1;
  1442. --error ER_SP_WRONG_NAME
  1443. create procedure ` `() select 1;
  1444. --error ER_SP_WRONG_NAME
  1445. create procedure `bug15658 `() select 1;
  1446. --error ER_WRONG_DB_NAME
  1447. create procedure ``.bug15658() select 1;
  1448. --error ER_WRONG_DB_NAME
  1449. create procedure `x `.bug15658() select 1;
  1450. # This should work
  1451. create procedure ` bug15658`() select 1;
  1452. call ` bug15658`();
  1453. --replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00'
  1454. show procedure status;
  1455. drop procedure ` bug15658`;
  1456. #
  1457. # BUG#14270: Stored procedures: crash if load index
  1458. #
  1459. --disable_warnings
  1460. drop function if exists bug14270;
  1461. drop table if exists t1;
  1462. --enable_warnings
  1463. create table t1 (s1 int primary key);
  1464. delimiter |;
  1465. --error ER_SP_NO_RETSET
  1466. create function bug14270() returns int
  1467. begin
  1468. load index into cache t1;
  1469. return 1;
  1470. end|
  1471. --error ER_SP_NO_RETSET
  1472. create function bug14270() returns int
  1473. begin
  1474. cache index t1 key (`primary`) in keycache1;
  1475. return 1;
  1476. end|
  1477. delimiter ;|
  1478. drop table t1;
  1479. #
  1480. # BUG#15091: Sp Returns Unknown error in order clause....and
  1481. # there is no order by clause
  1482. #
  1483. --disable_warnings
  1484. drop procedure if exists bug15091;
  1485. --enable_warnings
  1486. delimiter |;
  1487. create procedure bug15091()
  1488. begin
  1489. declare selectstr varchar(6000) default ' ';
  1490. declare conditionstr varchar(5000) default '';
  1491. set selectstr = concat(selectstr,
  1492. ' and ',
  1493. c.operatorid,
  1494. 'in (',conditionstr, ')');
  1495. end|
  1496. delimiter ;|
  1497. # The error message used to be:
  1498. # ERROR 1109 (42S02): Unknown table 'c' in order clause
  1499. # but is now rephrased to something less misleading:
  1500. # ERROR 1109 (42S02): Unknown table 'c' in field list
  1501. --error ER_UNKNOWN_TABLE
  1502. call bug15091();
  1503. drop procedure bug15091;
  1504. #
  1505. # BUG#16896: Stored function: unused AGGREGATE-clause in CREATE FUNCTION
  1506. #
  1507. --disable_warnings
  1508. drop function if exists bug16896;
  1509. --enable_warnings
  1510. --error ER_PARSE_ERROR
  1511. create aggregate function bug16896() returns int return 1;
  1512. #
  1513. #
  1514. # BUG#14702: misleading error message when syntax error in CREATE
  1515. # PROCEDURE
  1516. #
  1517. # Misleading error message was given when IF NOT EXISTS was used in
  1518. # CREATE PROCEDURE.
  1519. #
  1520. --disable_warnings
  1521. DROP PROCEDURE IF EXISTS bug14702;
  1522. --enable_warnings
  1523. --error ER_PARSE_ERROR
  1524. CREATE IF NOT EXISTS PROCEDURE bug14702()
  1525. BEGIN
  1526. END;
  1527. --error ER_PARSE_ERROR
  1528. CREATE PROCEDURE IF NOT EXISTS bug14702()
  1529. BEGIN
  1530. END;
  1531. #
  1532. # BUG#20953: create proc with a create view that uses local
  1533. # vars/params should fail to create
  1534. #
  1535. # See test case for what syntax is forbidden in a view.
  1536. #
  1537. --disable_warnings
  1538. DROP TABLE IF EXISTS t1;
  1539. --enable_warnings
  1540. CREATE TABLE t1 (i INT);
  1541. # We do not have to drop this procedure and view because they won't be
  1542. # created.
  1543. --error ER_VIEW_SELECT_CLAUSE
  1544. CREATE PROCEDURE bug20953() CREATE VIEW v AS SELECT 1 INTO @a;
  1545. --error ER_VIEW_SELECT_CLAUSE
  1546. CREATE PROCEDURE bug20953() CREATE VIEW v AS SELECT 1 INTO DUMPFILE "file";
  1547. --error ER_VIEW_SELECT_CLAUSE
  1548. CREATE PROCEDURE bug20953() CREATE VIEW v AS SELECT 1 INTO OUTFILE "file";
  1549. --error ER_VIEW_SELECT_CLAUSE
  1550. CREATE PROCEDURE bug20953()
  1551. CREATE VIEW v AS SELECT i FROM t1 PROCEDURE ANALYSE();
  1552. --error ER_VIEW_SELECT_DERIVED
  1553. CREATE PROCEDURE bug20953() CREATE VIEW v AS SELECT 1 FROM (SELECT 1) AS d1;
  1554. --error ER_VIEW_SELECT_VARIABLE
  1555. CREATE PROCEDURE bug20953(i INT) CREATE VIEW v AS SELECT i;
  1556. delimiter |;
  1557. --error ER_VIEW_SELECT_VARIABLE
  1558. CREATE PROCEDURE bug20953()
  1559. BEGIN
  1560. DECLARE i INT;
  1561. CREATE VIEW v AS SELECT i;
  1562. END |
  1563. delimiter ;|
  1564. --error ER_VIEW_SELECT_VARIABLE
  1565. PREPARE stmt FROM "CREATE VIEW v AS SELECT ?";
  1566. DROP TABLE t1;
  1567. #
  1568. # BUG#24491 "using alias from source table in insert ... on duplicate key"
  1569. #
  1570. --disable_warnings
  1571. drop tables if exists t1;
  1572. drop procedure if exists bug24491;
  1573. --enable_warnings
  1574. create table t1 (id int primary key auto_increment, value varchar(10));
  1575. insert into t1 (id, value) values (1, 'FIRST'), (2, 'SECOND'), (3, 'THIRD');
  1576. # Let us create routine with INSERT ... SELECT ... ON DUPLICATE KEY UPDATE
  1577. # statement which in its ON DUPLICATE KEY clause erroneously tries to assign
  1578. # value to a column which is mentioned only in SELECT part.
  1579. create procedure bug24491()
  1580. insert into t1 (id, value) select * from (select 4 as i, 'FOURTH' as v) as y on duplicate key update v = 'DUP';
  1581. # Both first and second calls to it should fail
  1582. --error ER_BAD_FIELD_ERROR
  1583. call bug24491();
  1584. --error ER_BAD_FIELD_ERROR
  1585. call bug24491();
  1586. drop procedure bug24491;
  1587. # And now the same test for more complex case which is more close
  1588. # to the one that was reported originally.
  1589. create procedure bug24491()
  1590. insert into t1 (id, value) select * from (select 4 as id, 'FOURTH' as value) as y on duplicate key update y.value = 'DUP';
  1591. --error ER_BAD_FIELD_ERROR
  1592. call bug24491();
  1593. --error ER_BAD_FIELD_ERROR
  1594. call bug24491();
  1595. drop procedure bug24491;
  1596. drop tables t1;
  1597. #
  1598. # BUG#18914: Calling certain SPs from triggers fail
  1599. #
  1600. # Failing to call a procedure that does implicit commit from a trigger
  1601. # is a correct behaviour, however the error message was misleading.
  1602. #
  1603. # DROP TABLE IF EXISTS is also fixed to give correct error instead of
  1604. # "Table doesn't exist".
  1605. #
  1606. --disable_warnings
  1607. DROP FUNCTION IF EXISTS bug18914_f1;
  1608. DROP FUNCTION IF EXISTS bug18914_f2;
  1609. DROP PROCEDURE IF EXISTS bug18914_p1;
  1610. DROP PROCEDURE IF EXISTS bug18914_p2;
  1611. DROP TABLE IF EXISTS t1, t2;
  1612. --enable_warnings
  1613. CREATE TABLE t1 (i INT);
  1614. CREATE PROCEDURE bug18914_p1() CREATE TABLE t2 (i INT);
  1615. CREATE PROCEDURE bug18914_p2() DROP TABLE IF EXISTS no_such_table;
  1616. delimiter |;
  1617. CREATE FUNCTION bug18914_f1() RETURNS INT
  1618. BEGIN
  1619. CALL bug18914_p1();
  1620. RETURN 1;
  1621. END |
  1622. CREATE FUNCTION bug18914_f2() RETURNS INT
  1623. BEGIN
  1624. CALL bug18914_p2();
  1625. RETURN 1;
  1626. END |
  1627. delimiter ;|
  1628. CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW
  1629. CALL bug18914_p1();
  1630. --error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1631. INSERT INTO t1 VALUES (1);
  1632. --error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1633. SELECT bug18914_f1();
  1634. --error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1635. SELECT bug18914_f2();
  1636. --error ER_NO_SUCH_TABLE
  1637. SELECT * FROM t2;
  1638. DROP FUNCTION bug18914_f1;
  1639. DROP FUNCTION bug18914_f2;
  1640. DROP PROCEDURE bug18914_p1;
  1641. DROP PROCEDURE bug18914_p2;
  1642. DROP TABLE t1;
  1643. #
  1644. # Bug#20713 (Functions will not not continue for SQLSTATE VALUE '42S02')
  1645. #
  1646. --disable_warnings
  1647. drop table if exists bogus_table_20713;
  1648. drop function if exists func_20713_a;
  1649. drop function if exists func_20713_b;
  1650. --enable_warnings
  1651. create table bogus_table_20713( id int(10) not null primary key);
  1652. insert into bogus_table_20713 values (1), (2), (3);
  1653. delimiter //;
  1654. create function func_20713_a() returns int(11)
  1655. begin
  1656. declare id int;
  1657. declare continue handler for sqlexception set id=null;
  1658. set @in_func := 1;
  1659. set id = (select id from bogus_table_20713 where id = 3);
  1660. set @in_func := 2;
  1661. return id;
  1662. end//
  1663. create function func_20713_b() returns int(11)
  1664. begin
  1665. declare id int;
  1666. declare continue handler for sqlstate value '42S02' set id=null;
  1667. set @in_func := 1;
  1668. set id = (select id from bogus_table_20713 where id = 3);
  1669. set @in_func := 2;
  1670. return id;
  1671. end//
  1672. delimiter ;//
  1673. set @in_func := 0;
  1674. select func_20713_a();
  1675. select @in_func;
  1676. set @in_func := 0;
  1677. select func_20713_b();
  1678. select @in_func;
  1679. drop table bogus_table_20713;
  1680. set @in_func := 0;
  1681. select func_20713_a();
  1682. select @in_func;
  1683. set @in_func := 0;
  1684. select func_20713_b();
  1685. select @in_func;
  1686. drop function if exists func_20713_a;
  1687. drop function if exists func_20713_b;
  1688. #
  1689. # Bug#25345 (Cursors from Functions)
  1690. #
  1691. --disable_warnings
  1692. drop table if exists table_25345_a;
  1693. drop table if exists table_25345_b;
  1694. drop procedure if exists proc_25345;
  1695. drop function if exists func_25345;
  1696. drop function if exists func_25345_b;
  1697. --enable_warnings
  1698. create table table_25345_a (a int);
  1699. create table table_25345_b (b int);
  1700. delimiter ||;
  1701. create procedure proc_25345()
  1702. begin
  1703. declare c1 cursor for select a from table_25345_a;
  1704. declare c2 cursor for select b from table_25345_b;
  1705. select 1 as result;
  1706. end ||
  1707. create function func_25345() returns int(11)
  1708. begin
  1709. call proc_25345();
  1710. return 1;
  1711. end ||
  1712. create function func_25345_b() returns int(11)
  1713. begin
  1714. declare c1 cursor for select a from table_25345_a;
  1715. declare c2 cursor for select b from table_25345_b;
  1716. return 1;
  1717. end ||
  1718. delimiter ;||
  1719. call proc_25345();
  1720. --error ER_SP_NO_RETSET
  1721. select func_25345();
  1722. select func_25345_b();
  1723. drop table table_25345_a;
  1724. call proc_25345();
  1725. --error ER_SP_NO_RETSET
  1726. select func_25345();
  1727. select func_25345_b();
  1728. drop table table_25345_b;
  1729. drop procedure proc_25345;
  1730. drop function func_25345;
  1731. drop function func_25345_b;
  1732. #
  1733. # End of 5.0 tests
  1734. #
  1735. --echo End of 5.0 tests
  1736. #
  1737. # Bug#16164 "Easter egg": check that SHOW AUTHORS is disabled in
  1738. # stored functions/triggers
  1739. #
  1740. --disable_warnings
  1741. drop function if exists bug16164;
  1742. --enable_warnings
  1743. delimiter |;
  1744. --error ER_SP_NO_RETSET
  1745. create function bug16164() returns int
  1746. begin
  1747. show authors;
  1748. return 42;
  1749. end|
  1750. delimiter ;|
  1751. #
  1752. # BUG#20701: BINARY keyword should be forbidden in stored routines
  1753. #
  1754. --disable_warnings
  1755. drop function if exists bug20701;
  1756. --enable_warnings
  1757. #
  1758. # This was disabled in 5.1.12. See bug #20701
  1759. # When collation support in SP is implemented, then this test should
  1760. # be removed.
  1761. #
  1762. --error ER_NOT_SUPPORTED_YET
  1763. create function bug20701() returns varchar(25) binary return "test";
  1764. create function bug20701() returns varchar(25) return "test";
  1765. drop function bug20701;
  1766. #
  1767. # Bug#26503 (Illegal SQL exception handler code causes the server to crash)
  1768. #
  1769. delimiter //;
  1770. --error ER_SP_LILABEL_MISMATCH
  1771. create procedure proc_26503_error_1()
  1772. begin
  1773. retry:
  1774. repeat
  1775. begin
  1776. declare continue handler for sqlexception
  1777. begin
  1778. iterate retry;
  1779. end
  1780. select "do something";
  1781. end
  1782. until true end repeat retry;
  1783. end//
  1784. --error ER_SP_LILABEL_MISMATCH
  1785. create procedure proc_26503_error_2()
  1786. begin
  1787. retry:
  1788. repeat
  1789. begin
  1790. declare continue handler for sqlexception
  1791. iterate retry;
  1792. select "do something";
  1793. end
  1794. until true end repeat retry;
  1795. end//
  1796. --error ER_SP_LILABEL_MISMATCH
  1797. create procedure proc_26503_error_3()
  1798. begin
  1799. retry:
  1800. repeat
  1801. begin
  1802. declare continue handler for sqlexception
  1803. begin
  1804. leave retry;
  1805. end
  1806. select "do something";
  1807. end
  1808. until true end repeat retry;
  1809. end//
  1810. --error ER_SP_LILABEL_MISMATCH
  1811. create procedure proc_26503_error_4()
  1812. begin
  1813. retry:
  1814. repeat
  1815. begin
  1816. declare continue handler for sqlexception
  1817. leave retry;
  1818. select "do something";
  1819. end
  1820. until true end repeat retry;
  1821. end//
  1822. delimiter ;//
  1823. #
  1824. # Bug#28360 (RENAME DATABASE destroys routines)
  1825. #
  1826. --disable_warnings
  1827. drop procedure if exists proc_28360;
  1828. drop function if exists func_28360;
  1829. --enable_warnings
  1830. delimiter //;
  1831. --error ER_SP_NO_DROP_SP
  1832. CREATE PROCEDURE proc_28360()
  1833. BEGIN
  1834. ALTER DATABASE `#mysql50#upgrade-me` UPGRADE DATA DIRECTORY NAME;
  1835. END//
  1836. --error ER_SP_NO_DROP_SP
  1837. CREATE FUNCTION func_28360() RETURNS int
  1838. BEGIN
  1839. ALTER DATABASE `#mysql50#upgrade-me` UPGRADE DATA DIRECTORY NAME;
  1840. RETURN 0;
  1841. END//
  1842. delimiter ;//
  1843. #
  1844. # Bug#29223 declare cursor c for SHOW .....
  1845. #
  1846. --disable_warnings
  1847. DROP PROCEDURE IF EXISTS p1;
  1848. --enable_warnings
  1849. --delimiter |
  1850. --error ER_PARSE_ERROR
  1851. CREATE PROCEDURE p1()
  1852. BEGIN
  1853. DECLARE c char(100);
  1854. DECLARE cur1 CURSOR FOR SHOW TABLES;
  1855. OPEN cur1;
  1856. FETCH cur1 INTO c;
  1857. select c;
  1858. CLOSE cur1;
  1859. END|
  1860. --delimiter ;
  1861. #
  1862. # Bug#29816 Syntactically wrong query fails with misleading error message
  1863. #
  1864. --disable_warnings
  1865. DROP DATABASE IF EXISTS mysqltest;
  1866. --enable_warnings
  1867. CREATE DATABASE mysqltest;
  1868. USE mysqltest;
  1869. DROP DATABASE mysqltest;
  1870. # Both ER_SP_DOES_NOT_EXIST and ER_PARSE_ERROR are valid here,
  1871. # the result is implementation dependent:
  1872. # See Bug#29816 for details
  1873. --error ER_SP_DOES_NOT_EXIST
  1874. SELECT inexistent(), 1 + ,;
  1875. --error ER_SP_DOES_NOT_EXIST
  1876. SELECT inexistent();
  1877. --error ER_PARSE_ERROR
  1878. SELECT .inexistent();
  1879. --error ER_PARSE_ERROR
  1880. SELECT ..inexistent();
  1881. USE test;
  1882. #
  1883. # Bug#30904 SET PASSWORD statement is non-transactional
  1884. #
  1885. delimiter |;
  1886. --error ER_SP_CANT_SET_AUTOCOMMIT
  1887. create function f1() returns int
  1888. begin
  1889. set @test = 1, password = password('foo');
  1890. return 1;
  1891. end|
  1892. --error ER_SP_CANT_SET_AUTOCOMMIT
  1893. create trigger t1
  1894. before insert on t2 for each row set password = password('foo');|
  1895. delimiter ;|
  1896. #
  1897. # Bug#30882 Dropping a temporary table inside a stored function may cause a server crash
  1898. #
  1899. --disable_warnings
  1900. drop function if exists f1;
  1901. drop function if exists f2;
  1902. drop table if exists t1, t2;
  1903. --enable_warnings
  1904. delimiter |;
  1905. create function f1() returns int
  1906. begin
  1907. drop temporary table t1;
  1908. return 1;
  1909. end|
  1910. delimiter ;|
  1911. --error ER_CANT_REOPEN_TABLE
  1912. create temporary table t1 as select f1();
  1913. delimiter |;
  1914. create function f2() returns int
  1915. begin
  1916. create temporary table t2 as select f1();
  1917. return 1;
  1918. end|
  1919. delimiter ;|
  1920. --error ER_CANT_REOPEN_TABLE
  1921. create temporary table t1 as select f2();
  1922. drop function f1;
  1923. drop function f2;
  1924. delimiter |;
  1925. create function f1() returns int
  1926. begin
  1927. drop temporary table t2,t1;
  1928. return 1;
  1929. end|
  1930. create function f2() returns int
  1931. begin
  1932. create temporary table t2 as select f1();
  1933. return 1;
  1934. end|
  1935. delimiter ;|
  1936. --error ER_CANT_REOPEN_TABLE
  1937. create temporary table t1 as select f2();
  1938. drop function f1;
  1939. drop function f2;
  1940. create temporary table t2(a int);
  1941. select * from t2;
  1942. delimiter |;
  1943. create function f2() returns int
  1944. begin
  1945. drop temporary table t2;
  1946. return 1;
  1947. end|
  1948. delimiter ;|
  1949. select f2();
  1950. drop function f2;
  1951. --error ER_BAD_TABLE_ERROR
  1952. drop table t2;
  1953. --echo End of 5.1 tests
  1954. #
  1955. # Bug#33983 (Stored Procedures: wrong end <label> syntax is accepted)
  1956. #
  1957. --disable_warnings
  1958. drop procedure if exists proc_33983_a;
  1959. drop procedure if exists proc_33983_b;
  1960. drop procedure if exists proc_33983_c;
  1961. drop procedure if exists proc_33983_d;
  1962. --enable_warnings
  1963. delimiter |;
  1964. --error ER_SP_LABEL_MISMATCH
  1965. create procedure proc_33983_a()
  1966. begin
  1967. label1:
  1968. begin
  1969. label2:
  1970. begin
  1971. select 1;
  1972. end label1;
  1973. end;
  1974. end|
  1975. --error ER_SP_LABEL_MISMATCH
  1976. create procedure proc_33983_b()
  1977. begin
  1978. label1:
  1979. repeat
  1980. label2:
  1981. repeat
  1982. select 1;
  1983. until FALSE end repeat label1;
  1984. until FALSE end repeat;
  1985. end|
  1986. --error ER_SP_LABEL_MISMATCH
  1987. create procedure proc_33983_c()
  1988. begin
  1989. label1:
  1990. while TRUE do
  1991. label2:
  1992. while TRUE do
  1993. select 1;
  1994. end while label1;
  1995. end while;
  1996. end|
  1997. --error ER_SP_LABEL_MISMATCH
  1998. create procedure proc_33983_d()
  1999. begin
  2000. label1:
  2001. loop
  2002. label2:
  2003. loop
  2004. select 1;
  2005. end loop label1;
  2006. end loop;
  2007. end|
  2008. CREATE TABLE t1 (a INT)|
  2009. INSERT INTO t1 VALUES (1),(2)|
  2010. CREATE PROCEDURE p1(a INT) BEGIN END|
  2011. --error ER_SUBQUERY_NO_1_ROW
  2012. CALL p1((SELECT * FROM t1))|
  2013. DROP PROCEDURE IF EXISTS p1|
  2014. DROP TABLE t1|
  2015. delimiter ;|
  2016. #
  2017. # Bug#21801: SQL exception handlers and warnings
  2018. #
  2019. --disable_warnings
  2020. drop procedure if exists p1;
  2021. --enable_warnings
  2022. delimiter |;
  2023. create procedure p1()
  2024. begin
  2025. create table t1 (a int) engine=MyISAM;
  2026. drop table t1;
  2027. end|
  2028. delimiter ;|
  2029. call p1();
  2030. call p1();
  2031. drop procedure p1;
  2032. #
  2033. # Bug#8759 (Stored Procedures: SQLSTATE '00000' should be illegal)
  2034. #
  2035. --disable_warnings
  2036. drop procedure if exists proc_8759;
  2037. --enable_warnings
  2038. delimiter $$;
  2039. --error ER_SP_BAD_SQLSTATE
  2040. create procedure proc_8759()
  2041. begin
  2042. declare should_be_illegal condition for sqlstate '00000';
  2043. declare continue handler for should_be_illegal set @x=0;
  2044. end$$
  2045. --error ER_SP_BAD_SQLSTATE
  2046. create procedure proc_8759()
  2047. begin
  2048. declare continue handler for sqlstate '00000' set @x=0;
  2049. end$$
  2050. delimiter ;$$
  2051. #
  2052. # Bug#36510 (Stored Procedures: mysql_error_code 0 should be illegal)
  2053. #
  2054. --disable_warnings
  2055. drop procedure if exists proc_36510;
  2056. --enable_warnings
  2057. delimiter $$;
  2058. --error ER_SP_BAD_SQLSTATE
  2059. create procedure proc_36510()
  2060. begin
  2061. declare should_be_illegal condition for sqlstate '00123';
  2062. declare continue handler for should_be_illegal set @x=0;
  2063. end$$
  2064. --error ER_SP_BAD_SQLSTATE
  2065. create procedure proc_36510()
  2066. begin
  2067. declare continue handler for sqlstate '00123' set @x=0;
  2068. end$$
  2069. --error ER_WRONG_VALUE
  2070. create procedure proc_36510()
  2071. begin
  2072. declare should_be_illegal condition for 0;
  2073. declare continue handler for should_be_illegal set @x=0;
  2074. end$$
  2075. --error ER_WRONG_VALUE
  2076. create procedure proc_36510()
  2077. begin
  2078. declare continue handler for 0 set @x=0;
  2079. end$$
  2080. delimiter ;$$
  2081. #
  2082. # Bug#15192: "fatal errors" are caught by handlers in stored procedures
  2083. #
  2084. --disable_warnings
  2085. drop procedure if exists p1;
  2086. --enable_warnings
  2087. set @old_recursion_depth = @@max_sp_recursion_depth;
  2088. set @@max_sp_recursion_depth = 255;
  2089. delimiter |;
  2090. create procedure p1(a int)
  2091. begin
  2092. declare continue handler for 1436 -- ER_STACK_OVERRUN_NEED_MORE
  2093. select 'exception';
  2094. call p1(a+1);
  2095. end|
  2096. delimiter ;|
  2097. --error 0,ER_STACK_OVERRUN_NEED_MORE,ER_SP_RECURSION_LIMIT
  2098. call p1(1);
  2099. set @@max_sp_recursion_depth = @old_recursion_depth;
  2100. drop procedure p1;
  2101. #
  2102. # BUG#NNNN: New bug synopsis
  2103. #
  2104. #--disable_warnings
  2105. #drop procedure if exists bugNNNN;
  2106. #drop function if exists bugNNNN;
  2107. #--enable_warnings
  2108. #create procedure bugNNNN...
  2109. #create function bugNNNN...
  2110. #
  2111. # CLEANUP and RESTORE
  2112. #
  2113. LOAD DATA INFILE '../../tmp/proc.txt' INTO TABLE mysql.proc;
  2114. remove_file $MYSQLTEST_VARDIR/tmp/proc.txt;
  2115. #
  2116. # Bug #38159: Function parsing problem generates misleading error message
  2117. #
  2118. CREATE TABLE t1 (a INT, b INT);
  2119. INSERT INTO t1 VALUES (1,1), (2,2);
  2120. --error ER_FUNC_INEXISTENT_NAME_COLLISION
  2121. SELECT MAX (a) FROM t1 WHERE b = 999999;
  2122. SELECT AVG (a) FROM t1 WHERE b = 999999;
  2123. --error ER_SP_DOES_NOT_EXIST
  2124. SELECT non_existent (a) FROM t1 WHERE b = 999999;
  2125. DROP TABLE t1;
  2126. #
  2127. # Bug #46374 crash, INSERT INTO t1 uses function, function modifies t1
  2128. #
  2129. CREATE TABLE t1 ( f2 INTEGER, f3 INTEGER );
  2130. INSERT INTO t1 VALUES ( 1, 1 );
  2131. delimiter |;
  2132. CREATE FUNCTION func_1 () RETURNS INTEGER
  2133. BEGIN
  2134. INSERT INTO t1 SELECT * FROM t1 ;
  2135. RETURN 1 ;
  2136. END|
  2137. delimiter ;|
  2138. # The bug caused the following INSERT statement to trigger
  2139. # an assertion. Error 1442 is the correct response
  2140. #
  2141. --error 1442
  2142. INSERT INTO t1 SELECT * FROM (SELECT 2 AS f1, 2 AS f2) AS A WHERE func_1() = 5;
  2143. # Cleanup
  2144. DROP FUNCTION func_1;
  2145. DROP TABLE t1;
  2146. --echo #
  2147. --echo # Bug #47788: Crash in TABLE_LIST::hide_view_error on UPDATE + VIEW +
  2148. --echo # SP + MERGE + ALTER
  2149. --echo #
  2150. CREATE TABLE t1 (pk INT, b INT, KEY (b));
  2151. CREATE ALGORITHM = TEMPTABLE VIEW v1 AS SELECT * FROM t1;
  2152. CREATE PROCEDURE p1 (a int) UPDATE IGNORE v1 SET b = a;
  2153. --error ER_NON_UPDATABLE_TABLE
  2154. CALL p1(5);
  2155. ALTER TABLE t1 CHANGE COLUMN b b2 INT;
  2156. --error ER_VIEW_INVALID
  2157. CALL p1(7);
  2158. DROP PROCEDURE p1;
  2159. DROP VIEW v1;
  2160. DROP TABLE t1;
  2161. --echo #
  2162. --echo # Bug#12428824 - PARSER STACK OVERFLOW AND CRASH IN SP_ADD_USED_ROUTINE
  2163. --echo # WITH OBSCURE QUERY
  2164. --echo #
  2165. --error ER_TOO_LONG_IDENT
  2166. SELECT very_long_fn_name_1111111111111111111111111111111111111111111111111111111111111111111111111222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222225555555555555555555555555577777777777777777777777777777777777777777777777777777777777777777777777788888888999999999999999999999();
  2167. --error ER_TOO_LONG_IDENT
  2168. CALL very_long_pr_name_1111111111111111111111111111111111111111111111111111111111111111111111111222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222225555555555555555555555555577777777777777777777777777777777777777777777777777777777777777777777777788888888999999999999999999999();
  2169. --error ER_WRONG_DB_NAME
  2170. SELECT very_long_db_name_1111111111111111111111111111111111111111111111111111111111111111111111111222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222225555555555555555555555555577777777777777777777777777777777777777777777777777777777777777777777777788888888999999999999999999999.simple_func();
  2171. --error ER_WRONG_DB_NAME
  2172. CALL very_long_db_name_1111111111111111111111111111111111111111111111111111111111111111111111111222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222225555555555555555555555555577777777777777777777777777777777777777777777777777777777777777777777777788888888999999999999999999999.simple_proc();
  2173. --error ER_TOO_LONG_IDENT
  2174. SELECT db_name.very_long_fn_name_111111111111111111111111111111111111111111111111111111111111111111111111122222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999999999999999999();
  2175. --error ER_TOO_LONG_IDENT
  2176. CALL db_name.very_long_pr_name_111111111111111111111111111111111111111111111111111111111111111111111111122222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999999999999999999();
  2177. --echo End of 5.1 tests
  2178. --echo #
  2179. --echo # Bug#23032: Handlers declared in a SP do not handle warnings generated in sub-SP
  2180. --echo #
  2181. --echo
  2182. --echo # - Case 1
  2183. --echo
  2184. --disable_warnings
  2185. DROP PROCEDURE IF EXISTS p1;
  2186. DROP PROCEDURE IF EXISTS p2;
  2187. DROP PROCEDURE IF EXISTS p3;
  2188. DROP PROCEDURE IF EXISTS p4;
  2189. DROP PROCEDURE IF EXISTS p5;
  2190. DROP PROCEDURE IF EXISTS p6;
  2191. --enable_warnings
  2192. delimiter |;
  2193. CREATE PROCEDURE p1()
  2194. BEGIN
  2195. SELECT CAST('10 ' as unsigned integer);
  2196. SELECT 1;
  2197. CALL p2();
  2198. END|
  2199. CREATE PROCEDURE p2()
  2200. BEGIN
  2201. SELECT CAST('10 ' as unsigned integer);
  2202. END|
  2203. delimiter ;|
  2204. CALL p1();
  2205. DROP PROCEDURE p1;
  2206. DROP PROCEDURE p2;
  2207. --echo
  2208. --echo # - Case 2
  2209. --echo
  2210. delimiter |;
  2211. CREATE PROCEDURE p1()
  2212. BEGIN
  2213. DECLARE c INT DEFAULT 0;
  2214. DECLARE CONTINUE HANDLER FOR SQLWARNING SET c = c + 1;
  2215. CALL p2();
  2216. CALL p3();
  2217. CALL p4();
  2218. SELECT c;
  2219. SELECT @@warning_count;
  2220. SHOW WARNINGS;
  2221. END|
  2222. CREATE PROCEDURE p2()
  2223. BEGIN
  2224. SELECT CAST('10 ' as unsigned integer);
  2225. END|
  2226. CREATE PROCEDURE p3()
  2227. BEGIN
  2228. SELECT CAST('10 ' as unsigned integer);
  2229. SELECT 1;
  2230. END|
  2231. CREATE PROCEDURE p4()
  2232. BEGIN
  2233. SELECT CAST('10 ' as unsigned integer);
  2234. CALL p2();
  2235. END|
  2236. CREATE PROCEDURE p5()
  2237. BEGIN
  2238. SELECT CAST('10 ' as unsigned integer);
  2239. SHOW WARNINGS;
  2240. END|
  2241. CREATE PROCEDURE P6()
  2242. BEGIN
  2243. DECLARE c INT DEFAULT 0;
  2244. DECLARE CONTINUE HANDLER FOR SQLWARNING SET c = c + 1;
  2245. CALL p5();
  2246. SELECT c;
  2247. END|
  2248. delimiter ;|
  2249. CALL p1();
  2250. CALL p6();
  2251. DROP PROCEDURE p1;
  2252. DROP PROCEDURE p2;
  2253. DROP PROCEDURE p3;
  2254. DROP PROCEDURE p4;
  2255. DROP PROCEDURE p5;
  2256. DROP PROCEDURE p6;
  2257. --echo
  2258. --echo # - Case 3: check that "Exception trumps No Data".
  2259. --echo
  2260. --disable_warnings
  2261. DROP TABLE IF EXISTS t1;
  2262. --enable_warnings
  2263. CREATE TABLE t1(a INT);
  2264. INSERT INTO t1 VALUES (1), (2), (3);
  2265. delimiter |;
  2266. CREATE PROCEDURE p1()
  2267. BEGIN
  2268. DECLARE c CURSOR FOR SELECT a FROM t1;
  2269. OPEN c;
  2270. BEGIN
  2271. DECLARE v1 INT;
  2272. DECLARE v2 INT;
  2273. DECLARE EXIT HANDLER FOR SQLEXCEPTION
  2274. SELECT "Error caught (expected)";
  2275. DECLARE EXIT HANDLER FOR NOT FOUND
  2276. SELECT "End of Result Set found!";
  2277. WHILE TRUE DO
  2278. FETCH c INTO v1, v2;
  2279. END WHILE;
  2280. END;
  2281. CLOSE c;
  2282. SELECT a INTO @foo FROM t1 LIMIT 1; # Clear warning stack
  2283. END|
  2284. delimiter ;|
  2285. CALL p1();
  2286. DROP PROCEDURE p1;
  2287. DROP TABLE t1;
  2288. --echo #
  2289. --echo # Bug#36185: Incorrect precedence for warning and exception handlers
  2290. --echo #
  2291. --disable_warnings
  2292. DROP TABLE IF EXISTS t1;
  2293. DROP PROCEDURE IF EXISTS p1;
  2294. --enable_warnings
  2295. CREATE TABLE t1 (a INT, b INT NOT NULL);
  2296. delimiter |;
  2297. CREATE PROCEDURE p1()
  2298. BEGIN
  2299. DECLARE CONTINUE HANDLER FOR SQLWARNING SELECT 'warning';
  2300. DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SELECT 'exception';
  2301. INSERT INTO t1 VALUES (CAST('10 ' AS SIGNED), NULL);
  2302. END|
  2303. delimiter ;|
  2304. CALL p1();
  2305. DROP TABLE t1;
  2306. DROP PROCEDURE p1;
  2307. --echo #
  2308. --echo # Bug#5889: Exit handler for a warning doesn't hide the warning in trigger
  2309. --echo #
  2310. CREATE TABLE t1(a INT, b INT);
  2311. INSERT INTO t1 VALUES (1, 2);
  2312. delimiter |;
  2313. CREATE TRIGGER t1_bu BEFORE UPDATE ON t1 FOR EACH ROW
  2314. BEGIN
  2315. DECLARE EXIT HANDLER FOR SQLWARNING
  2316. SET NEW.a = 10;
  2317. SET NEW.a = 99999999999;
  2318. END|
  2319. delimiter ;|
  2320. UPDATE t1 SET b = 20;
  2321. SHOW WARNINGS;
  2322. SELECT * FROM t1;
  2323. DROP TRIGGER t1_bu;
  2324. DROP TABLE t1;
  2325. --echo #
  2326. --echo # Bug#9857: Stored procedures: handler for sqlwarning ignored
  2327. --echo #
  2328. SET @sql_mode_saved = @@sql_mode;
  2329. SET sql_mode = traditional;
  2330. delimiter |;
  2331. CREATE PROCEDURE p1()
  2332. BEGIN
  2333. DECLARE CONTINUE HANDLER FOR SQLWARNING
  2334. SELECT 'warning caught (expected)';
  2335. SELECT 5 / 0;
  2336. END|
  2337. CREATE PROCEDURE p2()
  2338. BEGIN
  2339. DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
  2340. SELECT 'error caught (unexpected)';
  2341. SELECT 5 / 0;
  2342. END|
  2343. delimiter ;|
  2344. CALL p1();
  2345. SHOW WARNINGS;
  2346. CALL p2();
  2347. SHOW WARNINGS;
  2348. DROP PROCEDURE p1;
  2349. DROP PROCEDURE p2;
  2350. SET sql_mode = @sql_mode_saved;
  2351. --echo #
  2352. --echo # Bug#55850: Trigger warnings not cleared.
  2353. --echo #
  2354. --disable_warnings
  2355. DROP TABLE IF EXISTS t1;
  2356. DROP TABLE IF EXISTS t2;
  2357. DROP PROCEDURE IF EXISTS p1;
  2358. --enable_warnings
  2359. CREATE TABLE t1(x SMALLINT, y SMALLINT, z SMALLINT);
  2360. CREATE TABLE t2(a SMALLINT, b SMALLINT, c SMALLINT,
  2361. d SMALLINT, e SMALLINT, f SMALLINT);
  2362. CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW
  2363. INSERT INTO t2(a, b, c) VALUES(99999, 99999, 99999);
  2364. CREATE TRIGGER t1_ai AFTER INSERT ON t1 FOR EACH ROW
  2365. INSERT INTO t2(d, e, f) VALUES(99999, 99999, 99999);
  2366. CREATE PROCEDURE p1()
  2367. INSERT INTO t1 VALUES(99999, 99999, 99999);
  2368. # What happened before the patch was:
  2369. # - INSERT INTO t1 added 3 warnings about overflow in 'x', 'y' and 'z' columns;
  2370. # - t1_bi run and added 3 warnings about overflow in 'a', 'b' and 'c' columns;
  2371. # - t1_ai run and added 3 warnings about overflow in 'd', 'e' and 'f' columns;
  2372. # => we had 9 warnings.
  2373. #
  2374. # Now what happens is:
  2375. # - INSERT INTO t1 adds 3 warnings about overflow in 'x', 'y' and 'z' columns;
  2376. # - t1_bi adds 3 warnings about overflow in 'a', 'b' and 'c' columns;
  2377. # - The warnings added by triggers are cleared;
  2378. # - t1_ai run and added 3 warnings about overflow in 'd', 'e' and 'f' columns;
  2379. # - The warnings added by tr