~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to mysql-test/suite/funcs_1/datadict/is_views.inc

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
#                   create variants for embedded/non embedded server.
 
20
#
 
21
 
 
22
let $engine_type       = MEMORY;
 
23
let $other_engine_type = MyISAM;
 
24
 
 
25
let $is_table = VIEWS;
 
26
 
 
27
# The table INFORMATION_SCHEMA.VIEWS must exist
 
28
eval SHOW TABLES FROM information_schema LIKE '$is_table';
 
29
 
 
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.
 
35
#
 
36
--source suite/funcs_1/datadict/is_table_query.inc
 
37
 
 
38
 
 
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:
 
44
#
 
45
# TABLE_CATALOG (always shows NULL),
 
46
# TABLE_SCHEMA (shows the database, or schema, in which an accessible
 
47
#       view resides),
 
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
 
50
#       view's definition),
 
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).
 
56
#
 
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
eval SHOW CREATE TABLE information_schema.$is_table;
 
61
--source suite/funcs_1/datadict/datadict_bug_12777.inc
 
62
eval SHOW COLUMNS FROM information_schema.$is_table;
 
63
 
 
64
# Note: Retrieval of information within information_schema.columns about
 
65
#       information_schema.views is in is_columns_is.test.
 
66
 
 
67
# Show that TABLE_CATALOG is always NULL.
 
68
SELECT table_catalog, table_schema, table_name
 
69
FROM information_schema.views WHERE table_catalog IS NOT NULL;
 
70
 
 
71
 
 
72
--echo ################################################################################
 
73
--echo # Testcase 3.2.13.2 + 3.2.13.3: INFORMATION_SCHEMA.VIEWS accessible information
 
74
--echo ################################################################################
 
75
# 3.2.13.2: Ensure that the table shows the relevant information on every view for
 
76
#           which the current user or PUBLIC has the SHOW CREATE VIEW privilege.
 
77
# 3.2.13.3: Ensure that the table does not show any information on any views for which
 
78
#           the current user and PUBLIC have no SHOW CREATE VIEW privilege.
 
79
#
 
80
--disable_warnings
 
81
DROP DATABASE IF EXISTS db_datadict;
 
82
--enable_warnings
 
83
CREATE DATABASE db_datadict;
 
84
 
 
85
--error 0,ER_CANNOT_USER
 
86
DROP   USER 'testuser1'@'localhost';
 
87
CREATE USER 'testuser1'@'localhost';
 
88
--error 0,ER_CANNOT_USER
 
89
DROP   USER 'testuser2'@'localhost';
 
90
CREATE USER 'testuser2'@'localhost';
 
91
--error 0,ER_CANNOT_USER
 
92
DROP   USER 'test_no_views'@'localhost';
 
93
CREATE USER 'test_no_views'@'localhost';
 
94
 
 
95
--replace_result $engine_type <engine_type>
 
96
eval
 
97
CREATE TABLE db_datadict.t1(f1 INT, f2 INT, f3 INT)
 
98
ENGINE = $engine_type;
 
99
CREATE VIEW db_datadict.v_granted_to_1 AS SELECT * FROM db_datadict.t1;
 
100
CREATE VIEW db_datadict.v_granted_glob AS SELECT f2, f3 FROM db_datadict.t1;
 
101
 
 
102
GRANT SELECT ON db_datadict.t1 TO 'testuser1'@'localhost';
 
103
GRANT SELECT ON db_datadict.v_granted_to_1 TO 'testuser1'@'localhost';
 
104
GRANT SHOW VIEW, CREATE VIEW ON db_datadict.* TO 'testuser2'@'localhost';
 
105
 
 
106
let $select = SELECT * FROM information_schema.views
 
107
WHERE table_schema = 'db_datadict' ORDER BY table_name;
 
108
eval $select;
 
109
 
 
110
--echo # Establish connection testuser1 (user=testuser1)
 
111
--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
 
112
connect (testuser1, localhost, testuser1, , test);
 
113
eval $select;
 
114
 
 
115
--echo # Establish connection testuser2 (user=testuser2)
 
116
--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
 
117
connect (testuser2, localhost, testuser2, , test);
 
118
eval $select;
 
119
 
 
120
--echo # Establish connection test_no_views (user=test_no_views)
 
121
--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
 
122
connect (test_no_views, localhost, test_no_views, , test);
 
123
eval $select;
 
124
 
 
125
# Cleanup
 
126
--echo # Switch to connection default and close all other connections
 
127
connection default;
 
128
disconnect testuser1;
 
129
disconnect testuser2;
 
130
disconnect test_no_views;
 
131
DROP USER 'testuser1'@'localhost';
 
132
DROP USER 'testuser2'@'localhost';
 
133
DROP USER 'test_no_views'@'localhost';
 
