1 #### suite/funcs_1/storedproc/storedproc_10.inc
3 # This test cannot be used for the embedded server because we check here
5 --source include/not_embedded.inc
7 --source suite/funcs_1/storedproc/load_sp_tb.inc
9 # ==============================================================================
10 # (numbering from requirement document TP v1.0, Last updated: 25 Jan 2005 01:00)
14 ## 1. Ensure that a properly defined procedure can always be called, assuming
15 # the appropriate privileges exist.
16 #- 2. Ensure that a procedure cannot be called if the appropriate privileges
18 ## 3. Ensure that a function can never be called.
19 ## 4. Ensure that a properly defined function can always be executed, assuming
20 # the appropriate privileges exist.
21 #- 5. Ensure that a function cannot be executed if the appropriate privileges
23 ## 6. Ensure that a procedure can never be executed.
24 ## 7. Ensure that the ROW_COUNT() SQL function always returns the correct
25 # number of rows affected by the execution of a stored procedure.
26 ## 8. Ensure that the mysql_affected_rows() C API function always returns
27 # the correct number of rows affected by the execution of a
30 # ==============================================================================
31 let $message= Section 3.1.10 - CALL checks:;
32 --source include/show_msg80.inc
37 # ------------------------------------------------------------------------------
38 let $message= Testcase 3.1.10.2 + 3.1.10.5:;
39 --source include/show_msg.inc
41 2. Ensure that a procedure cannot be called
if the appropriate privileges
do not
43 5. Ensure that a
function cannot be executed
if the appropriate privileges
do
45 --source include/show_msg80.inc
48 DROP PROCEDURE IF EXISTS sp31102;
49 DROP FUNCTION IF EXISTS fn31105;
53 create user
'user_1'@
'localhost';
55 create user
'user_2'@
'localhost';
57 GRANT CREATE ROUTINE ON db_storedproc.* TO
'user_1'@
'localhost';
58 GRANT SELECT ON db_storedproc.* TO
'user_2'@
'localhost';
61 connect (user2_1, localhost, user_1, , db_storedproc);
62 --source suite/funcs_1/include/show_connection.inc
65 CREATE PROCEDURE sp31102 () SQL SECURITY INVOKER
67 SELECT * FROM db_storedproc.t1 WHERE f4=-5000 LIMIT 1;
72 CREATE FUNCTION fn31105(
n INT) RETURNS INT
82 connect (user2_2, localhost, user_2, , db_storedproc);
83 --source suite/funcs_1/include/show_connection.inc
86 --error ER_PROCACCESS_DENIED_ERROR
90 # now 'add' EXECUTE to INVOKER
91 --echo connection
default;
94 --source suite/funcs_1/include/show_connection.inc
95 # root can execute ...
98 GRANT EXECUTE ON db_storedproc.* TO
'user_2'@
'localhost';
103 connect (user2_3, localhost, user_2, , db_storedproc);
104 --source suite/funcs_1/include/show_connection.inc
109 # now 'remove' SELECT from INVOKER
110 --echo connection
default;
113 --source suite/funcs_1/include/show_connection.inc
114 REVOKE EXECUTE ON db_storedproc.* FROM
'user_2'@
'localhost';
117 # root can still execute
121 connect (user2_4, localhost, user_2, , db_storedproc);
122 --source suite/funcs_1/include/show_connection.inc
131 --source suite/funcs_1/include/show_connection.inc
132 DROP PROCEDURE sp31102;
133 DROP FUNCTION fn31105;
134 DROP USER
'user_1'@
'localhost';
135 DROP USER
'user_2'@
'localhost';
138 # ------------------------------------------------------------------------------
139 let $message= Testcase 3.1.10.3:;
140 --source include/show_msg.inc
142 Ensure that a
function can never be called.;
143 --source include/show_msg80.inc
146 DROP FUNCTION IF EXISTS fn1;
150 CREATE FUNCTION fn1(a
int) returns
int
157 --error ER_SP_DOES_NOT_EXIST
164 # ------------------------------------------------------------------------------
165 let $message= Testcase 3.1.10.6:;
166 --source include/show_msg.inc
168 Ensure that a procedure can never be executed.;
169 --source include/show_msg80.inc
172 DROP PROCEDURE IF EXISTS sp1;
173 DROP FUNCTION IF EXISTS sp1;
177 CREATE PROCEDURE sp1()
183 --error ER_SP_DOES_NOT_EXIST
190 # ------------------------------------------------------------------------------
191 let $message= Testcase 3.1.10.7:;
192 --source include/show_msg.inc
194 Ensure that the ROW_COUNT() SQL function always returns the correct number of
195 rows affected by the execution of a stored procedure.;
196 --source include/show_msg80.inc
197 # Note(mleich): Information taken from a comments in
198 # Bug#21818 Return value of ROW_COUNT() is incorrect for
199 # ALTER TABLE, LOAD DATA
200 # ROW_COUNT() is -1 following any statement which is not DELETE, INSERT
202 # Also, after a CALL statement, ROW_COUNT() will return the value of the
203 # last statement in the stored procedure.
206 DROP PROCEDURE IF EXISTS sp_ins_1;
207 DROP PROCEDURE IF EXISTS sp_ins_3;
208 DROP PROCEDURE IF EXISTS sp_upd;
209 DROP PROCEDURE IF EXISTS sp_ins_upd;
210 DROP PROCEDURE IF EXISTS sp_del;
211 DROP PROCEDURE IF EXISTS sp_with_rowcount;
214 CREATE
TABLE temp(f1 CHAR(20),f2 CHAR(25),f3 DATE,f4 INT,f5 CHAR(25),f6 INT);
215 INSERT INTO
temp SELECT * FROM t10;
218 CREATE PROCEDURE sp_ins_1()
220 INSERT INTO
temp VALUES ('abc', 'abc', '20051003', 100, 'uvw', 1000);
223 CREATE PROCEDURE sp_ins_3()
225 INSERT INTO
temp VALUES ('abc', 'xyz', '19490523', 100, 'uvw', 1000);
226 INSERT INTO
temp VALUES ('abc', 'xyz', '1989-11-09', 100, 'uvw', 1000);
227 INSERT INTO
temp VALUES ('abc', 'xyz', '2005-10-24', 100, 'uvw', 1000);
230 CREATE PROCEDURE sp_upd()
232 UPDATE
temp SET
temp.f1 = 'updated' WHERE
temp.f1 ='abc';
235 CREATE PROCEDURE sp_ins_upd()
238 INSERT INTO
temp VALUES ('qwe', 'abc', '1989-11-09', 100, 'uvw', 1000);
239 INSERT INTO
temp VALUES ('qwe', 'xyz', '1998-03-26', 100, 'uvw', 1000);
240 INSERT INTO
temp VALUES ('qwe', 'abc', '2000-11-09', 100, 'uvw', 1000);
241 INSERT INTO
temp VALUES ('qwe', 'abc', '2005-11-07', 100, 'uvw', 1000);
243 SELECT COUNT( f1 ), f1 FROM
temp GROUP BY f1;
244 UPDATE
temp SET
temp.f1 = 'updated_2' WHERE
temp.f1 ='qwe' AND
temp.f2 = 'abc';
247 CREATE PROCEDURE sp_del()
249 DELETE FROM
temp WHERE
temp.f1 ='qwe' OR
temp.f1 = 'updated_2';
252 CREATE PROCEDURE sp_with_rowcount()
255 INSERT INTO
temp VALUES ('qwe', 'abc', '1989-11-09', 100, 'uvw', 1000),
256 ('qwe', 'xyz', '1998-03-26', 100, 'uvw', 1000),
257 ('qwe', 'abc', '2000-11-09', 100, 'uvw', 1000),
258 ('qwe', 'xyz', '2005-11-07', 100, 'uvw', 1000);
260 SELECT row_count() AS 'row_count() after insert';
261 SELECT row_count() AS 'row_count() after select row_count()';
262 SELECT f1,f2,f3 FROM
temp ORDER BY f1,f2,f3;
263 UPDATE
temp SET
temp.f1 = 'updated_2' WHERE
temp.f2 = 'abc';
264 SELECT row_count() AS 'row_count() after update';
265 SELECT f1,f2,f3 FROM
temp ORDER BY f1,f2,f3;
266 DELETE FROM
temp WHERE
temp.f1 = 'updated_2';
267 SELECT row_count() AS 'row_count() after delete';
297 CALL sp_with_rowcount();
304 DROP PROCEDURE sp_ins_1;
305 DROP PROCEDURE sp_ins_3;
306 DROP PROCEDURE sp_upd;
307 DROP PROCEDURE sp_ins_upd;
308 DROP PROCEDURE sp_del;
309 DROP PROCEDURE sp_with_rowcount;
313 # ------------------------------------------------------------------------------
314 let $message= Testcase 3.1.10.8:;
315 --source include/show_msg.inc
317 Ensure that the mysql_affected_rows() C API function always returns the correct
318 number of rows affected by the execution of a stored procedure.;
319 --source include/show_msg80.inc
321 #FIXME: 3.1.10.8: to be added later.
323 # ==============================================================================
324 # USE the same .inc to cleanup before and after the test
325 --source suite/funcs_1/storedproc/cleanup_sp_tb.inc
327 # ==============================================================================
329 --echo . +++ END OF SCRIPT +++
330 --echo --------------------------------------------------------------------------------
331 # ==============================================================================