~ubuntu-branches/ubuntu/trusty/mariadb-5.5/trusty-proposed

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Otto Kekäläinen
  • Date: 2013-12-22 10:27:05 UTC
  • Revision ID: package-import@ubuntu.com-20131222102705-mndw7s12mz0szrcn
Tags: upstream-5.5.32
Import upstream version 5.5.32

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
let $is_table = SCHEMATA;
 
22
 
 
23
# The table INFORMATION_SCHEMA.SCHEMATA 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.9.1: INFORMATION_SCHEMA.SCHEMATA layout;
 
37
--echo #########################################################################
 
38
# Ensure that the INFORMATION_SCHEMA.SCHEMATA table has the following columns,
 
39
# in the following order:
 
40
#
 
41
# CATALOG_NAME (always shows NULL),
 
42
# SCHEMA_NAME (shows the name of a database, or schema, on which the current
 
43
#        user or PUBLIC has privileges),
 
44
# DEFAULT_CHARACTER_SET_NAME (shows the name of that database's default
 
45
#        character set),
 
46
# DEFAULT_COLLATION_NAME (shows the database defaul collation)
 
47
# SQL_PATH (always shows NULL).
 
48
#
 
49
--source suite/funcs_1/datadict/datadict_bug_12777.inc
 
50
eval DESCRIBE          information_schema.$is_table;
 
51
--source suite/funcs_1/datadict/datadict_bug_12777.inc
 
52
eval SHOW CREATE TABLE information_schema.$is_table;
 
53
--source suite/funcs_1/datadict/datadict_bug_12777.inc
 
54
eval SHOW COLUMNS FROM information_schema.$is_table;
 
55
 
 
56
# Note: Retrieval of information within information_schema.columns about
 
57
#       information_schema.schemata is in is_columns_is.test.
 
58
 
 
59
# Show that CATALOG_NAME and SQL_PATH are always NULL.
 
60
SELECT catalog_name, schema_name, sql_path
 
61
FROM information_schema.schemata
 
62
WHERE catalog_name IS NOT NULL or sql_path IS NOT NULL;
 
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;
 
82
CREATE DATABASE db_datadict_2;
 
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
# not embedded | ER_DBACCESS_DENIED_ERROR | ERROR 42000: Access denied for user 'root'@'localhost' to database 'information_schema'
 
220
# embedded     | ER_NON_INSERTABLE_TABLE  | ERROR HY000: The target table schemata of the INSERT is not insertable-into
 
221
#              | or similar               |              or similar
 
222
;
 
223
 
 
224
--disable_abort_on_error
 
225
INSERT INTO information_schema.schemata
 
226
       (catalog_name, schema_name, default_character_set_name, sql_path)
 
227
VALUES (NULL, 'db1', 'latin1', NULL);
 
228
if (!$mysql_errno)
 
229
{
 
230
   --echo $my_error_message
 
231
   exit;
 
232
}
 
233
INSERT INTO information_schema.schemata
 
234
SELECT * FROM information_schema.schemata;
 
235
if (!$mysql_errno)
 
236
{
 
237
   --echo $my_error_message
 
238
   exit;
 
239
}
 
240
UPDATE information_schema.schemata
 
241
SET default_character_set_name = 'utf8'
 
242
WHERE schema_name = 'db_datadict';
 
243
if (!$mysql_errno)
 
244
{
 
245
   --echo $my_error_message
 
246
   exit;
 
247
}
 
248
UPDATE information_schema.schemata SET catalog_name = 't_4711';
 
249
if (!$mysql_errno)
 
250
{
 
251
   --echo $my_error_message
 
252
   exit;
 
253
}
 
254
DELETE FROM information_schema.schemata WHERE schema_name = 'db_datadict';
 
255
if (!$mysql_errno)
 
256
{
 
257
   --echo $my_error_message
 
258
   exit;
 
259
}
 
260
TRUNCATE information_schema.schemata;
 
261
if (!$mysql_errno)
 
262
{
 
263
   --echo $my_error_message
 
264
   exit;
 
265
}
 
266
CREATE INDEX i1 ON information_schema.schemata(schema_name);
 
267
if (!$mysql_errno)
 
268
{
 
269
   --echo $my_error_message
 
270
   exit;
 
271
}
 
272
ALTER TABLE information_schema.schemata ADD f1 INT;
 
273
if (!$mysql_errno)
 
274
{
 
275
   --echo $my_error_message
 
276
   exit;
 
277
}
 
278
DROP TABLE information_schema.schemata;
 
279
if (!$mysql_errno)
 
280
{
 
281
   --echo $my_error_message
 
282
   exit;
 
283
}
 
284
ALTER TABLE information_schema.schemata RENAME db_datadict.schemata;
 
285
if (!$mysql_errno)
 
286
{
 
287
   --echo $my_error_message
 
288
   exit;
 
289
}
 
290
ALTER TABLE information_schema.schemata RENAME information_schema.xschemata;
 
291
if (!$mysql_errno)
 
292
{
 
293
   --echo $my_error_message
 
294
   exit;
 
295
}
 
296
--enable_abort_on_error
 
297
 
 
298
# Cleanup
 
299
DROP DATABASE db_datadict;
 
300