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

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

http://github.com/jyr/MNPP
Unknown | 2496 lines | 2123 code | 373 blank | 0 comment | 0 complexity | 863d7759d51fd92564411110c216fc56 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, LGPL-2.0, LGPL-3.0, MPL-2.0-no-copyleft-exception, GPL-2.0, BSD-3-Clause, GPL-3.0, BSD-2-Clause

Large files files are truncated, but you can click here to view the full file

  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 1100
  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_SP_BADSTATEMENT
  1150. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN load table t1 from master; END |
  1151. -- error ER_SP_BADSTATEMENT
  1152. CREATE FUNCTION bug_13627_f() returns int BEGIN load table t1 from master; 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 table t2 (a int); END |
  1155. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1156. CREATE FUNCTION bug_13627_f() returns int BEGIN create table t2 (a int); 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 create index t1_i on t1 (a); END |
  1159. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1160. CREATE FUNCTION bug_13627_f() returns int BEGIN create index t1_i on t1 (a); 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 alter table t1 add column b int; END |
  1163. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1164. CREATE FUNCTION bug_13627_f() returns int BEGIN alter table t1 add column b int; 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 rename table t1 to t2; END |
  1167. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1168. CREATE FUNCTION bug_13627_f() returns int BEGIN rename table t1 to t2; 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 truncate table t1; END |
  1171. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1172. CREATE FUNCTION bug_13627_f() returns int BEGIN truncate 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 table t1; END |
  1175. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1176. CREATE FUNCTION bug_13627_f() returns int BEGIN drop table t1; return 1; END |
  1177. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1178. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN drop index t1_i on t1; END |
  1179. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1180. CREATE FUNCTION bug_13627_f() returns int BEGIN drop index t1_i on t1; return 1; END |
  1181. -- error ER_SP_BADSTATEMENT
  1182. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN unlock tables; END |
  1183. -- error ER_SP_BADSTATEMENT
  1184. CREATE FUNCTION bug_13627_f() returns int BEGIN unlock tables; return 1; END |
  1185. -- error ER_SP_BADSTATEMENT
  1186. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN LOCK TABLE t1 READ; END |
  1187. -- error ER_SP_BADSTATEMENT
  1188. CREATE FUNCTION bug_13627_f() returns int BEGIN LOCK TABLE t1 READ; 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 create database mysqltest; END |
  1191. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1192. CREATE FUNCTION bug_13627_f() returns int BEGIN create 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 drop database mysqltest; END |
  1195. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1196. CREATE FUNCTION bug_13627_f() returns int BEGIN drop database mysqltest; return 1; END |
  1197. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1198. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN create user 'mysqltest_1'; END |
  1199. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1200. CREATE FUNCTION bug_13627_f() returns int BEGIN create user '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 grant select on t1 to 'mysqltest_1'; END |
  1203. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1204. CREATE FUNCTION bug21975() returns int BEGIN grant select on t1 to '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 select on t1 from 'mysqltest_1'; END |
  1207. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1208. CREATE FUNCTION bug21975() returns int BEGIN revoke select on t1 from 'mysqltest_1'; return 1; END |
  1209. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1210. CREATE TRIGGER bug21975 BEFORE INSERT ON t1 FOR EACH ROW BEGIN revoke all privileges on *.* from 'mysqltest_1'; END |
  1211. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1212. CREATE FUNCTION bug21975() returns int BEGIN revoke all privileges on *.* from '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 drop user 'mysqltest_1'; END |
  1215. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1216. CREATE FUNCTION bug_13627_f() returns int BEGIN drop user '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 rename user 'mysqltest_2' to 'mysqltest_1'; END |
  1219. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1220. CREATE FUNCTION bug_13627_f() returns int BEGIN rename user 'mysqltest_2' to 'mysqltest_1'; return 1; END |
  1221. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1222. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN create view v1 as select 1; END |
  1223. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1224. CREATE FUNCTION bug_13627_f() returns int BEGIN create view v1 as select 1; return 1; END |
  1225. -- error ER_SP_BADSTATEMENT
  1226. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN alter view v1 as select 1; END |
  1227. -- error ER_SP_BADSTATEMENT
  1228. CREATE FUNCTION bug_13627_f() returns int BEGIN alter view v1 as select 1; return 1; END |
  1229. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1230. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN drop view v1; END |
  1231. -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1232. CREATE FUNCTION bug_13627_f() returns int BEGIN drop view v1; return 1; END |
  1233. -- error ER_SP_NO_RECURSIVE_CREATE
  1234. 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 |
  1235. -- error ER_SP_NO_RECURSIVE_CREATE
  1236. CREATE FUNCTION bug_13627_f() returns int BEGIN create trigger tr2 before insert on t1 for each row do select 1; return 1; END |
  1237. -- error ER_SP_NO_DROP_SP
  1238. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN drop function bug_13627_f; END |
  1239. -- error ER_SP_NO_DROP_SP
  1240. CREATE FUNCTION bug_13627_f() returns int BEGIN drop function bug_13627_f; return 1; END |
  1241. -- error ER_SP_NO_RECURSIVE_CREATE
  1242. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN create function f2 () returns int return 1; END |
  1243. -- error ER_SP_NO_RECURSIVE_CREATE
  1244. CREATE FUNCTION bug_13627_f() returns int BEGIN create function f2 () returns int return 1; return 1; END |
  1245. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW
  1246. BEGIN
  1247. CREATE TEMPORARY TABLE t2 (a int);
  1248. DROP TEMPORARY TABLE t2;
  1249. END |
  1250. CREATE FUNCTION bug_13627_f() returns int
  1251. BEGIN
  1252. CREATE TEMPORARY TABLE t2 (a int);
  1253. DROP TEMPORARY TABLE t2;
  1254. return 1;
  1255. END |
  1256. drop table t1|
  1257. drop function bug_13627_f|
  1258. delimiter ;|
  1259. # BUG#12329: "Bogus error msg when executing PS with stored procedure after
  1260. # SP was re-created". See also test for related bug#13399 in trigger.test
  1261. drop function if exists bug12329;
  1262. --enable_warnings
  1263. create table t1 as select 1 a;
  1264. create table t2 as select 1 a;
  1265. create function bug12329() returns int return (select a from t1);
  1266. prepare stmt1 from 'select bug12329()';
  1267. execute stmt1;
  1268. drop function bug12329;
  1269. create function bug12329() returns int return (select a+100 from t2);
  1270. select bug12329();
  1271. execute stmt1;
  1272. deallocate prepare stmt1;
  1273. drop function bug12329;
  1274. drop table t1, t2;
  1275. #
  1276. # Bug#13514 "server crash when create a stored procedure before choose a
  1277. # database" and
  1278. # Bug#13587 "Server crash when SP is created without database
  1279. # selected"
  1280. #
  1281. create database mysqltest1;
  1282. use mysqltest1;
  1283. drop database mysqltest1;
  1284. --error ER_NO_DB_ERROR
  1285. create function f1() returns int return 1;
  1286. delimiter |;
  1287. --error ER_NO_DB_ERROR
  1288. create procedure p1(out param1 int)
  1289. begin
  1290. select count(*) into param1 from t3;
  1291. end|
  1292. delimiter ;|
  1293. use test;
  1294. #
  1295. # BUG#13037: undefined variable in IF cause erroneous error-message
  1296. #
  1297. --disable_warnings
  1298. DROP PROCEDURE IF EXISTS bug13037_p1;
  1299. DROP PROCEDURE IF EXISTS bug13037_p2;
  1300. DROP PROCEDURE IF EXISTS bug13037_p3;
  1301. --enable_warnings
  1302. delimiter |;
  1303. CREATE PROCEDURE bug13037_p1()
  1304. BEGIN
  1305. IF bug13037_foo THEN
  1306. SELECT 1;
  1307. END IF;
  1308. END|
  1309. CREATE PROCEDURE bug13037_p2()
  1310. BEGIN
  1311. SET @bug13037_foo = bug13037_bar;
  1312. END|
  1313. CREATE PROCEDURE bug13037_p3()
  1314. BEGIN
  1315. SELECT bug13037_foo;
  1316. END|
  1317. delimiter ;|
  1318. --echo
  1319. --error 1054
  1320. CALL bug13037_p1();
  1321. --error 1054
  1322. CALL bug13037_p2();
  1323. --error 1054
  1324. CALL bug13037_p3();
  1325. --error 1054
  1326. CALL bug13037_p1();
  1327. --error 1054
  1328. CALL bug13037_p2();
  1329. --error 1054
  1330. CALL bug13037_p3();
  1331. DROP PROCEDURE bug13037_p1;
  1332. DROP PROCEDURE bug13037_p2;
  1333. DROP PROCEDURE bug13037_p3;
  1334. #
  1335. # Bug#14569 "editing a stored procedure kills mysqld-nt"
  1336. #
  1337. create database mysqltest1;
  1338. create database mysqltest2;
  1339. use mysqltest1;
  1340. drop database mysqltest1;
  1341. create procedure mysqltest2.p1() select version();
  1342. --error ER_NO_DB_ERROR
  1343. create procedure p2() select version();
  1344. use mysqltest2;
  1345. --replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00'
  1346. show procedure status;
  1347. drop database mysqltest2;
  1348. use test;
  1349. #
  1350. # Bug#13012 "SP: REPAIR/BACKUP/RESTORE TABLE crashes the server"
  1351. #
  1352. delimiter |;
  1353. --disable_warnings
  1354. DROP FUNCTION IF EXISTS bug13012|
  1355. --enable_warnings
  1356. --error ER_SP_NO_RETSET
  1357. CREATE FUNCTION bug13012() RETURNS INT
  1358. BEGIN
  1359. REPAIR TABLE t1;
  1360. RETURN 1;
  1361. END|
  1362. --error ER_SP_NO_RETSET
  1363. CREATE FUNCTION bug13012() RETURNS INT
  1364. BEGIN
  1365. BACKUP TABLE t1 TO '/tmp';
  1366. RETURN 1;
  1367. END|
  1368. --error ER_SP_NO_RETSET
  1369. CREATE FUNCTION bug13012() RETURNS INT
  1370. BEGIN
  1371. RESTORE TABLE t1 FROM '/tmp';
  1372. RETURN 1;
  1373. END|
  1374. create table t1 (a int)|
  1375. CREATE PROCEDURE bug13012_1() REPAIR TABLE t1|
  1376. CREATE FUNCTION bug13012_2() RETURNS INT
  1377. BEGIN
  1378. CALL bug13012_1();
  1379. RETURN 1;
  1380. END|
  1381. --error ER_SP_NO_RETSET
  1382. SELECT bug13012_2()|
  1383. drop table t1|
  1384. drop procedure bug13012_1|
  1385. drop function bug13012_2|
  1386. delimiter ;|
  1387. #
  1388. # BUG#11555 "Stored procedures: current SP tables locking make
  1389. # impossible view security". We should not expose names of tables
  1390. # which are implicitly used by view (via stored routines/triggers).
  1391. #
  1392. # Note that SQL standard assumes that you simply won't be able drop table
  1393. # and leave some objects (routines/views/triggers) which were depending on
  1394. # it. Such objects should be dropped in advance (by default) or will be
  1395. # dropped simultaneously with table (DROP TABLE with CASCADE clause).
  1396. # So these tests probably should go away once we will implement standard
  1397. # behavior.
  1398. --disable_warnings
  1399. drop function if exists bug11555_1;
  1400. drop function if exists bug11555_2;
  1401. drop view if exists v1, v2, v3, v4;
  1402. --enable_warnings
  1403. create function bug11555_1() returns int return (select max(i) from t1);
  1404. create function bug11555_2() returns int return bug11555_1();
  1405. # It is OK to report name of implicitly used table which is missing
  1406. # when we create view.
  1407. # For stored functions however, because of exceptions handlers, there is
  1408. # no easy way to find out if a missing table makes the view invalid.
  1409. create view v1 as select bug11555_1();
  1410. drop view v1;
  1411. create view v2 as select bug11555_2();
  1412. drop view v2;
  1413. # But we should hide name of missing implicitly used table when we use view
  1414. create table t1 (i int);
  1415. create view v1 as select bug11555_1();
  1416. create view v2 as select bug11555_2();
  1417. create view v3 as select * from v1;
  1418. drop table t1;
  1419. --error ER_VIEW_INVALID
  1420. select * from v1;
  1421. --error ER_VIEW_INVALID
  1422. select * from v2;
  1423. --error ER_VIEW_INVALID
  1424. select * from v3;
  1425. # Note that creation of view which depends on broken view is yet
  1426. # another form of view usage.
  1427. create view v4 as select * from v1;
  1428. drop view v1, v2, v3, v4;
  1429. # We also should hide details about broken triggers which are
  1430. # invoked for view.
  1431. drop function bug11555_1;
  1432. drop function bug11555_2;
  1433. create table t1 (i int);
  1434. create table t2 (i int);
  1435. create trigger t1_ai after insert on t1 for each row insert into t2 values (new.i);
  1436. create view v1 as select * from t1;
  1437. drop table t2;
  1438. # Limitation, the desired error is ER_VIEW_INVALID
  1439. --error ER_NO_SUCH_TABLE
  1440. insert into v1 values (1);
  1441. drop trigger t1_ai;
  1442. create function bug11555_1() returns int return (select max(i) from t2);
  1443. create trigger t1_ai after insert on t1 for each row set @a:=bug11555_1();
  1444. # Limitation, the desired error is ER_VIEW_INVALID
  1445. --error ER_NO_SUCH_TABLE
  1446. insert into v1 values (2);
  1447. drop function bug11555_1;
  1448. drop table t1;
  1449. drop view v1;
  1450. #
  1451. # BUG#15658: Server crashes after creating function as empty string
  1452. #
  1453. --disable_warnings
  1454. drop procedure if exists ` bug15658`;
  1455. --enable_warnings
  1456. --error ER_SP_WRONG_NAME
  1457. create procedure ``() select 1;
  1458. --error ER_SP_WRONG_NAME
  1459. create procedure ` `() select 1;
  1460. --error ER_SP_WRONG_NAME
  1461. create procedure `bug15658 `() select 1;
  1462. --error ER_WRONG_DB_NAME
  1463. create procedure ``.bug15658() select 1;
  1464. --error ER_WRONG_DB_NAME
  1465. create procedure `x `.bug15658() select 1;
  1466. # This should work
  1467. create procedure ` bug15658`() select 1;
  1468. call ` bug15658`();
  1469. --replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00'
  1470. show procedure status;
  1471. drop procedure ` bug15658`;
  1472. #
  1473. # BUG#14270: Stored procedures: crash if load index
  1474. #
  1475. --disable_warnings
  1476. drop function if exists bug14270;
  1477. drop table if exists t1;
  1478. --enable_warnings
  1479. create table t1 (s1 int primary key);
  1480. delimiter |;
  1481. --error ER_SP_NO_RETSET
  1482. create function bug14270() returns int
  1483. begin
  1484. load index into cache t1;
  1485. return 1;
  1486. end|
  1487. --error ER_SP_NO_RETSET
  1488. create function bug14270() returns int
  1489. begin
  1490. cache index t1 key (`primary`) in keycache1;
  1491. return 1;
  1492. end|
  1493. delimiter ;|
  1494. drop table t1;
  1495. #
  1496. # BUG#15091: Sp Returns Unknown error in order clause....and
  1497. # there is no order by clause
  1498. #
  1499. --disable_warnings
  1500. drop procedure if exists bug15091;
  1501. --enable_warnings
  1502. delimiter |;
  1503. create procedure bug15091()
  1504. begin
  1505. declare selectstr varchar(6000) default ' ';
  1506. declare conditionstr varchar(5000) default '';
  1507. set selectstr = concat(selectstr,
  1508. ' and ',
  1509. c.operatorid,
  1510. 'in (',conditionstr, ')');
  1511. end|
  1512. delimiter ;|
  1513. # The error message used to be:
  1514. # ERROR 1109 (42S02): Unknown table 'c' in order clause
  1515. # but is now rephrased to something less misleading:
  1516. # ERROR 1109 (42S02): Unknown table 'c' in field list
  1517. --error ER_UNKNOWN_TABLE
  1518. call bug15091();
  1519. drop procedure bug15091;
  1520. #
  1521. # BUG#16896: Stored function: unused AGGREGATE-clause in CREATE FUNCTION
  1522. #
  1523. --disable_warnings
  1524. drop function if exists bug16896;
  1525. --enable_warnings
  1526. --error ER_PARSE_ERROR
  1527. create aggregate function bug16896() returns int return 1;
  1528. #
  1529. #
  1530. # BUG#14702: misleading error message when syntax error in CREATE
  1531. # PROCEDURE
  1532. #
  1533. # Misleading error message was given when IF NOT EXISTS was used in
  1534. # CREATE PROCEDURE.
  1535. #
  1536. --disable_warnings
  1537. DROP PROCEDURE IF EXISTS bug14702;
  1538. --enable_warnings
  1539. --error ER_PARSE_ERROR
  1540. CREATE IF NOT EXISTS PROCEDURE bug14702()
  1541. BEGIN
  1542. END;
  1543. --error ER_PARSE_ERROR
  1544. CREATE PROCEDURE IF NOT EXISTS bug14702()
  1545. BEGIN
  1546. END;
  1547. #
  1548. # BUG#20953: create proc with a create view that uses local
  1549. # vars/params should fail to create
  1550. #
  1551. # See test case for what syntax is forbidden in a view.
  1552. #
  1553. --disable_warnings
  1554. DROP TABLE IF EXISTS t1;
  1555. --enable_warnings
  1556. CREATE TABLE t1 (i INT);
  1557. # We do not have to drop this procedure and view because they won't be
  1558. # created.
  1559. --error ER_VIEW_SELECT_CLAUSE
  1560. CREATE PROCEDURE bug20953() CREATE VIEW v AS SELECT 1 INTO @a;
  1561. --error ER_VIEW_SELECT_CLAUSE
  1562. CREATE PROCEDURE bug20953() CREATE VIEW v AS SELECT 1 INTO DUMPFILE "file";
  1563. --error ER_VIEW_SELECT_CLAUSE
  1564. CREATE PROCEDURE bug20953() CREATE VIEW v AS SELECT 1 INTO OUTFILE "file";
  1565. --error ER_VIEW_SELECT_CLAUSE
  1566. CREATE PROCEDURE bug20953()
  1567. CREATE VIEW v AS SELECT i FROM t1 PROCEDURE ANALYSE();
  1568. --error ER_VIEW_SELECT_DERIVED
  1569. CREATE PROCEDURE bug20953() CREATE VIEW v AS SELECT 1 FROM (SELECT 1) AS d1;
  1570. --error ER_VIEW_SELECT_VARIABLE
  1571. CREATE PROCEDURE bug20953(i INT) CREATE VIEW v AS SELECT i;
  1572. delimiter |;
  1573. --error ER_VIEW_SELECT_VARIABLE
  1574. CREATE PROCEDURE bug20953()
  1575. BEGIN
  1576. DECLARE i INT;
  1577. CREATE VIEW v AS SELECT i;
  1578. END |
  1579. delimiter ;|
  1580. --error ER_VIEW_SELECT_VARIABLE
  1581. PREPARE stmt FROM "CREATE VIEW v AS SELECT ?";
  1582. DROP TABLE t1;
  1583. #
  1584. # BUG#24491 "using alias from source table in insert ... on duplicate key"
  1585. #
  1586. --disable_warnings
  1587. drop tables if exists t1;
  1588. drop procedure if exists bug24491;
  1589. --enable_warnings
  1590. create table t1 (id int primary key auto_increment, value varchar(10));
  1591. insert into t1 (id, value) values (1, 'FIRST'), (2, 'SECOND'), (3, 'THIRD');
  1592. # Let us create routine with INSERT ... SELECT ... ON DUPLICATE KEY UPDATE
  1593. # statement which in its ON DUPLICATE KEY clause erroneously tries to assign
  1594. # value to a column which is mentioned only in SELECT part.
  1595. create procedure bug24491()
  1596. insert into t1 (id, value) select * from (select 4 as i, 'FOURTH' as v) as y on duplicate key update v = 'DUP';
  1597. # Both first and second calls to it should fail
  1598. --error ER_BAD_FIELD_ERROR
  1599. call bug24491();
  1600. --error ER_BAD_FIELD_ERROR
  1601. call bug24491();
  1602. drop procedure bug24491;
  1603. # And now the same test for more complex case which is more close
  1604. # to the one that was reported originally.
  1605. create procedure bug24491()
  1606. insert into t1 (id, value) select * from (select 4 as id, 'FOURTH' as value) as y on duplicate key update y.value = 'DUP';
  1607. --error ER_BAD_FIELD_ERROR
  1608. call bug24491();
  1609. --error ER_BAD_FIELD_ERROR
  1610. call bug24491();
  1611. drop procedure bug24491;
  1612. drop tables t1;
  1613. #
  1614. # BUG#18914: Calling certain SPs from triggers fail
  1615. #
  1616. # Failing to call a procedure that does implicit commit from a trigger
  1617. # is a correct behaviour, however the error message was misleading.
  1618. #
  1619. # DROP TABLE IF EXISTS is also fixed to give correct error instead of
  1620. # "Table doesn't exist".
  1621. #
  1622. --disable_warnings
  1623. DROP FUNCTION IF EXISTS bug18914_f1;
  1624. DROP FUNCTION IF EXISTS bug18914_f2;
  1625. DROP PROCEDURE IF EXISTS bug18914_p1;
  1626. DROP PROCEDURE IF EXISTS bug18914_p2;
  1627. DROP TABLE IF EXISTS t1, t2;
  1628. --enable_warnings
  1629. CREATE TABLE t1 (i INT);
  1630. CREATE PROCEDURE bug18914_p1() CREATE TABLE t2 (i INT);
  1631. CREATE PROCEDURE bug18914_p2() DROP TABLE IF EXISTS no_such_table;
  1632. delimiter |;
  1633. CREATE FUNCTION bug18914_f1() RETURNS INT
  1634. BEGIN
  1635. CALL bug18914_p1();
  1636. RETURN 1;
  1637. END |
  1638. CREATE FUNCTION bug18914_f2() RETURNS INT
  1639. BEGIN
  1640. CALL bug18914_p2();
  1641. RETURN 1;
  1642. END |
  1643. delimiter ;|
  1644. CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW
  1645. CALL bug18914_p1();
  1646. --error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1647. INSERT INTO t1 VALUES (1);
  1648. --error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1649. SELECT bug18914_f1();
  1650. --error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
  1651. SELECT bug18914_f2();
  1652. --error ER_NO_SUCH_TABLE
  1653. SELECT * FROM t2;
  1654. DROP FUNCTION bug18914_f1;
  1655. DROP FUNCTION bug18914_f2;
  1656. DROP PROCEDURE bug18914_p1;
  1657. DROP PROCEDURE bug18914_p2;
  1658. DROP TABLE t1;
  1659. #
  1660. # Bug#20713 (Functions will not not continue for SQLSTATE VALUE '42S02')
  1661. #
  1662. --disable_warnings
  1663. drop table if exists bogus_table_20713;
  1664. drop function if exists func_20713_a;
  1665. drop function if exists func_20713_b;
  1666. --enable_warnings
  1667. create table bogus_table_20713( id int(10) not null primary key);
  1668. insert into bogus_table_20713 values (1), (2), (3);
  1669. delimiter //;
  1670. create function func_20713_a() returns int(11)
  1671. begin
  1672. declare id int;
  1673. declare continue handler for sqlexception set id=null;
  1674. set @in_func := 1;
  1675. set id = (select id from bogus_table_20713 where id = 3);
  1676. set @in_func := 2;
  1677. return id;
  1678. end//
  1679. create function func_20713_b() returns int(11)
  1680. begin
  1681. declare id int;
  1682. declare continue handler for sqlstate value '42S02' set id=null;
  1683. set @in_func := 1;
  1684. set id = (select id from bogus_table_20713 where id = 3);
  1685. set @in_func := 2;
  1686. return id;
  1687. end//
  1688. delimiter ;//
  1689. set @in_func := 0;
  1690. select func_20713_a();
  1691. select @in_func;
  1692. set @in_func := 0;
  1693. select func_20713_b();
  1694. select @in_func;
  1695. drop table bogus_table_20713;
  1696. set @in_func := 0;
  1697. select func_20713_a();
  1698. select @in_func;
  1699. set @in_func := 0;
  1700. select func_20713_b();
  1701. select @in_func;
  1702. drop function if exists func_20713_a;
  1703. drop function if exists func_20713_b;
  1704. #
  1705. # Bug#25345 (Cursors from Functions)
  1706. #
  1707. --disable_warnings
  1708. drop table if exists table_25345_a;
  1709. drop table if exists table_25345_b;
  1710. drop procedure if exists proc_25345;
  1711. drop function if exists func_25345;
  1712. drop function if exists func_25345_b;
  1713. --enable_warnings
  1714. create table table_25345_a (a int);
  1715. create table table_25345_b (b int);
  1716. delimiter ||;
  1717. create procedure proc_25345()
  1718. begin
  1719. declare c1 cursor for select a from table_25345_a;
  1720. declare c2 cursor for select b from table_25345_b;
  1721. select 1 as result;
  1722. end ||
  1723. create function func_25345() returns int(11)
  1724. begin
  1725. call proc_25345();
  1726. return 1;
  1727. end ||
  1728. create function func_25345_b() returns int(11)
  1729. begin
  1730. declare c1 cursor for select a from table_25345_a;
  1731. declare c2 cursor for select b from table_25345_b;
  1732. return 1;
  1733. end ||
  1734. delimiter ;||
  1735. call proc_25345();
  1736. --error ER_SP_NO_RETSET
  1737. select func_25345();
  1738. select func_25345_b();
  1739. drop table table_25345_a;
  1740. call proc_25345();
  1741. --error ER_SP_NO_RETSET
  1742. select func_25345();
  1743. select func_25345_b();
  1744. drop table table_25345_b;
  1745. drop procedure proc_25345;
  1746. drop function func_25345;
  1747. drop function func_25345_b;
  1748. #
  1749. # End of 5.0 tests
  1750. #
  1751. --echo End of 5.0 tests
  1752. #
  1753. # Bug#16164 "Easter egg": check that SHOW AUTHORS is disabled in
  1754. # stored functions/triggers
  1755. #
  1756. --disable_warnings
  1757. drop function if exists bug16164;
  1758. --enable_warnings
  1759. delimiter |;
  1760. --error ER_SP_NO_RETSET
  1761. create function bug16164() returns int
  1762. begin
  1763. show authors;
  1764. return 42;
  1765. end|
  1766. delimiter ;|
  1767. #
  1768. # BUG#20701: BINARY keyword should be forbidden in stored routines
  1769. #
  1770. --disable_warnings
  1771. drop function if exists bug20701;
  1772. --enable_warnings
  1773. #
  1774. # This was disabled in 5.1.12. See bug #20701
  1775. # When collation support in SP is implemented, then this test should
  1776. # be removed.
  1777. #
  1778. --error ER_NOT_SUPPORTED_YET
  1779. create function bug20701() returns varchar(25) binary return "test";
  1780. create function bug20701() returns varchar(25) return "test";
  1781. drop function bug20701;
  1782. #
  1783. # Bug#26503 (Illegal SQL exception handler code causes the server to crash)
  1784. #
  1785. delimiter //;
  1786. --error ER_SP_LILABEL_MISMATCH
  1787. create procedure proc_26503_error_1()
  1788. begin
  1789. retry:
  1790. repeat
  1791. begin
  1792. declare continue handler for sqlexception
  1793. begin
  1794. iterate retry;
  1795. end
  1796. select "do something";
  1797. end
  1798. until true end repeat retry;
  1799. end//
  1800. --error ER_SP_LILABEL_MISMATCH
  1801. create procedure proc_26503_error_2()
  1802. begin
  1803. retry:
  1804. repeat
  1805. begin
  1806. declare continue handler for sqlexception
  1807. iterate retry;
  1808. select "do something";
  1809. end
  1810. until true end repeat retry;
  1811. end//
  1812. --error ER_SP_LILABEL_MISMATCH
  1813. create procedure proc_26503_error_3()
  1814. begin
  1815. retry:
  1816. repeat
  1817. begin
  1818. declare continue handler for sqlexception
  1819. begin
  1820. leave retry;
  1821. end
  1822. select "do something";
  1823. end
  1824. until true end repeat retry;
  1825. end//
  1826. --error ER_SP_LILABEL_MISMATCH
  1827. create procedure proc_26503_error_4()
  1828. b

Large files files are truncated, but you can click here to view the full file