134
DROP DATABASE db_datadict;
 
135
 
 
136
--echo #########################################################################
 
137
--echo # 3.2.1.13+3.2.1.14+3.2.1.15: INFORMATION_SCHEMA.VIEWS modifications
 
138
--echo #########################################################################
 
139
# 3.2.1.13: Ensure that the creation of any new database object (e.g. table or
 
140
#           column) automatically inserts all relevant information on that
 
141
#           object into every appropriate INFORMATION_SCHEMA table.
 
142
# 3.2.1.14: Ensure that the alteration of any existing database object
 
143
#           automatically updates all relevant information on that object in
 
144
#           every appropriate INFORMATION_SCHEMA table.
 
145
# 3.2.1.15: Ensure that the dropping of any existing database object
 
146
#           automatically deletes all relevant information on that object from
 
147
#           every appropriate INFORMATION_SCHEMA table.
 
148
#
 
149
--disable_warnings
 
150
DROP TABLE IF EXISTS test.t1_my_table;
 
151
DROP DATABASE IF EXISTS db_datadict;
 
152
--enable_warnings
 
153
CREATE DATABASE db_datadict;
 
154
--replace_result $engine_type <engine_type>
 
155
eval
 
156
CREATE TABLE test.t1_table (f1 BIGINT, f2 CHAR(10))
 
157
DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci
 
158
ENGINE = $engine_type;
 
159
--error 0,ER_CANNOT_USER
 
160
DROP   USER 'testuser1'@'localhost';
 
161
CREATE USER 'testuser1'@'localhost';
 
162
 
 
163
# Check just created VIEW
 
164
SELECT * FROM information_schema.views
 
165
WHERE table_name LIKE 't1_%';
 
166
CREATE VIEW test.t1_view AS SELECT DISTINCT f1 FROM test.t1_table;
 
167
SELECT * FROM information_schema.views
 
168
WHERE table_name LIKE 't1_%';
 
169
#
 
170
# Check modification of DEFINER, SECURITY_TYPE, IS_UPDATABLE, VIEW_DEFINITION,
 
171
# CHECK_OPTION
 
172
SELECT table_name,definer FROM information_schema.views
 
173
WHERE table_name = 't1_view';
 
174
ALTER DEFINER = 'testuser1'@'localhost' VIEW test.t1_view AS
 
175
SELECT DISTINCT f1 FROM test.t1_table;
 
176
# The next result set could suffer from
 
177
# Bug#22763     Disrepancy between SHOW CREATE VIEW and I_S.VIEWS
 
178
# because the VIEW definition is missing.
 
179
# Therefore we exclude the problematic columns from the result set.
 
180
SELECT table_name,definer,security_type FROM information_schema.views
 
181
WHERE table_name LIKE 't1_%';
 
182
ALTER DEFINER = 'root'@'localhost' SQL SECURITY INVOKER VIEW test.t1_view AS
 
183
SELECT f1 FROM test.t1_table WITH LOCAL CHECK OPTION;
 
184
SELECT table_name,definer,security_type FROM information_schema.views
 
185
WHERE table_name LIKE 't1_%';
 
186
#
 
187
# Check modification of TABLE_SCHEMA
 
188
SELECT table_schema,table_name FROM information_schema.views
 
189
WHERE table_name LIKE 't1_%'
 
190
ORDER BY table_schema,table_name;
 
191
--error ER_FORBID_SCHEMA_CHANGE
 
192
RENAME TABLE test.t1_view TO db_datadict.t1_view;
 
193
# Workaround for missing move to another database
 
194
DROP VIEW test.t1_view;
 
195
CREATE VIEW db_datadict.t1_view AS SELECT * FROM test.t1_table;
 
196
SELECT table_schema,table_name FROM information_schema.views
 
197
WHERE table_name LIKE 't1_%'
 
198
ORDER BY table_schema,table_name;
 
199
#
 
200
# Check modification of TABLE_NAME
 
201
SELECT table_name FROM information_schema.views
 
202
WHERE table_name LIKE 't1_%'
 
203
ORDER BY table_name;
 
204
RENAME TABLE db_datadict.t1_view TO db_datadict.t1_viewx;
 
205
SELECT table_name FROM information_schema.views
 
206
WHERE table_name LIKE 't1_%'
 
207
ORDER BY table_name;
 
208
#
 
209
# Check impact of DROP VIEW
 
210
SELECT table_name FROM information_schema.views
 
211
WHERE table_name LIKE 't1_%'
 
212
ORDER BY table_name;
 
213
DROP VIEW db_datadict.t1_viewx;
 
214
SELECT table_name FROM information_schema.views
 
215
WHERE table_name LIKE 't1_%'
 
216
ORDER BY table_name;
 
