| 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 |
# |
| 19 |
|
| 20 |
let $is_table = SCHEMATA; |
| 21 |
|
| 22 |
# The table INFORMATION_SCHEMA.SCHEMATA must exist |
| 23 |
eval SHOW TABLES FROM information_schema LIKE '$is_table'; |
| 24 |
|
| 25 |
--echo ####################################################################### |
| 26 |
--echo # Testcase 3.2.1.1: INFORMATION_SCHEMA tables can be queried via SELECT |
| 27 |
--echo ####################################################################### |
| 28 |
# Ensure that every INFORMATION_SCHEMA table can be queried with a SELECT |
| 29 |
# statement, just as if it were an ordinary user-defined table. |
| 30 |
# |
| 31 |
--source suite/funcs_1/datadict/is_table_query.inc |
| 32 |
|
| 33 |
|
| 34 |
--echo ######################################################################### |
| 35 |
--echo # Testcase 3.2.9.1: INFORMATION_SCHEMA.SCHEMATA layout; |
| 36 |
--echo ######################################################################### |
| 37 |
# Ensure that the INFORMATION_SCHEMA.SCHEMATA table has the following columns, |
| 38 |
# in the following order: |
| 39 |
# |
| 40 |
# CATALOG_NAME (always shows NULL), |
| 41 |
# SCHEMA_NAME (shows the name of a database, or schema, on which the current |
| 42 |
# user or PUBLIC has privileges), |
| 43 |
# DEFAULT_CHARACTER_SET_NAME (shows the name of that database's default |
| 44 |
# character set), |
| 45 |
# DEFAULT_COLLATION_NAME (shows the database defaul collation) |
| 46 |
# SQL_PATH (always shows NULL). |
| 47 |
# |
| 48 |
--source suite/funcs_1/datadict/datadict_bug_12777.inc |
| 49 |
eval DESCRIBE information_schema.$is_table; |
| 50 |
--source suite/funcs_1/datadict/datadict_bug_12777.inc |
| 51 |
eval SHOW CREATE TABLE information_schema.$is_table; |
| 52 |
--source suite/funcs_1/datadict/datadict_bug_12777.inc |
| 53 |
eval SHOW COLUMNS FROM information_schema.$is_table; |
| 54 |
|
| 55 |
# Note: Retrieval of information within information_schema.columns about |
| 56 |
# information_schema.schemata is in is_columns_is.test. |
| 57 |
|
| 58 |
# Show that CATALOG_NAME and SQL_PATH are always NULL. |
| 59 |
SELECT catalog_name, schema_name, sql_path |
| 60 |
FROM information_schema.schemata |
| 61 |
WHERE catalog_name IS NOT NULL or sql_path IS NOT NULL |
| 62 |
ORDER BY schema_name; |
| 63 |
|
| 64 |
|
| 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. |
| 72 |
# |
| 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. |
| 76 |
# |
| 77 |
--disable_warnings |
| 78 |
DROP DATABASE IF EXISTS db_datadict_1; |
| 79 |
DROP DATABASE IF EXISTS db_datadict_2; |
| 80 |
--enable_warnings |
| 81 |
CREATE DATABASE db_datadict_1 charset latin1; |
| 82 |
CREATE DATABASE db_datadict_2 charset latin1; |
| 83 |
|
| 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'; |
| 93 |
|
| 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'; |
| 97 |
|
| 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_%'; |
| 101 |
|
| 102 |
eval $my_select; |
| 103 |
--sorted_result |
| 104 |
eval $my_show; |
| 105 |
|
| 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 |
| 110 |
eval $my_select; |
| 111 |
--sorted_result |
| 112 |
eval $my_show; |
| 113 |
|
| 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 |
| 118 |
eval $my_select; |
| 119 |
--sorted_result |
| 120 |
eval $my_show; |
| 121 |
|
| 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 |
| 126 |
eval $my_select; |
| 127 |
--sorted_result |
| 128 |
eval $my_show; |
| 129 |
|
| 130 |
# Cleanup |
| 131 |
--echo # Switch to connection default and close connections testuser1,testuser2,testuser3 |
| 132 |
connection default; |
| 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; |
| 141 |
|
| 142 |
|
| 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. |
| 155 |
# |
| 156 |
--disable_warnings |
| 157 |
DROP DATABASE IF EXISTS db_datadict; |
| 158 |
--enable_warnings |
| 159 |
|
| 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'; |
| 163 |
|
| 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'; |
| 171 |
|
| 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'; |
| 178 |
|
| 179 |
# Check DROP DATABASE |
| 180 |
SELECT schema_name |
| 181 |
FROM information_schema.schemata WHERE schema_name = 'db_datadict'; |
| 182 |
DROP DATABASE db_datadict; |
| 183 |
SELECT schema_name |
| 184 |
FROM information_schema.schemata WHERE schema_name = 'db_datadict'; |
| 185 |
|
| 186 |
|
| 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 |
| 202 |
# other database. |
| 203 |
# 3.2.1.12: Ensure that no user may directly add to, alter, or delete any data |
| 204 |
# in an INFORMATION_SCHEMA table. |
| 205 |
# |
| 206 |
--disable_warnings |
| 207 |
DROP DATABASE IF EXISTS db_datadict; |
| 208 |
--enable_warnings |
| 209 |
CREATE DATABASE db_datadict CHARACTER SET 'latin1' COLLATE 'latin1_swedish_ci'; |
| 210 |
|
| 211 |
# Note(mleich): |
| 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 |
# MySQL | ER_DBACCESS_DENIED_ERROR | ERROR 42000: Access denied for user 'root'@'localhost' to database 'information_schema' |
| 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 |
|