1
# suite/funcs_1/datadict/is_views.inc
3
# Check the layout of information_schema.views and the impact of
4
# CREATE/ALTER/DROP TABLE/VIEW/SCHEMA ... on it.
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.
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_views.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 = VIEWS;
27
# The table INFORMATION_SCHEMA.VIEWS 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.13.1: INFORMATION_SCHEMA.VIEWS layout
41
--echo #########################################################################
42
# Ensure that the INFORMATION_SCHEMA.VIEWS table has the following columns,
43
# in the following order:
45
# TABLE_CATALOG (always shows NULL),
46
# TABLE_SCHEMA (shows the database, or schema, in which an accessible
48
# TABLE_NAME (shows the name of a view accessible to the current user),
49
# VIEW_DEFINITION (shows the SELECT statement that makes up the
51
# CHECK_OPTION (shows the value of the WITH CHECK OPTION clause used to define
52
# the view, either NONE, LOCAL or CASCADED),
53
# IS_UPDATABLE (shows whether the view is an updatable view),
54
# DEFINER (added with 5.0.14),
55
# SECURITY_TYPE (added with 5.0.14).
57
--source suite/funcs_1/datadict/datadict_bug_12777.inc
58
eval DESCRIBE information_schema.$is_table;
59
--source suite/funcs_1/datadict/datadict_bug_12777.inc
60
--replace_result ENGINE=MyISAM "" ENGINE=MARIA "" " PAGE_CHECKSUM=1" "" " PAGE_CHECKSUM=0" ""
61
eval SHOW CREATE TABLE information_schema.$is_table;
62
--source suite/funcs_1/datadict/datadict_bug_12777.inc
63
eval SHOW COLUMNS FROM information_schema.$is_table;
65
# Note: Retrieval of information within information_schema.columns about
66
# information_schema.views is in is_columns_is.test.
68
# Show that TABLE_CATALOG is always NULL.
69
SELECT table_catalog, table_schema, table_name
70
FROM information_schema.views WHERE table_catalog IS NOT NULL;
73
--echo ################################################################################
74
--echo # Testcase 3.2.13.2 + 3.2.13.3: INFORMATION_SCHEMA.VIEWS accessible information
75
--echo ################################################################################
76
# 3.2.13.2: Ensure that the table shows the relevant information on every view for
77
# which the current user or PUBLIC has the SHOW CREATE VIEW privilege.
78
# 3.2.13.3: Ensure that the table does not show any information on any views for which
79
# the current user and PUBLIC have no SHOW CREATE VIEW privilege.
82
DROP DATABASE IF EXISTS db_datadict;
84
CREATE DATABASE db_datadict;
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 'test_no_views'@'localhost';
94
CREATE USER 'test_no_views'@'localhost';
96
--replace_result $engine_type <engine_type>
98
CREATE TABLE db_datadict.t1(f1 INT, f2 INT, f3 INT)
99
ENGINE = $engine_type;
100
CREATE VIEW db_datadict.v_granted_to_1 AS SELECT * FROM db_datadict.t1;
101
CREATE VIEW db_datadict.v_granted_glob AS SELECT f2, f3 FROM db_datadict.t1;
103
GRANT SELECT ON db_datadict.t1 TO 'testuser1'@'localhost';
104
GRANT SELECT ON db_datadict.v_granted_to_1 TO 'testuser1'@'localhost';
105
GRANT SHOW VIEW, CREATE VIEW ON db_datadict.* TO 'testuser2'@'localhost';
107
let $select = SELECT * FROM information_schema.views
108
WHERE table_schema = 'db_datadict' ORDER BY table_name;
111
--echo # Establish connection testuser1 (user=testuser1)
112
--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
113
connect (testuser1, localhost, testuser1, , test);
116
--echo # Establish connection testuser2 (user=testuser2)
117
--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
118
connect (testuser2, localhost, testuser2, , test);
121
--echo # Establish connection test_no_views (user=test_no_views)
122
--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
123
connect (test_no_views, localhost, test_no_views, , test);
127
--echo # Switch to connection default and close all other connections
129
disconnect testuser1;
130
disconnect testuser2;
131
disconnect test_no_views;
132
DROP USER 'testuser1'@'localhost';
133
DROP USER 'testuser2'@'localhost';
134
DROP USER 'test_no_views'@'localhost';
135
DROP DATABASE db_datadict;
137
--echo #########################################################################
138
--echo # 3.2.1.13+3.2.1.14+3.2.1.15: INFORMATION_SCHEMA.VIEWS modifications
139
--echo #########################################################################
140
# 3.2.1.13: Ensure that the creation of any new database object (e.g. table or
141
# column) automatically inserts all relevant information on that
142
# object into every appropriate INFORMATION_SCHEMA table.
143
# 3.2.1.14: Ensure that the alteration of any existing database object
144
# automatically updates all relevant information on that object in
145
# every appropriate INFORMATION_SCHEMA table.
146
# 3.2.1.15: Ensure that the dropping of any existing database object
147
# automatically deletes all relevant information on that object from
148
# every appropriate INFORMATION_SCHEMA table.
151
DROP TABLE IF EXISTS test.t1_my_table;
152
DROP DATABASE IF EXISTS db_datadict;
154
CREATE DATABASE db_datadict;
155
--replace_result $engine_type <engine_type>
157
CREATE TABLE test.t1_table (f1 BIGINT, f2 CHAR(10))
158
DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci
159
ENGINE = $engine_type;
160
--error 0,ER_CANNOT_USER
161
DROP USER 'testuser1'@'localhost';
162
CREATE USER 'testuser1'@'localhost';
164
# Check just created VIEW
165
SELECT * FROM information_schema.views
166
WHERE table_name LIKE 't1_%';
167
CREATE VIEW test.t1_view AS SELECT DISTINCT f1 FROM test.t1_table;
168
SELECT * FROM information_schema.views
169
WHERE table_name LIKE 't1_%';
171
# Check modification of DEFINER, SECURITY_TYPE, IS_UPDATABLE, VIEW_DEFINITION,
173
SELECT table_name,definer FROM information_schema.views
174
WHERE table_name = 't1_view';
175
ALTER DEFINER = 'testuser1'@'localhost' VIEW test.t1_view AS
176
SELECT DISTINCT f1 FROM test.t1_table;
177
# The next result set could suffer from
178
# Bug#22763 Disrepancy between SHOW CREATE VIEW and I_S.VIEWS
179
# because the VIEW definition is missing.
180
# Therefore we exclude the problematic columns from the result set.
181
SELECT table_name,definer,security_type FROM information_schema.views
182
WHERE table_name LIKE 't1_%';
183
ALTER DEFINER = 'root'@'localhost' SQL SECURITY INVOKER VIEW test.t1_view AS
184
SELECT f1 FROM test.t1_table WITH LOCAL CHECK OPTION;
185
SELECT table_name,definer,security_type FROM information_schema.views
186
WHERE table_name LIKE 't1_%';
188
# Check modification of TABLE_SCHEMA
189
SELECT table_schema,table_name FROM information_schema.views
190
WHERE table_name LIKE 't1_%'
191
ORDER BY table_schema,table_name;
192
--error ER_FORBID_SCHEMA_CHANGE
193
RENAME TABLE test.t1_view TO db_datadict.t1_view;
194
# Workaround for missing move to another database
195
DROP VIEW test.t1_view;
196
CREATE VIEW db_datadict.t1_view AS SELECT * FROM test.t1_table;
197
SELECT table_schema,table_name FROM information_schema.views
198
WHERE table_name LIKE 't1_%'
199
ORDER BY table_schema,table_name;
201
# Check modification of TABLE_NAME
202
SELECT table_name FROM information_schema.views
203
WHERE table_name LIKE 't1_%'
205
RENAME TABLE db_datadict.t1_view TO db_datadict.t1_viewx;
206
SELECT table_name FROM information_schema.views
207
WHERE table_name LIKE 't1_%'
210
# Check impact of DROP VIEW
211
SELECT table_name FROM information_schema.views
212
WHERE table_name LIKE 't1_%'
214
DROP VIEW db_datadict.t1_viewx;
215
SELECT table_name FROM information_schema.views
216
WHERE table_name LIKE 't1_%'
218
CREATE VIEW db_datadict.t1_view AS SELECT * FROM test.t1_table;
220
# Check impact of DROP base TABLE of VIEW
221
SELECT table_name FROM information_schema.views
222
WHERE table_name LIKE 't1_%'
224
DROP TABLE test.t1_table;
225
SELECT table_name FROM information_schema.views
226
WHERE table_name LIKE 't1_%'
228
--replace_result $engine_type <engine_type>
230
CREATE TABLE test.t1_table (f1 BIGINT, f2 CHAR(10))
231
DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci COMMENT = 'Initial Comment'
232
ENGINE = $engine_type;
234
# Check impact of DROP SCHEMA
235
SELECT table_name FROM information_schema.views
236
WHERE table_name LIKE 't1_%'
238
DROP DATABASE db_datadict;
239
SELECT table_name FROM information_schema.views
240
WHERE table_name LIKE 't1_%'
244
DROP USER 'testuser1'@'localhost';
245
DROP TABLE test.t1_table;
247
--echo ########################################################################
248
--echo # Testcases 3.2.1.3-3.2.1.5 + 3.2.1.8-3.2.1.12: INSERT/UPDATE/DELETE and
249
--echo # DDL on INFORMATION_SCHEMA table are not supported
250
--echo ########################################################################
251
# 3.2.1.3: Ensure that no user may execute an INSERT statement on any
252
# INFORMATION_SCHEMA table.
253
# 3.2.1.4: Ensure that no user may execute an UPDATE statement on any
254
# INFORMATION_SCHEMA table.
255
# 3.2.1.5: Ensure that no user may execute a DELETE statement on any
256
# INFORMATION_SCHEMA table.
257
# 3.2.1.8: Ensure that no user may create an index on an
258
# INFORMATION_SCHEMA table.
259
# 3.2.1.9: Ensure that no user may alter the definition of an
260
# INFORMATION_SCHEMA table.
261
# 3.2.1.10: Ensure that no user may drop an INFORMATION_SCHEMA table.
262
# 3.2.1.11: Ensure that no user may move an INFORMATION_SCHEMA table to any
264
# 3.2.1.12: Ensure that no user may directly add to, alter, or delete any data
265
# in an INFORMATION_SCHEMA table.
268
DROP DATABASE IF EXISTS db_datadict;
270
CREATE DATABASE db_datadict;
271
CREATE VIEW db_datadict.v1 AS SELECT 1;
273
--error ER_DBACCESS_DENIED_ERROR
274
INSERT INTO information_schema.views
275
SELECT * FROM information_schema.views;
276
--error ER_DBACCESS_DENIED_ERROR
277
INSERT INTO information_schema.views(table_schema, table_name)
278
VALUES ('db2', 'v2');
280
--error ER_DBACCESS_DENIED_ERROR
281
UPDATE information_schema.views SET table_schema = 'test'
282
WHERE table_name = 't1';
284
--error ER_DBACCESS_DENIED_ERROR
285
DELETE FROM information_schema.views WHERE table_name = 't1';
286
--error ER_DBACCESS_DENIED_ERROR
287
TRUNCATE information_schema.views;
289
--error ER_DBACCESS_DENIED_ERROR
290
CREATE INDEX my_idx_on_views ON information_schema.views(table_schema);
292
--error ER_DBACCESS_DENIED_ERROR
293
ALTER TABLE information_schema.views DROP PRIMARY KEY;
294
--error ER_DBACCESS_DENIED_ERROR
295
ALTER TABLE information_schema.views ADD f1 INT;
297
--error ER_DBACCESS_DENIED_ERROR
298
DROP TABLE information_schema.views;
300
--error ER_DBACCESS_DENIED_ERROR
301
ALTER TABLE information_schema.views RENAME db_datadict.views;
302
--error ER_DBACCESS_DENIED_ERROR
303
ALTER TABLE information_schema.views RENAME information_schema.xviews;
306
DROP DATABASE db_datadict;