| 1 |
# suite/funcs_1/datadict/is_views.inc |
| 2 |
# |
| 3 |
# Check the layout of information_schema.views and the impact of |
| 4 |
# CREATE/ALTER/DROP TABLE/VIEW/SCHEMA ... on it. |
| 5 |
# |
| 6 |
# Note: |
| 7 |
# - This test should not check storage engine properties. |
| 8 |
# - Please do not change the storage engines used within this test |
| 9 |
# except you know that the impact is acceptable. |
| 10 |
# Some storage engines might not support the modification of |
| 11 |
# properties like in the following tests. |
| 12 |
# |
| 13 |
# Author: |
| 14 |
# 2008-01-23 mleich WL#4203 Reorganize and fix the data dictionary tests of |
| 15 |
# testsuite funcs_1 |
| 16 |
# Create this script based on older scripts and new code. |
| 17 |
# Last Change: |
| 18 |
# 2008-06-11 mleich Move t/is_views.test to this file and |
| 19 |
# |
| 20 |
|
| 21 |
let $is_table = VIEWS; |
| 22 |
|
| 23 |
# The table INFORMATION_SCHEMA.VIEWS must exist |
| 24 |
eval SHOW TABLES FROM information_schema LIKE '$is_table'; |
| 25 |
|
| 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. |
| 31 |
# |
| 32 |
--source suite/funcs_1/datadict/is_table_query.inc |
| 33 |
|
| 34 |
|
| 35 |
--echo ######################################################################### |
| 36 |
--echo # Testcase 3.2.13.1: INFORMATION_SCHEMA.VIEWS layout |
| 37 |
--echo ######################################################################### |
| 38 |
# Ensure that the INFORMATION_SCHEMA.VIEWS table has the following columns, |
| 39 |
# in the following order: |
| 40 |
# |
| 41 |
# TABLE_CATALOG (always shows NULL), |
| 42 |
# TABLE_SCHEMA (shows the database, or schema, in which an accessible |
| 43 |
# view resides), |
| 44 |
# TABLE_NAME (shows the name of a view accessible to the current user), |
| 45 |
# VIEW_DEFINITION (shows the SELECT statement that makes up the |
| 46 |
# view's definition), |
| 47 |
# CHECK_OPTION (shows the value of the WITH CHECK OPTION clause used to define |
| 48 |
# the view, either NONE, LOCAL or CASCADED), |
| 49 |
# IS_UPDATABLE (shows whether the view is an updatable view), |
| 50 |
# DEFINER (added with 5.0.14), |
| 51 |
# SECURITY_TYPE (added with 5.0.14). |
| 52 |
# |
| 53 |
--source suite/funcs_1/datadict/datadict_bug_12777.inc |
| 54 |
eval DESCRIBE information_schema.$is_table; |
| 55 |
--source suite/funcs_1/datadict/datadict_bug_12777.inc |
| 56 |
--replace_result InnoDB TMP_TABLE_ENGINE MyISAM TMP_TABLE_ENGINE |
| 57 |
eval SHOW CREATE TABLE information_schema.$is_table; |
| 58 |
--source suite/funcs_1/datadict/datadict_bug_12777.inc |
| 59 |
eval SHOW COLUMNS FROM information_schema.$is_table; |
| 60 |
|
| 61 |
# Note: Retrieval of information within information_schema.columns about |
| 62 |
# information_schema.views is in is_columns_is.test. |
| 63 |
|
| 64 |
# Show that TABLE_CATALOG is always NULL. |
| 65 |
SELECT table_catalog, table_schema, table_name |
| 66 |
FROM information_schema.views WHERE table_catalog IS NOT NULL order by table_name; |
| 67 |
|
| 68 |
|
| 69 |
--echo ################################################################################ |
| 70 |
--echo # Testcase 3.2.13.2 + 3.2.13.3: INFORMATION_SCHEMA.VIEWS accessible information |
| 71 |
--echo ################################################################################ |
| 72 |
# 3.2.13.2: Ensure that the table shows the relevant information on every view for |
| 73 |
# which the current user or PUBLIC has the SHOW CREATE VIEW privilege. |
| 74 |
# 3.2.13.3: Ensure that the table does not show any information on any views for which |
| 75 |
# the current user and PUBLIC have no SHOW CREATE VIEW privilege. |
| 76 |
# |
| 77 |
--disable_warnings |
| 78 |
DROP DATABASE IF EXISTS db_datadict; |
| 79 |
--enable_warnings |
| 80 |
CREATE DATABASE db_datadict; |
| 81 |
|
| 82 |
--error 0,ER_CANNOT_USER |
| 83 |
DROP USER 'testuser1'@'localhost'; |
| 84 |
CREATE USER 'testuser1'@'localhost'; |
| 85 |
--error 0,ER_CANNOT_USER |
| 86 |
DROP USER 'testuser2'@'localhost'; |
| 87 |
CREATE USER 'testuser2'@'localhost'; |
| 88 |
--error 0,ER_CANNOT_USER |
| 89 |
DROP USER 'test_no_views'@'localhost'; |
| 90 |
CREATE USER 'test_no_views'@'localhost'; |
| 91 |
|
| 92 |
--replace_result $engine_type <engine_type> |
| 93 |
eval |
| 94 |
CREATE TABLE db_datadict.t1(f1 INT, f2 INT, f3 INT) |
| 95 |
ENGINE = $engine_type; |
| 96 |
CREATE VIEW db_datadict.v_granted_to_1 AS SELECT * FROM db_datadict.t1; |
| 97 |
CREATE VIEW db_datadict.v_granted_glob AS SELECT f2, f3 FROM db_datadict.t1; |
| 98 |
|
| 99 |
GRANT SELECT ON db_datadict.t1 TO 'testuser1'@'localhost'; |
| 100 |
GRANT SELECT ON db_datadict.v_granted_to_1 TO 'testuser1'@'localhost'; |
| 101 |
GRANT SHOW VIEW, CREATE VIEW ON db_datadict.* TO 'testuser2'@'localhost'; |
| 102 |
|
| 103 |
let $select = SELECT * FROM information_schema.views |
| 104 |
WHERE table_schema = 'db_datadict' ORDER BY table_name; |
| 105 |
eval $select; |
| 106 |
|
| 107 |
--echo # Establish connection testuser1 (user=testuser1) |
| 108 |
--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK |
| 109 |
connect (testuser1, localhost, testuser1, , test); |
| 110 |
eval $select; |
| 111 |
|
| 112 |
--echo # Establish connection testuser2 (user=testuser2) |
| 113 |
--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK |
| 114 |
connect (testuser2, localhost, testuser2, , test); |
| 115 |
eval $select; |
| 116 |
|
| 117 |
--echo # Establish connection test_no_views (user=test_no_views) |
| 118 |
--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK |
| 119 |
connect (test_no_views, localhost, test_no_views, , test); |
| 120 |
eval $select; |
| 121 |
|
| 122 |
# Cleanup |
| 123 |
--echo # Switch to connection default and close all other connections |
| 124 |
connection default; |
| 125 |
disconnect testuser1; |
| 126 |
disconnect testuser2; |
| 127 |
disconnect test_no_views; |
| 128 |
DROP USER 'testuser1'@'localhost'; |
| 129 |
DROP USER 'testuser2'@'localhost'; |
| 130 |
DROP USER 'test_no_views'@'localhost'; |
| 131 |
DROP DATABASE db_datadict; |
| 132 |
|
| 133 |
--echo ######################################################################### |
| 134 |
--echo # 3.2.1.13+3.2.1.14+3.2.1.15: INFORMATION_SCHEMA.VIEWS modifications |
| 135 |
--echo ######################################################################### |
| 136 |
# 3.2.1.13: Ensure that the creation of any new database object (e.g. table or |
| 137 |
# column) automatically inserts all relevant information on that |
| 138 |
# object into every appropriate INFORMATION_SCHEMA table. |
| 139 |
# 3.2.1.14: Ensure that the alteration of any existing database object |
| 140 |
# automatically updates all relevant information on that object in |
| 141 |
# every appropriate INFORMATION_SCHEMA table. |
| 142 |
# 3.2.1.15: Ensure that the dropping of any existing database object |
| 143 |
# automatically deletes all relevant information on that object from |
| 144 |
# every appropriate INFORMATION_SCHEMA table. |
| 145 |
# |
| 146 |
--disable_warnings |
| 147 |
DROP TABLE IF EXISTS test.t1_my_table; |
| 148 |
DROP DATABASE IF EXISTS db_datadict; |
| 149 |
--enable_warnings |
| 150 |
CREATE DATABASE db_datadict; |
| 151 |
--replace_result $engine_type <engine_type> |
| 152 |
eval |
| 153 |
CREATE TABLE test.t1_table (f1 BIGINT, f2 CHAR(10)) |
| 154 |
DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci |
| 155 |
ENGINE = $engine_type; |
| 156 |
--error 0,ER_CANNOT_USER |
| 157 |
DROP USER 'testuser1'@'localhost'; |
| 158 |
CREATE USER 'testuser1'@'localhost'; |
| 159 |
|
| 160 |
# Check just created VIEW |
| 161 |
SELECT * FROM information_schema.views |
| 162 |
WHERE table_name LIKE 't1_%'; |
| 163 |
CREATE VIEW test.t1_view AS SELECT DISTINCT f1 FROM test.t1_table; |
| 164 |
SELECT * FROM information_schema.views |
| 165 |
WHERE table_name LIKE 't1_%'; |
| 166 |
# |
| 167 |
# Check modification of DEFINER, SECURITY_TYPE, IS_UPDATABLE, VIEW_DEFINITION, |
| 168 |
# CHECK_OPTION |
| 169 |
SELECT table_name,definer FROM information_schema.views |
| 170 |
WHERE table_name = 't1_view'; |
| 171 |
ALTER DEFINER = 'testuser1'@'localhost' VIEW test.t1_view AS |
| 172 |
SELECT DISTINCT f1 FROM test.t1_table; |
| 173 |
# The next result set could suffer from |
| 174 |
# Bug#22763 Disrepancy between SHOW CREATE VIEW and I_S.VIEWS |
| 175 |
# because the VIEW definition is missing. |
| 176 |
# Therefore we exclude the problematic columns from the result set. |
| 177 |
SELECT table_name,definer,security_type FROM information_schema.views |
| 178 |
WHERE table_name LIKE 't1_%'; |
| 179 |
ALTER DEFINER = 'root'@'localhost' SQL SECURITY INVOKER VIEW test.t1_view AS |
| 180 |
SELECT f1 FROM test.t1_table WITH LOCAL CHECK OPTION; |
| 181 |
SELECT table_name,definer,security_type FROM information_schema.views |
| 182 |
WHERE table_name LIKE 't1_%'; |
| 183 |
# |
| 184 |
# Check modification of TABLE_SCHEMA |
| 185 |
SELECT table_schema,table_name FROM information_schema.views |
| 186 |
WHERE table_name LIKE 't1_%' |
| 187 |
ORDER BY table_schema,table_name; |
| 188 |
--error ER_FORBID_SCHEMA_CHANGE |
| 189 |
RENAME TABLE test.t1_view TO db_datadict.t1_view; |
| 190 |
# Workaround for missing move to another database |
| 191 |
DROP VIEW test.t1_view; |
| 192 |
CREATE VIEW db_datadict.t1_view AS SELECT * FROM test.t1_table; |
| 193 |
SELECT table_schema,table_name FROM information_schema.views |
| 194 |
WHERE table_name LIKE 't1_%' |
| 195 |
ORDER BY table_schema,table_name; |
| 196 |
# |
| 197 |
# Check modification of TABLE_NAME |
| 198 |
SELECT table_name FROM information_schema.views |
| 199 |
WHERE table_name LIKE 't1_%' |
| 200 |
ORDER BY table_name; |
| 201 |
RENAME TABLE db_datadict.t1_view TO db_datadict.t1_viewx; |
| 202 |
SELECT table_name FROM information_schema.views |
| 203 |
WHERE table_name LIKE 't1_%' |
| 204 |
ORDER BY table_name; |
| 205 |
# |
| 206 |
# Check impact of DROP VIEW |
| 207 |
SELECT table_name FROM information_schema.views |
| 208 |
WHERE table_name LIKE 't1_%' |
| 209 |
ORDER BY table_name; |
| 210 |
DROP VIEW db_datadict.t1_viewx; |
| 211 |
SELECT table_name FROM information_schema.views |
| 212 |
WHERE table_name LIKE 't1_%' |
| 213 |
ORDER BY table_name; |
| 214 |
CREATE VIEW db_datadict.t1_view AS SELECT * FROM test.t1_table; |
| 215 |
# |
| 216 |
# Check impact of DROP base TABLE of VIEW |
| 217 |
SELECT table_name FROM information_schema.views |
| 218 |
WHERE table_name LIKE 't1_%' |
| 219 |
ORDER BY table_name; |
| 220 |
DROP TABLE test.t1_table; |
| 221 |
SELECT table_name FROM information_schema.views |
| 222 |
WHERE table_name LIKE 't1_%' |
| 223 |
ORDER BY table_name; |
| 224 |
--replace_result $engine_type <engine_type> |
| 225 |
eval |
| 226 |
CREATE TABLE test.t1_table (f1 BIGINT, f2 CHAR(10)) |
| 227 |
DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci COMMENT = 'Initial Comment' |
| 228 |
ENGINE = $engine_type; |
| 229 |
# |
| 230 |
# Check impact of DROP SCHEMA |
| 231 |
SELECT table_name FROM information_schema.views |
| 232 |
WHERE table_name LIKE 't1_%' |
| 233 |
ORDER BY table_name; |
| 234 |
DROP DATABASE db_datadict; |
| 235 |
SELECT table_name FROM information_schema.views |
| 236 |
WHERE table_name LIKE 't1_%' |
| 237 |
ORDER BY table_name; |
| 238 |
|
| 239 |
# Cleanup |
| 240 |
DROP USER 'testuser1'@'localhost'; |
| 241 |
DROP TABLE test.t1_table; |
| 242 |
|
| 243 |
--echo ######################################################################## |
| 244 |
--echo # Testcases 3.2.1.3-3.2.1.5 + 3.2.1.8-3.2.1.12: INSERT/UPDATE/DELETE and |
| 245 |
--echo # DDL on INFORMATION_SCHEMA table are not supported |
| 246 |
--echo ######################################################################## |
| 247 |
# 3.2.1.3: Ensure that no user may execute an INSERT statement on any |
| 248 |
# INFORMATION_SCHEMA table. |
| 249 |
# 3.2.1.4: Ensure that no user may execute an UPDATE statement on any |
| 250 |
# INFORMATION_SCHEMA table. |
| 251 |
# 3.2.1.5: Ensure that no user may execute a DELETE statement on any |
| 252 |
# INFORMATION_SCHEMA table. |
| 253 |
# 3.2.1.8: Ensure that no user may create an index on an |
| 254 |
# INFORMATION_SCHEMA table. |
| 255 |
# 3.2.1.9: Ensure that no user may alter the definition of an |
| 256 |
# INFORMATION_SCHEMA table. |
| 257 |
# 3.2.1.10: Ensure that no user may drop an INFORMATION_SCHEMA table. |
| 258 |
# 3.2.1.11: Ensure that no user may move an INFORMATION_SCHEMA table to any |
| 259 |
# other database. |
| 260 |
# 3.2.1.12: Ensure that no user may directly add to, alter, or delete any data |
| 261 |
# in an INFORMATION_SCHEMA table. |
| 262 |
# |
| 263 |
--disable_warnings |
| 264 |
DROP DATABASE IF EXISTS db_datadict; |
| 265 |
--enable_warnings |
| 266 |
CREATE DATABASE db_datadict; |
| 267 |
CREATE VIEW db_datadict.v1 AS SELECT 1; |
| 268 |
|
| 269 |
--error ER_DBACCESS_DENIED_ERROR |
| 270 |
INSERT INTO information_schema.views |
| 271 |
SELECT * FROM information_schema.views; |
| 272 |
--error ER_DBACCESS_DENIED_ERROR |
| 273 |
INSERT INTO information_schema.views(table_schema, table_name) |
| 274 |
VALUES ('db2', 'v2'); |
| 275 |
|
| 276 |
# Note: |
| 277 |
# 1. We can get different error messages here. |
| 278 |
# 2. We do not want to unify the individual messages to the far to unspecific |
| 279 |
# 'Got one of the listed errors'. |
| 280 |
let $my_error_message = |
| 281 |
##### The previous statement must fail ###### |
| 282 |
# Server type | expected error name | expected error message |
| 283 |
# -------------------------------------------------------------------------------------------------------------------- |
| 284 |
# MySQL | ER_DBACCESS_DENIED_ERROR | ERROR 42000: Access denied for user 'root'@'localhost' to database 'information_schema' |
| 285 |
; |
| 286 |
--disable_abort_on_error |
| 287 |
UPDATE information_schema.views SET table_schema = 'test' |
| 288 |
WHERE table_name = 't1'; |
| 289 |
if (!$mysql_errno) |
| 290 |
{ |
| 291 |
--echo $my_error_message |
| 292 |
exit; |
| 293 |
} |
| 294 |
--enable_abort_on_error |
| 295 |
|
| 296 |
--error ER_DBACCESS_DENIED_ERROR |
| 297 |
DELETE FROM information_schema.views WHERE table_name = 't1'; |
| 298 |
--error ER_DBACCESS_DENIED_ERROR |
| 299 |
TRUNCATE information_schema.views; |
| 300 |
|
| 301 |
--error ER_DBACCESS_DENIED_ERROR |
| 302 |
CREATE INDEX my_idx_on_views ON information_schema.views(table_schema); |
| 303 |
|
| 304 |
--error ER_DBACCESS_DENIED_ERROR |
| 305 |
ALTER TABLE information_schema.views DROP PRIMARY KEY; |
| 306 |
--error ER_DBACCESS_DENIED_ERROR |
| 307 |
ALTER TABLE information_schema.views ADD f1 INT; |
| 308 |
|
| 309 |
--error ER_DBACCESS_DENIED_ERROR |
| 310 |
DROP TABLE information_schema.views; |
| 311 |
|
| 312 |
--error ER_DBACCESS_DENIED_ERROR |
| 313 |
ALTER TABLE information_schema.views RENAME db_datadict.views; |
| 314 |
--error ER_DBACCESS_DENIED_ERROR |
| 315 |
ALTER TABLE information_schema.views RENAME information_schema.xviews; |
| 316 |
|
| 317 |
# Cleanup |
| 318 |
DROP DATABASE db_datadict; |
| 319 |
|