Debian Codegraph @

mysql-test/suite/funcs_1/datadict/is_schemata.inc

raw
1 # suite/funcs_1/datadict/is_schemata.inc
2 #
3 # Check the layout of information_schema.schemata, permissions and the impact of
4 # CREATE/ALTER/DROP SCHEMA on it.
5 #
6 # Note:
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
11 #
12 # Author:
13 # 2008-01-23 mleich WL#4203 Reorganize and fix the data dictionary tests of
14 # testsuite funcs_1
15 # Create this script based on older scripts and new code.
16 # Last Change:
17 # 2008-06-11 mleich Move t/is_schemata.test to this file and
18 # create variants for embedded/non embedded server.
19 #
20
21 --source include/default_charset.inc
22 let $is_table = SCHEMATA;
23
24 # The table INFORMATION_SCHEMA.SCHEMATA must exist
25 eval SHOW TABLES FROM information_schema LIKE '$is_table';
26
27 --echo #######################################################################
28 --echo # Testcase 3.2.1.1: INFORMATION_SCHEMA tables can be queried via SELECT
29 --echo #######################################################################
30 # Ensure that every INFORMATION_SCHEMA table can be queried with a SELECT
31 # statement, just as if it were an ordinary user-defined table.
32 #
33 --source suite/funcs_1/datadict/is_table_query.inc
34
35
36 --echo #########################################################################
37 --echo # Testcase 3.2.9.1: INFORMATION_SCHEMA.SCHEMATA layout;
38 --echo #########################################################################
39 # Ensure that the INFORMATION_SCHEMA.SCHEMATA table has the following columns,
40 # in the following order:
41 #
42 # CATALOG_NAME (always shows NULL),
43 # SCHEMA_NAME (shows the name of a database, or schema, on which the current
44 # user or PUBLIC has privileges),
45 # DEFAULT_CHARACTER_SET_NAME (shows the name of that database's default
46 # character set),
47 # DEFAULT_COLLATION_NAME (shows the database defaul collation)
48 # SQL_PATH (always shows NULL).
49 #
50 --source suite/funcs_1/datadict/datadict_bug_12777.inc
51 eval DESCRIBE information_schema.$is_table;
52 --source suite/funcs_1/datadict/datadict_bug_12777.inc
53 eval SHOW CREATE TABLE information_schema.$is_table;
54 --source suite/funcs_1/datadict/datadict_bug_12777.inc
55 eval SHOW COLUMNS FROM information_schema.$is_table;
56
57 # Note: Retrieval of information within information_schema.columns about
58 # information_schema.schemata is in is_columns_is.test.
59
60 # Show that CATALOG_NAME and SQL_PATH are always NULL.
61 SELECT catalog_name, schema_name, sql_path
62 FROM information_schema.schemata
63 WHERE catalog_name IS NOT NULL or sql_path IS NOT NULL
64 ORDER BY schema_name;
65
66
67 --echo ###############################################################################
68 --echo # Testcases 3.2.9.2+3.2.9.3: INFORMATION_SCHEMA.SCHEMATA accessible information
69 --echo ###############################################################################
70 # 3.2.9.2 Ensure that the table shows the relevant information for every
71 # database on which the current user or PUBLIC have privileges.
72 # 3.2.9.3 Ensure that the table does not show any information on any databases
73 # on which the current user and PUBLIC have no privileges.
74 #
75 # Note: Check of content within information_schema.schemata about the databases
76 # information_schema and mysql is in
77 # suite/funcs_1/t/is_schemata_is_mysql.test.
78 #
79 --disable_warnings
80 DROP DATABASE IF EXISTS db_datadict_1;
81 DROP DATABASE IF EXISTS db_datadict_2;
82 --enable_warnings
83 CREATE DATABASE db_datadict_1;
84 CREATE DATABASE db_datadict_2;
85
86 --error 0,ER_CANNOT_USER
87 DROP USER 'testuser1'@'localhost';
88 CREATE USER 'testuser1'@'localhost';
89 --error 0,ER_CANNOT_USER
90 DROP USER 'testuser2'@'localhost';
91 CREATE USER 'testuser2'@'localhost';
92 --error 0,ER_CANNOT_USER
93 DROP USER 'testuser3'@'localhost';
94 CREATE USER 'testuser3'@'localhost';
95
96 GRANT SELECT ON db_datadict_1.* to 'testuser1'@'localhost';
97 GRANT SELECT ON db_datadict_1.* to 'testuser2'@'localhost';
98 GRANT SELECT ON db_datadict_2.* to 'testuser2'@'localhost';
99
100 let $my_select = SELECT * FROM information_schema.schemata
101 WHERE schema_name LIKE 'db_datadict_%' ORDER BY schema_name;
102 let $my_show = SHOW DATABASES LIKE 'db_datadict_%';
103
104 eval $my_select;
105 --sorted_result
106 eval $my_show;
107
108 --replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
109 connect (testuser1, localhost, testuser1, , db_datadict_1);
110 # Shows db_datadict_1
111 eval $my_select;
112 --sorted_result
113 eval $my_show;
114
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
118 eval $my_select;
119 --sorted_result
120 eval $my_show;
121
122 --replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
123 connect (testuser3, localhost, testuser3, ,"*NO-ONE*");
124 # Shows neither db_datadict_1 nor db_datadict_2
125 eval $my_select;
126 --sorted_result
127 eval $my_show;
128
129 # Cleanup
130 connection default;
131 disconnect testuser1;
132 disconnect testuser2;
133 disconnect testuser3;
134 DROP USER 'testuser1'@'localhost';
135 DROP USER 'testuser2'@'localhost';
136 DROP USER 'testuser3'@'localhost';
137 DROP DATABASE db_datadict_1;
138 DROP DATABASE db_datadict_2;
139
140
141 --echo #################################################################################
142 --echo # Testcases 3.2.1.13+3.2.1.14+3.2.1.15: INFORMATION_SCHEMA.SCHEMATA modifications
143 --echo #################################################################################
144 # 3.2.1.13: Ensure that the creation of any new database object (e.g. table or
145 # column) automatically inserts all relevant information on that
146 # object into every appropriate INFORMATION_SCHEMA table.
147 # 3.2.1.14: Ensure that the alteration of any existing database object
148 # automatically updates all relevant information on that object in
149 # every appropriate INFORMATION_SCHEMA table.
150 # 3.2.1.15: Ensure that the dropping of any existing database object
151 # automatically deletes all relevant information on that object from
152 # every appropriate INFORMATION_SCHEMA table.
153 #
154 --disable_warnings
155 DROP DATABASE IF EXISTS db_datadict;
156 --enable_warnings
157
158 SELECT * FROM information_schema.schemata WHERE schema_name = 'db_datadict';
159 CREATE DATABASE db_datadict CHARACTER SET 'latin1' COLLATE 'latin1_swedish_ci';
160 SELECT * FROM information_schema.schemata WHERE schema_name = 'db_datadict';
161
162 # Check modify default CHARACTER SET
163 SELECT schema_name, default_character_set_name
164 FROM information_schema.schemata WHERE schema_name = 'db_datadict';
165 ALTER SCHEMA db_datadict CHARACTER SET 'utf8';
166 SELECT schema_name, default_character_set_name
167 FROM information_schema.schemata WHERE schema_name = 'db_datadict';
168 ALTER SCHEMA db_datadict CHARACTER SET 'latin1';
169
170 # Check modify default COLLATION
171 SELECT schema_name, default_collation_name FROM information_schema.schemata
172 WHERE schema_name = 'db_datadict';
173 ALTER SCHEMA db_datadict COLLATE 'latin1_general_cs';
174 SELECT schema_name, default_collation_name FROM information_schema.schemata
175 WHERE schema_name = 'db_datadict';
176
177 # Check DROP DATABASE
178 SELECT schema_name
179 FROM information_schema.schemata WHERE schema_name = 'db_datadict';
180 DROP DATABASE db_datadict;
181 SELECT schema_name
182 FROM information_schema.schemata WHERE schema_name = 'db_datadict';
183
184
185 --echo ########################################################################
186 --echo # Testcases 3.2.1.3-3.2.1.5 + 3.2.1.8-3.2.1.12: INSERT/UPDATE/DELETE and
187 --echo # DDL on INFORMATION_SCHEMA tables are not supported
188 --echo ########################################################################
189 # 3.2.1.3: Ensure that no user may execute an INSERT statement on any
190 # INFORMATION_SCHEMA table.
191 # 3.2.1.4: Ensure that no user may execute an UPDATE statement on any
192 # INFORMATION_SCHEMA table.
193 # 3.2.1.5: Ensure that no user may execute a DELETE statement on any
194 # INFORMATION_SCHEMA table.
195 # 3.2.1.8: Ensure that no user may create an index on an INFORMATION_SCHEMA table.
196 # 3.2.1.9: Ensure that no user may alter the definition of an
197 # INFORMATION_SCHEMA table.
198 # 3.2.1.10: Ensure that no user may drop an INFORMATION_SCHEMA table.
199 # 3.2.1.11: Ensure that no user may move an INFORMATION_SCHEMA table to any
200 # other database.
201 # 3.2.1.12: Ensure that no user may directly add to, alter, or delete any data
202 # in an INFORMATION_SCHEMA table.
203 #
204 --disable_warnings
205 DROP DATABASE IF EXISTS db_datadict;
206 --enable_warnings
207 CREATE DATABASE db_datadict CHARACTER SET 'latin1' COLLATE 'latin1_swedish_ci';
208
209 # Note(mleich):
210 # 1. We can get here different error messages.
211 # 2. We do not want to unify the individual messages to the far to unspecific
212 # 'Got one of the listed errors'.
213 let $my_error_message =
214 ##### The previous statement must fail ######
215 # Server type | expected error name | expected error message
216 # --------------------------------------------------------------------------------------------------------------------
217 # not embedded | ER_DBACCESS_DENIED_ERROR | ERROR 42000: Access denied for user 'root'@'localhost' to database 'information_schema'
218 # embedded | ER_NON_INSERTABLE_TABLE | ERROR HY000: The target table schemata of the INSERT is not insertable-into
219 # | or similar | or similar
220 ;
221
222 --disable_abort_on_error
223 INSERT INTO information_schema.schemata
224 (catalog_name, schema_name, default_character_set_name, sql_path)
225 VALUES (NULL, 'db1', 'latin1', NULL);
226 if (!$mysql_errno)
227 {
228 --echo $my_error_message
229 exit;
230 }
231 INSERT INTO information_schema.schemata
232 SELECT * FROM information_schema.schemata;
233 if (!$mysql_errno)
234 {
235 --echo $my_error_message
236 exit;
237 }
238 UPDATE information_schema.schemata
239 SET default_character_set_name = 'utf8'
240 WHERE schema_name = 'db_datadict';
241 if (!$mysql_errno)
242 {
243 --echo $my_error_message
244 exit;
245 }
246 UPDATE information_schema.schemata SET catalog_name = 't_4711';
247 if (!$mysql_errno)
248 {
249 --echo $my_error_message
250 exit;
251 }
252 DELETE FROM information_schema.schemata WHERE schema_name = 'db_datadict';
253 if (!$mysql_errno)
254 {
255 --echo $my_error_message
256 exit;
257 }
258 TRUNCATE information_schema.schemata;
259 if (!$mysql_errno)
260 {
261 --echo $my_error_message
262 exit;
263 }
264 CREATE INDEX i1 ON information_schema.schemata(schema_name);
265 if (!$mysql_errno)
266 {
267 --echo $my_error_message
268 exit;
269 }
270 ALTER TABLE information_schema.schemata ADD f1 INT;
271 if (!$mysql_errno)
272 {
273 --echo $my_error_message
274 exit;
275 }
276 DROP TABLE information_schema.schemata;
277 if (!$mysql_errno)
278 {
279 --echo $my_error_message
280 exit;
281 }
282 ALTER TABLE information_schema.schemata RENAME db_datadict.schemata;
283 if (!$mysql_errno)
284 {
285 --echo $my_error_message
286 exit;
287 }
288 ALTER TABLE information_schema.schemata RENAME information_schema.xschemata;
289 if (!$mysql_errno)
290 {
291 --echo $my_error_message
292 exit;
293 }
294 --enable_abort_on_error
295
296 # Cleanup
297 DROP DATABASE db_datadict;
298