1 # suite/funcs_1/datadict/is_schemata.inc 
    3 # Check the layout of information_schema.schemata, permissions and the impact of 
    4 # CREATE/ALTER/DROP SCHEMA on it. 
    7 #    This test is not intended 
    8 #    - to show information about the all time existing databases 
    9 #      information_schema and mysql 
   10 #    - for checking storage engine properties 
   13 # 2008-01-23 mleich WL#4203 Reorganize and fix the data dictionary tests of 
   15 #                   Create this script based on older scripts and new code. 
   17 # 2008-06-11 mleich Move t/is_schemata.test to this file and 
   18 #                   create variants for embedded/non embedded server. 
   21 let $is_table = SCHEMATA;
 
   23 # The table INFORMATION_SCHEMA.SCHEMATA must exist 
   24 eval SHOW TABLES FROM information_schema LIKE 
'$is_table';
 
   26 --echo #######################################################################
 
   27 --echo # Testcase 3.2.1.1: INFORMATION_SCHEMA tables can be queried via SELECT
 
   28 --echo #######################################################################
 
   29 # Ensure that every INFORMATION_SCHEMA table can be queried with a SELECT 
   30 # statement, just as if it were an ordinary user-defined table. 
   32 --source suite/funcs_1/datadict/is_table_query.inc
 
   35 --echo #########################################################################
 
   36 --echo # Testcase 3.2.9.1: INFORMATION_SCHEMA.SCHEMATA layout;
 
   37 --echo #########################################################################
 
   38 # Ensure that the INFORMATION_SCHEMA.SCHEMATA table has the following columns, 
   39 # in the following order: 
   41 # CATALOG_NAME (always shows NULL), 
   42 # SCHEMA_NAME (shows the name of a database, or schema, on which the current 
   43 #        user or PUBLIC has privileges), 
   44 # DEFAULT_CHARACTER_SET_NAME (shows the name of that database's default 
   46 # DEFAULT_COLLATION_NAME (shows the database defaul collation) 
   47 # SQL_PATH (always shows NULL). 
   49 --source suite/funcs_1/datadict/datadict_bug_12777.inc
 
   50 eval DESCRIBE          information_schema.$is_table;
 
   51 --source suite/funcs_1/datadict/datadict_bug_12777.inc
 
   52 eval SHOW CREATE 
TABLE information_schema.$is_table;
 
   53 --source suite/funcs_1/datadict/datadict_bug_12777.inc
 
   54 eval SHOW COLUMNS FROM information_schema.$is_table;
 
   56 # Note: Retrieval of information within information_schema.columns about 
   57 #       information_schema.schemata is in is_columns_is.test. 
   59 # Show that CATALOG_NAME and SQL_PATH are always NULL. 
   60 SELECT catalog_name, schema_name, sql_path
 
   61 FROM information_schema.schemata
 
   62 WHERE catalog_name IS NOT NULL or sql_path IS NOT NULL;
 
   65 --echo ###############################################################################
 
   66 --echo # Testcases 3.2.9.2+3.2.9.3: INFORMATION_SCHEMA.SCHEMATA accessible information
 
   67 --echo ###############################################################################
 
   68 # 3.2.9.2 Ensure that the table shows the relevant information for every 
   69 #         database on which the current user or PUBLIC have privileges. 
   70 # 3.2.9.3 Ensure that the table does not show any information on any databases 
   71 #         on which the current user and PUBLIC have no privileges. 
   73 # Note: Check of content within information_schema.schemata about the databases 
   74 #       information_schema and mysql is in 
   75 #       suite/funcs_1/t/is_schemata_is_mysql.test. 
   78 DROP DATABASE IF EXISTS db_datadict_1;
 
   79 DROP DATABASE IF EXISTS db_datadict_2;
 
   81 CREATE DATABASE db_datadict_1;
 
   82 CREATE DATABASE db_datadict_2;
 
   84 --error 0,ER_CANNOT_USER
 
   85 DROP   USER 
'testuser1'@
'localhost';
 
   86 CREATE USER 
'testuser1'@
'localhost';
 
   87 --error 0,ER_CANNOT_USER
 
   88 DROP   USER 
'testuser2'@
'localhost';
 
   89 CREATE USER 