217
CREATE VIEW db_datadict.t1_view AS SELECT * FROM test.t1_table;
 
218
#
 
219
# Check impact of DROP base TABLE of VIEW
 
220
SELECT table_name FROM information_schema.views
 
221
WHERE table_name LIKE 't1_%'
 
222
ORDER BY table_name;
 
223
DROP TABLE test.t1_table;
 
224
SELECT table_name FROM information_schema.views
 
225
WHERE table_name LIKE 't1_%'
 
226
ORDER BY table_name;
 
227
--replace_result $engine_type <engine_type>
 
228
eval
 
229
CREATE TABLE test.t1_table (f1 BIGINT, f2 CHAR(10))
 
230
DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci COMMENT = 'Initial Comment'
 
231
ENGINE = $engine_type;
 
232
#
 
233
# Check impact of DROP SCHEMA
 
234
SELECT table_name FROM information_schema.views
 
235
WHERE table_name LIKE 't1_%'
 
236
ORDER BY table_name;
 
237
DROP DATABASE db_datadict;
 
238
SELECT table_name FROM information_schema.views
 
239
WHERE table_name LIKE 't1_%'
 
240
ORDER BY table_name;
 
241
 
 
242
# Cleanup
 
243
DROP USER 'testuser1'@'localhost';
 
244
DROP TABLE test.t1_table;
 
245
 
 
246
--echo ########################################################################
 
247
--echo # Testcases 3.2.1.3-3.2.1.5 + 3.2.1.8-3.2.1.12: INSERT/UPDATE/DELETE and
 
248
--echo #           DDL on INFORMATION_SCHEMA table are not supported
 
249
--echo ########################################################################
 
250
# 3.2.1.3:  Ensure that no user may execute an INSERT statement on any
 
251
#           INFORMATION_SCHEMA table.
 
252
# 3.2.1.4:  Ensure that no user may execute an UPDATE statement on any
 
253
#           INFORMATION_SCHEMA table.
 
254
# 3.2.1.5:  Ensure that no user may execute a DELETE statement on any
 
255
#           INFORMATION_SCHEMA table.
 
256
# 3.2.1.8:  Ensure that no user may create an index on an
 
257
#           INFORMATION_SCHEMA table.
 
258
# 3.2.1.9:  Ensure that no user may alter the definition of an
 
259
#           INFORMATION_SCHEMA table.
 
260
# 3.2.1.10: Ensure that no user may drop an INFORMATION_SCHEMA table.
 
261
# 3.2.1.11: Ensure that no user may move an INFORMATION_SCHEMA table to any
 
262
#           other database.
 
263
# 3.2.1.12: Ensure that no user may directly add to, alter, or delete any data
 
264
#           in an INFORMATION_SCHEMA table.
 
265
#
 
266
--disable_warnings
 
267
DROP DATABASE IF EXISTS db_datadict;
 
268
--enable_warnings
 
269
CREATE DATABASE db_datadict;
 
270
CREATE VIEW db_datadict.v1 AS SELECT 1;
 
271
 
 
272
--error ER_DBACCESS_DENIED_ERROR
 
273
INSERT INTO information_schema.views
 
274
SELECT * FROM information_schema.views;
 
275
--error ER_DBACCESS_DENIED_ERROR
 
276
INSERT INTO information_schema.views(table_schema, table_name)
 
277
VALUES ('db2', 'v2');
 
278
 
 
279
--error ER_DBACCESS_DENIED_ERROR
 
280
UPDATE information_schema.views SET table_schema = 'test'
 
281
WHERE table_name = 't1';
 
282
 
 
283
--error ER_DBACCESS_DENIED_ERROR
 
284
DELETE FROM information_schema.views WHERE table_name = 't1';
 
285
--error ER_DBACCESS_DENIED_ERROR
 
286
TRUNCATE information_schema.views;
 
287
 
 
288
--error ER_DBACCESS_DENIED_ERROR
 
289
CREATE INDEX my_idx_on_views ON information_schema.views(table_schema);
 
290
 
 
291
--error ER_DBACCESS_DENIED_ERROR
 
292
ALTER TABLE information_schema.views DROP PRIMARY KEY;
 
293
--error ER_DBACCESS_DENIED_ERROR
 
294
ALTER TABLE information_schema.views ADD f1 INT;
 
295
 
 
296
--error ER_DBACCESS_DENIED_ERROR
 
297
DROP TABLE information_schema.views;
 
298
 
 
299
--error ER_DBACCESS_DENIED_ERROR
 
300
ALTER TABLE information_schema.views RENAME db_datadict.views;
 
301
--error ER_DBACCESS_DENIED_ERROR
 
302
ALTER TABLE information_schema.views RENAME information_schema.xviews;
 
303
 
 
304
# Cleanup
 
305
DROP DATABASE db_datadict;
 
306