1 # suite/funcs_1/datadict/is_routines.inc
3 # Check the layout of information_schema.routines and the impact of
4 # CREATE/ALTER/DROP PROCEDURE/FUNCTION ... on it.
7 # This test is not intended
8 # - to show information about the all time existing routines (there are no
9 # in the moment) within the databases information_schema and mysql
10 # - for checking storage engine properties
11 # Therefore please do not alter $engine_type and $other_engine_type.
14 # 2008-01-23 mleich WL#4203 Reorganize and fix the data dictionary tests of
16 # Create this script based on older scripts and new code.
18 # 2008-06-11 mleich Move t/is_routines.test to this file and
19 # create variants for embedded/non embedded server.
22 let $engine_type = MEMORY;
23 let $other_engine_type = MyISAM;
25 let $is_table = ROUTINES;
27 # The table INFORMATION_SCHEMA.TABLES must exist
28 eval SHOW TABLES FROM information_schema LIKE
'$is_table';
30 --echo #######################################################################
31 --echo # Testcase 3.2.1.1: INFORMATION_SCHEMA tables can be queried via SELECT
32 --echo #######################################################################
33 # Ensure that every INFORMATION_SCHEMA table can be queried with a SELECT
34 # statement, just as if it were an ordinary user-defined table.
36 --source suite/funcs_1/datadict/is_table_query.inc
39 --echo #########################################################################
40 --echo # Testcase 3.2.8.1: INFORMATION_SCHEMA.ROUTINES layout
41 --echo #########################################################################
42 # Ensure that the INFORMATION_SCHEMA.ROUTINES table has the following columns,
43 # in the following order:
45 # SPECIFIC_NAME (shows the name of an accessible stored procedure, or routine),
46 # ROUTINE_CATALOG (always shows NULL),
47 # ROUTINE_SCHEMA (shows the database, or schema, in which the routine resides),
48 # ROUTINE_NAME (shows the same stored procedure name),
49 # ROUTINE_TYPE (shows whether the stored procedure is a procedure or a function),
50 # DTD_IDENTIFIER (shows, for a function, the complete data type definition of
51 # the value the function will return; otherwise NULL),
52 # ROUTINE_BODY (shows the language in which the stored procedure is written;
53 # currently always SQL),
54 # ROUTINE_DEFINITION (shows as much of the routine body as is possible in the
56 # EXTERNAL_NAME (always shows NULL),
57 # EXTERNAL_LANGUAGE (always shows NULL),
58 # PARAMETER_STYLE (shows the routine's parameter style; always SQL),
59 # IS_DETERMINISTIC (shows whether the routine is deterministic),
60 # SQL_DATA_ACCESS (shows the routine's defined sql-data-access clause value),
61 # SQL_PATH (always shows NULL),
62 # SECURITY_TYPE (shows whether the routine's defined security_type is 'definer'
64 # CREATED (shows the timestamp of the time the routine was created),
65 # LAST_ALTERED (shows the timestamp of the time the routine was last altered),
66 # SQL_MODE (shows the sql_mode setting at the time the routine was created),
67 # ROUTINE_COMMENT (shows the comment, if any, defined for the routine;
69 # DEFINER (shows the user who created the routine).
70 # Starting with MySQL 5.1
71 # CHARACTER_SET_CLIENT
72 # COLLATION_CONNECTION
75 --source suite/funcs_1/datadict/datadict_bug_12777.inc
76 eval DESCRIBE information_schema.$is_table;
77 --source suite/funcs_1/datadict/datadict_bug_12777.inc
78 eval SHOW CREATE
TABLE information_schema.$is_table;
79 --source suite/funcs_1/datadict/datadict_bug_12777.inc
80 eval SHOW COLUMNS FROM information_schema.$is_table;
84 DROP PROCEDURE IF EXISTS sp_for_routines;
85 DROP FUNCTION IF EXISTS function_for_routines;
87 CREATE PROCEDURE sp_for_routines() SELECT 'db_datadict';
88 CREATE FUNCTION function_for_routines() RETURNS INT RETURN 0;
90 # Show that the column values of
91 # ROUTINE_CATALOG, EXTERNAL_NAME, EXTERNAL_LANGUAGE, SQL_PATH are always NULL
93 # ROUTINE_BODY, PARAMETER_STYLE are 'SQL'
95 # SPECIFIC_NAME = ROUTINE_NAME.
96 SELECT specific_name,routine_catalog,routine_schema,routine_name,routine_type,
97 routine_body,external_name,external_language,parameter_style,sql_path
98 FROM information_schema.routines
99 WHERE routine_schema =
'test' AND
100 (routine_catalog IS NOT NULL OR external_name IS NOT NULL
101 OR external_language IS NOT NULL OR sql_path IS NOT NULL
102 OR routine_body <>
'SQL' OR parameter_style <>
'SQL'
103 OR specific_name <> routine_name);
105 DROP PROCEDURE sp_for_routines;
106 DROP FUNCTION function_for_routines;
109 --echo ################################################################################
110 --echo # Testcase 3.2.8.2 + 3.2.8.3: INFORMATION_SCHEMA.ROUTINES accessible information
111 --echo ################################################################################
112 # 3.2.8.2: Ensure that the table shows the relevant information on every SQL-invoked
113 # routine (i.e. stored procedure) which is accessible to the current user
115 # 3.2.8.3: Ensure that the table does not show any information on any stored procedure
116 # that is not accessible to the current user or PUBLIC.
119 DROP DATABASE IF EXISTS db_datadict;
120 DROP DATABASE IF EXISTS db_datadict_2;
123 CREATE DATABASE db_datadict;
125 --replace_result $other_engine_type <other_engine_type>
127 CREATE
TABLE res_6_408002_1(f1 CHAR(3), f2 TEXT(25), f3 DATE, f4 INT)
128 ENGINE = $other_engine_type;
129 INSERT INTO res_6_408002_1(f1, f2, f3, f4)
130 VALUES('abc', 'xyz', '1989-11-09', 0815);
132 DROP PROCEDURE IF EXISTS sp_6_408002_1;
135 CREATE PROCEDURE sp_6_408002_1()
137 SELECT * FROM db_datadict.res_6_408002_1;
141 CREATE DATABASE db_datadict_2;
143 --replace_result $other_engine_type <other_engine_type>
145 CREATE
TABLE res_6_408002_2(f1 CHAR(3), f2 TEXT(25), f3 DATE, f4 INT)
146 ENGINE = $other_engine_type;
147 INSERT INTO res_6_408002_2(f1, f2, f3, f4)
148 VALUES('abc', 'xyz', '1990-10-03', 4711);
150 DROP PROCEDURE IF EXISTS sp_6_408002_2;
153 CREATE PROCEDURE sp_6_408002_2()
155 SELECT * FROM db_datadict_2.res_6_408002_2;
159 --error 0,ER_CANNOT_USER
160 DROP USER 'testuser1'@'localhost';
161 CREATE USER 'testuser1'@'localhost';
162 --error 0,ER_CANNOT_USER
163 DROP USER 'testuser2'@'localhost';
164 CREATE USER 'testuser2'@'localhost';
165 --error 0,ER_CANNOT_USER
166 DROP USER 'testuser3'@'localhost';
167 CREATE USER 'testuser3'@'localhost';
170 GRANT SELECT ON db_datadict_2.* TO 'testuser1'@'localhost';
171 GRANT EXECUTE ON db_datadict_2.* TO 'testuser1'@'localhost';
173 GRANT EXECUTE ON db_datadict.* TO 'testuser1'@'localhost';
174 GRANT SELECT ON db_datadict.* TO 'testuser2'@'localhost';
176 GRANT EXECUTE ON PROCEDURE db_datadict_2.sp_6_408002_2
177 TO 'testuser2'@'localhost';
178 GRANT EXECUTE ON db_datadict_2.* TO 'testuser2'@'localhost';
181 --echo
# Establish connection testuser1 (user=testuser1)
182 --replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
183 connect (testuser1, localhost, testuser1, , db_datadict);
184 --replace_column 24
"YYYY-MM-DD hh:mm:ss" 25
"YYYY-MM-DD hh:mm:ss"
185 SELECT * FROM information_schema.routines;
187 --echo # Establish connection testuser2 (user=testuser2)
188 --replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
189 connect (testuser2, localhost, testuser2, , db_datadict);
190 --replace_column 24
"YYYY-MM-DD hh:mm:ss" 25
"YYYY-MM-DD hh:mm:ss"
191 SELECT * FROM information_schema.routines;
193 --echo # Establish connection testuser3 (user=testuser3)
194 --replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
195 connect (testuser3, localhost, testuser3, ,
test);
196 --replace_column 24
"YYYY-MM-DD hh:mm:ss" 25
"YYYY-MM-DD hh:mm:ss"
197 SELECT * FROM information_schema.routines;
200 --echo # Switch
to connection
default and close connections testuser1,testuser2,testuser3
202 disconnect testuser1;
203 disconnect testuser2;
204 disconnect testuser3;
206 DROP USER
'testuser1'@
'localhost';
207 DROP USER
'testuser2'@
'localhost';
208 DROP USER
'testuser3'@
'localhost';
211 DROP DATABASE db_datadict;
212 DROP DATABASE db_datadict_2;
215 --echo #########################################################################
216 --echo # 3.2.1.13+3.2.1.14+3.2.1.15: INFORMATION_SCHEMA.ROUTINES modifications
217 --echo #########################################################################
218 # 3.2.1.13: Ensure that the creation of any new database object (e.g. table or
219 # column) automatically inserts all relevant information on that
220 # object into every appropriate INFORMATION_SCHEMA table.
221 # 3.2.1.14: Ensure that the alteration of any existing database object
222 # automatically updates all relevant information on that object in
223 # every appropriate INFORMATION_SCHEMA table.
224 # 3.2.1.15: Ensure that the dropping of any existing database object
225 # automatically deletes all relevant information on that object from
226 # every appropriate INFORMATION_SCHEMA table.
228 # Some more tests are in t/information_schema_routines.test which exists
229 # in MySQL 5.1 and up only.
232 DROP DATABASE IF EXISTS db_datadict;
234 CREATE DATABASE db_datadict;
236 SELECT * FROM information_schema.routines WHERE routine_schema =
'db_datadict';
238 CREATE PROCEDURE sp_for_routines() SELECT 'db_datadict';
239 CREATE FUNCTION function_for_routines() RETURNS INT RETURN 0;
241 --replace_column 24 <created> 25 <modified>
242 SELECT * FROM information_schema.routines WHERE routine_schema = 'db_datadict'
243 ORDER BY routine_name;
246 ALTER PROCEDURE sp_for_routines SQL SECURITY INVOKER;
247 ALTER FUNCTION function_for_routines COMMENT 'updated comments';
249 --replace_column 24 <created> 25 <modified>
250 SELECT * FROM information_schema.routines WHERE routine_schema = 'db_datadict'
251 ORDER BY routine_name;
254 DROP PROCEDURE sp_for_routines;
255 DROP FUNCTION function_for_routines;
256 SELECT * FROM information_schema.routines WHERE routine_schema = 'db_datadict';
258 CREATE PROCEDURE sp_for_routines() SELECT 'db_datadict';
259 CREATE FUNCTION function_for_routines() RETURNS INT RETURN 0;
261 --replace_column 24 <created> 25 <modified>
262 SELECT * FROM information_schema.routines WHERE routine_schema = 'db_datadict'
263 ORDER BY routine_name;
266 DROP DATABASE db_datadict;
267 SELECT * FROM information_schema.routines WHERE routine_schema = 'db_datadict';
270 --echo
#########################################################################
271 --echo # 3.2.8.4: INFORMATION_SCHEMA.ROUTINES routine body too big
for
272 --echo # ROUTINE_DEFINITION column
273 --echo #########################################################################
274 # Ensure that a stored procedure with a routine body that is too large to fit
275 # into the INFORMATION_SCHEMA.ROUTINES.ROUTINE_DEFINITION column correctly shows
276 # as much of the information as is possible within the allotted size.
279 DROP DATABASE IF EXISTS db_datadict;
281 CREATE DATABASE db_datadict;
284 --replace_result $other_engine_type <other_engine_type>
286 CREATE
TABLE db_datadict.res_6_408004_1
287 (f1 LONGTEXT , f2 MEDIUMINT , f3 LONGBLOB , f4 REAL , f5 YEAR)
288 ENGINE = $other_engine_type;
289 INSERT INTO db_datadict.res_6_408004_1
290 VALUES (
'abc', 98765 , 99999999 , 98765, 10);
292 --replace_result $other_engine_type <other_engine_type>
294 CREATE
TABLE db_datadict.res_6_408004_2
295 (f1 LONGTEXT , f2 MEDIUMINT , f3 LONGBLOB , f4 REAL , f5 YEAR)
296 ENGINE = $other_engine_type;
297 INSERT INTO db_datadict.res_6_408004_2
298 VALUES (
'abc', 98765 , 99999999 , 98765, 10);
300 --echo # Checking the max. possible length of (currently) 4 GByte is not
301 --echo # in
this environment here.
304 CREATE PROCEDURE sp_6_408004 ()
306 DECLARE done INTEGER DEFAULt 0;
307 DECLARE variable_number_1 LONGTEXT;
308 DECLARE variable_number_2 MEDIUMINT;
309 DECLARE variable_number_3 LONGBLOB;
310 DECLARE variable_number_4 REAL;
311 DECLARE variable_number_5 YEAR;
312 DECLARE cursor_number_1
CURSOR FOR SELECT * FROM res_6_408004_1 LIMIT 0, 10;
313 DECLARE cursor_number_2
CURSOR FOR SELECT * FROM res_6_408004_1 LIMIT 0, 10;
314 DECLARE cursor_number_3
CURSOR FOR SELECT * FROM res_6_408004_1 LIMIT 0, 10;
315 DECLARE cursor_number_4
CURSOR FOR SELECT * FROM res_6_408004_1 LIMIT 0, 10;
316 DECLARE cursor_number_5
CURSOR FOR SELECT * FROM res_6_408004_1 LIMIT 0, 10;
317 DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
319 OPEN cursor_number_1;
321 FETCH cursor_number_1
322 INTO variable_number_1, variable_number_2, variable_number_3,
323 variable_number_4, variable_number_5;
325 INSERT INTO res_6_408004_2
326 VALUES (variable_number_1, variable_number_2, variable_number_3,
327 variable_number_4, variable_number_5);
333 OPEN cursor_number_2;
335 FETCH cursor_number_2
336 INTO variable_number_1, variable_number_2, variable_number_3,
337 variable_number_4, variable_number_5;
339 INSERT INTO res_6_408004_2
340 VALUES(variable_number_1, variable_number_2, variable_number_3,
341 variable_number_4, variable_number_5);
346 OPEN cursor_number_3;
348 FETCH cursor_number_3
349 INTO variable_number_1, variable_number_2, variable_number_3,
350 variable_number_4, variable_number_5;
352 INSERT INTO res_6_408004_2
353 VALUES(variable_number_1, variable_number_2, variable_number_3,
354 variable_number_4, variable_number_5);
361 OPEN cursor_number_4;
363 FETCH cursor_number_4
364 INTO variable_number_1, variable_number_2, variable_number_3,
365 variable_number_4, variable_number_5;
367 INSERT INTO res_6_408004_2
368 VALUES (variable_number_1, variable_number_2, variable_number_3,
369 variable_number_4, variable_number_5);
381 OPEN cursor_number_5;
383 FETCH cursor_number_5
384 INTO variable_number_1, variable_number_2, variable_number_3,
385 variable_number_4, variable_number_5;
387 INSERT INTO res_6_408004_2
388 VALUES (variable_number_1, variable_number_2, variable_number_3,
389 variable_number_4, variable_number_5);
402 CALL db_datadict.sp_6_408004 ();
403 SELECT * FROM db_datadict.res_6_408004_2;
406 --replace_column 24 "YYYY-MM-DD hh:mm:ss" 25 "YYYY-MM-DD hh:mm:ss"
407 SELECT *, LENGTH(routine_definition) FROM information_schema.routines
408 WHERE routine_schema = 'db_datadict';
412 DROP DATABASE db_datadict;
413 # ----------------------------------------------------------------------------------------------
416 --echo ########################################################################
417 --echo # Testcases 3.2.1.3-3.2.1.5 + 3.2.1.8-3.2.1.12: INSERT/UPDATE/DELETE and
418 --echo # DDL on INFORMATION_SCHEMA
table are not supported
419 --echo ########################################################################
420 # 3.2.1.3: Ensure that no user may execute an INSERT statement on any
421 # INFORMATION_SCHEMA table.
422 # 3.2.1.4: Ensure that no user may execute an UPDATE statement on any
423 # INFORMATION_SCHEMA table.
424 # 3.2.1.5: Ensure that no user may execute a DELETE statement on any
425 # INFORMATION_SCHEMA table.
426 # 3.2.1.8: Ensure that no user may create an index on an INFORMATION_SCHEMA table.
427 # 3.2.1.9: Ensure that no user may alter the definition of an
428 # INFORMATION_SCHEMA table.
429 # 3.2.1.10: Ensure that no user may drop an INFORMATION_SCHEMA table.
430 # 3.2.1.11: Ensure that no user may move an INFORMATION_SCHEMA table to any
432 # 3.2.1.12: Ensure that no user may directly add to, alter, or delete any data
433 # in an INFORMATION_SCHEMA table.
436 DROP DATABASE IF EXISTS db_datadict;
438 CREATE DATABASE db_datadict;
440 CREATE PROCEDURE sp_for_routines() SELECT 'db_datadict';
444 # 1. We can get here different error messages.
445 # 2. We do not want to unify the individual messages to the far to unspecific
446 # 'Got one of the listed errors'.
447 let $my_error_message =
448 ##### The previous statement must fail ######
449 # Server type | expected error name | expected error message
450 # --------------------------------------------------------------------------------------------------------------------
451 # not embedded | ER_DBACCESS_DENIED_ERROR | ERROR 42000: Access denied for user 'root'@'localhost' to database 'information_schema'
452 # embedded | ER_NON_INSERTABLE_TABLE | ERROR HY000: The target table schemata of the INSERT is not insertable-into
453 # | or similar | or similar
456 --disable_abort_on_error
457 INSERT INTO information_schema.routines (routine_name, routine_type )
458 VALUES (
'p2',
'procedure');
461 --echo $my_error_message
464 UPDATE information_schema.routines SET routine_name =
'p2'
465 WHERE routine_body =
'sql';
468 --echo $my_error_message
471 DELETE FROM information_schema.routines ;
474 --echo $my_error_message
477 TRUNCATE information_schema.routines ;
480 --echo $my_error_message
483 CREATE INDEX i7 ON information_schema.routines (routine_name);
486 --echo $my_error_message
489 ALTER
TABLE information_schema.routines ADD f1 INT;
492 --echo $my_error_message
495 ALTER
TABLE information_schema.routines DISCARD TABLESPACE;
498 --echo $my_error_message
501 DROP
TABLE information_schema.routines ;
504 --echo $my_error_message
507 ALTER
TABLE information_schema.routines RENAME db_datadict.routines;
510 --echo $my_error_message
513 ALTER
TABLE information_schema.routines RENAME information_schema.xroutines;
516 --echo $my_error_message
519 --enable_abort_on_error
522 DROP DATABASE db_datadict;