'testuser2'@
'localhost';
 
   90 --error 0,ER_CANNOT_USER
 
   91 DROP   USER 
'testuser3'@
'localhost';
 
   92 CREATE USER 
'testuser3'@
'localhost';
 
   94 GRANT SELECT ON db_datadict_1.* 
to 'testuser1'@
'localhost';
 
   95 GRANT SELECT ON db_datadict_1.* 
to 'testuser2'@
'localhost';
 
   96 GRANT SELECT ON db_datadict_2.* 
to 'testuser2'@
'localhost';
 
   98 let $my_select = SELECT * FROM information_schema.schemata
 
   99 WHERE schema_name LIKE 
'db_datadict_%' ORDER BY schema_name;
 
  100 let $my_show = SHOW DATABASES LIKE 
'db_datadict_%';
 
  106 --echo # Establish connection testuser1 (user=testuser1)
 
  107 --replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
 
  108 connect (testuser1, localhost, testuser1, , db_datadict_1);
 
  109 # Shows db_datadict_1 
  114 --echo # Establish connection testuser2 (user=testuser2)
 
  115 --replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
 
  116 connect (testuser2, localhost, testuser2, , db_datadict_2);
 
  117 # Shows db_datadict_1 and db_datadict_2 
  122 --echo # Establish connection testuser3 (user=testuser3)
 
  123 --replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
 
  124 connect (testuser3, localhost, testuser3, , 
test);
 
  125 # Shows neither db_datadict_1 nor db_datadict_2 
  131 --echo # Switch 
to connection 
default and close connections testuser1,testuser2,testuser3
 
  133 disconnect testuser1;
 
  134 disconnect testuser2;
 
  135 disconnect testuser3;
 
  136 DROP USER 
'testuser1'@
'localhost';
 
  137 DROP USER 
'testuser2'@
'localhost';
 
  138 DROP USER 
'testuser3'@
'localhost';
 
  139 DROP DATABASE db_datadict_1;
 
  140 DROP DATABASE db_datadict_2;
 
  143 --echo #################################################################################
 
  144 --echo # Testcases 3.2.1.13+3.2.1.14+3.2.1.15: INFORMATION_SCHEMA.SCHEMATA modifications
 
  145 --echo #################################################################################
 
  146 # 3.2.1.13: Ensure that the creation of any new database object (e.g. table or 
  147 #           column) automatically inserts all relevant information on that 
  148 #           object into every appropriate INFORMATION_SCHEMA table. 
  149 # 3.2.1.14: Ensure that the alteration of any existing database object 
  150 #           automatically updates all relevant information on that object in 
  151 #           every appropriate INFORMATION_SCHEMA table. 
  152 # 3.2.1.15: Ensure that the dropping of any existing database object 
  153 #           automatically deletes all relevant information on that object from 
  154 #           every appropriate INFORMATION_SCHEMA table. 
  157 DROP DATABASE IF EXISTS db_datadict;
 
  160 SELECT * FROM information_schema.schemata WHERE schema_name = 
'db_datadict';
 
  161 CREATE DATABASE db_datadict CHARACTER SET 
'latin1' COLLATE 
'latin1_swedish_ci';
 
  162 SELECT * FROM information_schema.schemata WHERE schema_name = 
'db_datadict';
 
  164 # Check modify default CHARACTER SET 
  165 SELECT schema_name, default_character_set_name
 
  166 FROM information_schema.schemata WHERE schema_name = 
'db_datadict';
 
  167 ALTER SCHEMA db_datadict CHARACTER SET 
'utf8';
 
  168 SELECT schema_name, default_character_set_name
 
  169 FROM information_schema.schemata WHERE schema_name = 
'db_datadict';
 
  170 ALTER SCHEMA db_datadict CHARACTER SET 
'latin1';
 
  172 # Check modify default COLLATION 
  173 SELECT schema_name, default_collation_name FROM information_schema.schemata
 
  174 WHERE schema_name = 
'db_datadict';
 
  175 ALTER SCHEMA db_datadict COLLATE 
'latin1_general_cs';
 
  176 SELECT schema_name, default_collation_name FROM information_schema.schemata
 
  177 WHERE schema_name = 
'db_datadict';
 
  179 # Check DROP DATABASE 
  181 FROM information_schema.schemata WHERE schema_name = 
'db_datadict';
 
  182 DROP DATABASE db_datadict;
 
  184 FROM information_schema.schemata WHERE schema_name = 
'db_datadict';
 
  187 --echo ########################################################################
 
  188 --echo # Testcases 3.2.1.3-3.2.1.5 + 3.2.1.8-3.2.1.12: INSERT/UPDATE/DELETE and
 
  189 --echo #           DDL on INFORMATION_SCHEMA tables are not supported
 
  190 --echo ########################################################################
 
  191 # 3.2.1.3:  Ensure that no user may execute an INSERT statement on any 
  192 #           INFORMATION_SCHEMA table. 
  193 # 3.2.1.4:  Ensure that no user may execute an UPDATE statement on any 
  194 #           INFORMATION_SCHEMA table. 
  195 # 3.2.1.5:  Ensure that no user may execute a DELETE statement on any 
  196 #           INFORMATION_SCHEMA table. 
  197 # 3.2.1.8:  Ensure that no user may create an index on an INFORMATION_SCHEMA table. 
  198 # 3.2.1.9:  Ensure that no user may alter the definition of an 
  199 #           INFORMATION_SCHEMA table. 
  200 # 3.2.1.10: Ensure that no user may drop an INFORMATION_SCHEMA table. 
  201 # 3.2.1.11: Ensure that no user may move an INFORMATION_SCHEMA table to any 
  203 # 3.2.1.12: Ensure that no user may directly add to, alter, or delete any data 
  204 #           in an INFORMATION_SCHEMA table. 
  207 DROP DATABASE IF EXISTS db_datadict;
 
  209 CREATE DATABASE db_datadict CHARACTER SET 
'latin1' COLLATE 
'latin1_swedish_ci';
 
  212 # 1. We can get here different error messages. 
  213 # 2. We do not want to unify the individual messages to the far to unspecific 
  214 #    'Got one of the listed errors'. 
  215 let $my_error_message =
 
  216 ##### The previous statement must fail ###### 
  217 # Server type  | expected error name      | expected error message 
  218 # -------------------------------------------------------------------------------------------------------------------- 
  219 # not embedded | ER_DBACCESS_DENIED_ERROR | ERROR 42000: Access denied for user 'root'@'localhost' to database 'information_schema' 
  220 # embedded     | ER_NON_INSERTABLE_TABLE  | ERROR HY000: The target table schemata of the INSERT is not insertable-into 
  221 #              | or similar               |              or similar 
  224 --disable_abort_on_error
 
  225 INSERT INTO information_schema.schemata
 
  226        (catalog_name, schema_name, default_character_set_name, sql_path)
 
  227 VALUES (NULL, 
'db1', 
'latin1', NULL);
 
  230    --echo $my_error_message
 
  233 INSERT INTO information_schema.schemata
 
  234 SELECT * FROM information_schema.schemata;
 
  237    --echo $my_error_message
 
  240 UPDATE information_schema.schemata
 
  241 SET default_character_set_name = 
'utf8' 
  242 WHERE schema_name = 
'db_datadict';
 
  245    --echo $my_error_message
 
  248 UPDATE information_schema.schemata SET catalog_name = 
't_4711';
 
  251    --echo $my_error_message
 
  254 DELETE FROM information_schema.schemata WHERE schema_name = 
'db_datadict';
 
  257    --echo $my_error_message
 
  260 TRUNCATE information_schema.schemata;
 
  263    --echo $my_error_message
 
  266 CREATE INDEX i1 ON information_schema.schemata(schema_name);
 
  269    --echo $my_error_message
 
  272 ALTER 
TABLE information_schema.schemata ADD f1 INT;
 
  275    --echo $my_error_message
 
  278 DROP 
TABLE information_schema.schemata;
 
  281    --echo $my_error_message
 
  284 ALTER 
TABLE information_schema.schemata RENAME db_datadict.schemata;
 
  287    --echo $my_error_message
 
  290 ALTER 
TABLE information_schema.schemata RENAME information_schema.xschemata;
 
  293    --echo $my_error_message
 
  296 --enable_abort_on_error
 
  299 DROP DATABASE db_datadict;