~stewart/drizzle/embedded-innodb-create-select-transaction-arrgh

« back to all changes in this revision

Viewing changes to mysql-test/suite/funcs_1/t/is_columns.test

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# suite/funcs_1/t/is_columns.test
 
2
#
 
3
# Check the layout of information_schema.columns and the impact of
 
4
# CREATE/ALTER/DROP TABLE/VIEW/SCHEMA/COLUMN ... on its content.
 
5
#
 
6
# Note:
 
7
#    This test is not intended
 
8
#    - to show information about the all time existing tables
 
9
#      within the databases information_schema and mysql
 
10
#    - for checking storage engine properties
 
11
#      Therefore please do not alter $engine_type and $other_engine_type.
 
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
#
 
18
 
 
19
# --source suite/funcs_1/datadict/datadict.pre
 
20
 
 
21
let $engine_type       = MEMORY;
 
22
let $other_engine_type = MyISAM;
 
23
 
 
24
let $is_table = COLUMNS;
 
25
 
 
26
# The table INFORMATION_SCHEMA.COLUMNS must exist
 
27
eval SHOW TABLES FROM information_schema LIKE '$is_table';
 
28
 
 
29
--echo #######################################################################
 
30
--echo # Testcase 3.2.1.1: INFORMATION_SCHEMA tables can be queried via SELECT
 
31
--echo #######################################################################
 
32
# Ensure that every INFORMATION_SCHEMA table can be queried with a SELECT
 
33
# statement, just as if it were an ordinary user-defined table.
 
34
#
 
35
--source suite/funcs_1/datadict/is_table_query.inc
 
36
 
 
37
 
 
38
--echo #########################################################################
 
39
--echo # Testcase 3.2.6.1: INFORMATION_SCHEMA.COLUMNS layout
 
40
--echo #########################################################################
 
41
# Ensure that the INFORMATION_SCHEMA.COLUMNS table has the following columns,
 
42
# in the following order:
 
43
#
 
44
# TABLE_CATALOG (always shows NULL),
 
45
# TABLE_SCHEMA (shows the name of the database, or schema, in which an
 
46
#       accessible table resides),
 
47
# TABLE_NAME (shows the name of an accessible table),
 
48
# COLUMN_NAME (shows the name of a column within that table),
 
49
# ORDINAL_POSITION (shows the ordinal position of that column in that table),
 
50
# COLUMN_DEFAULT (shows the column's default value),
 
51
# IS_NULLABLE (shows whether the column may accept NULL values),
 
52
# DATA_TYPE (shows the column's defined data type; keyword only),
 
53
# CHARACTER_MAXIMUM_LENGTH (shows, for a string column, the column's defined
 
54
#       maximum length in characters; otherwise NULL),
 
55
# CHARACTER_OCTET_LENGTH (shows, for a string column, the column's defined
 
56
#       maximum length in octets; otherwise NULL),
 
57
# NUMERIC_PRECISION (shows, for a numeric column, the column's or data type's
 
58
#       defined precision; otherwise NULL),
 
59
# NUMERIC_SCALE (shows, for a numeric column, the column's or data type's
 
60
#       defined scale; otherwise NULL),
 
61
# CHARACTER_SET_NAME (shows, for a character string column, the column's default
 
62
#       character set; otherwise NULL),
 
63
# COLLATION_NAME (shows, for a character string column, the column's default
 
64
#       collation; otherwise NULL),
 
65
# COLUMN_TYPE (shows the column's complete, defined data type),
 
66
# COLUMN_KEY (shows whether the column is indexed; possible values are PRI if
 
67
#       the column is part of a PRIMARY KEY, UNI if the column is part of a
 
68
#       UNIQUE key, MUL if the column is part of an index key that allows
 
69
#       duplicates),
 
70
# EXTRA (shows any additional column definition information, e.g. whether the
 
71
#       column was defined with the AUTO_INCREMENT attribute),
 
72
# PRIVILEGES (shows the privileges available to the user on the column),
 
73
# COLUMN_COMMENT (shows the comment, if any, defined for the comment;
 
74
#       otherwise NULL).
 
75
# STORAGE (NDB specific)
 
76
# FORMAT (NDB specific)
 
77
#
 
78
--source suite/funcs_1/datadict/datadict_bug_12777.inc
 
79
eval DESCRIBE          information_schema.$is_table;
 
80
--source suite/funcs_1/datadict/datadict_bug_12777.inc
 
81
eval SHOW CREATE TABLE information_schema.$is_table;
 
82
--source suite/funcs_1/datadict/datadict_bug_12777.inc
 
83
eval SHOW COLUMNS FROM information_schema.$is_table;
 
84
 
 
85
# Note: Retrieval of information within information_schema.columns about
 
86
#       information_schema.columns is in is_columns_is.test.
 
87
 
 
88
# Show that TABLE_CATALOG is always NULL.
 
89
SELECT table_catalog, table_schema, table_name, column_name
 
90
FROM information_schema.columns WHERE table_catalog IS NOT NULL;
 
91
 
 
92
 
 
93
--echo ###############################################################################
 
94
--echo # Testcase 3.2.6.2 + 3.2.6.3: INFORMATION_SCHEMA.COLUMNS accessible information
 
95
--echo ###############################################################################
 
96
# 3.2.6.2:  Ensure that the table shows the relevant information on the columns
 
97
#           of every table that is accessible to the current user or to PUBLIC.
 
98
# 3.2.6.3:  Ensure that the table does not show any information on the columns
 
99
#           of any table which is not accessible to the current user or PUBLIC.
 
100
#
 
101
# Note: Check of content within information_schema.columns about
 
102
#       databases           is in
 
103
#       mysql               is_columns_mysql.test
 
104
#       information_schema  is_columns_is.test
 
105
#       test%               is_columns_<engine>.test
 
106
#
 
107
--disable_warnings
 
108
DROP DATABASE IF EXISTS db_datadict;
 
109
--enable_warnings
 
110
CREATE DATABASE db_datadict;
 
111
 
 
112
--error 0,ER_CANNOT_USER
 
113
DROP   USER 'testuser1'@'localhost';
 
114
CREATE USER 'testuser1'@'localhost';
 
115
--error 0,ER_CANNOT_USER
 
116
DROP   USER 'testuser2'@'localhost';
 
117
CREATE USER 'testuser2'@'localhost';
 
118
 
 
119
--replace_result $other_engine_type <other_engine_type>
 
120
eval
 
121
CREATE TABLE db_datadict.t1
 
122
   (f1 CHAR(10), f2 TEXT, f3 DATE, f4 INT AUTO_INCREMENT,
 
123
    UNIQUE INDEX MUL_IDX(f1,f3), PRIMARY KEY (f4))
 
124
ENGINE = $other_engine_type;
 
125
CREATE VIEW db_datadict.v1 AS SELECT 1 AS f1, 1 AS f2;
 
126
GRANT SELECT(f1, f2) ON db_datadict.t1 TO 'testuser1'@'localhost';
 
127
GRANT SELECT(f2)     ON db_datadict.v1 TO 'testuser1'@'localhost';
 
128
 
 
129
--replace_result $other_engine_type <other_engine_type>
 
130
eval
 
131
CREATE TABLE db_datadict.t2
 
132
(f1 CHAR(10), f2 TEXT, f3 DATE, f4 INT, PRIMARY KEY (f1,f4))
 
133
ENGINE = $other_engine_type;
 
134
GRANT INSERT(f1, f2) ON db_datadict.t2 TO 'testuser2'@'localhost';
 
135
 
 
136
let $my_select= SELECT * FROM information_schema.columns
 
137
             WHERE table_schema = 'db_datadict'
 
138
ORDER BY table_schema, table_name, ordinal_position;
 
139
let $my_show1 = SHOW COLUMNS FROM db_datadict.t1;
 
140
let $my_show2 = SHOW COLUMNS FROM db_datadict.t2;
 
141
let $my_show3 = SHOW COLUMNS FROM db_datadict.v1;
 
142
 
 
143
# Point of view of user root.
 
144
--source suite/funcs_1/datadict/datadict_bug_12777.inc
 
145
eval $my_select;
 
146
eval $my_show1;
 
147
eval $my_show2;
 
148
eval $my_show3;
 
149
 
 
150
--echo # Establish connection testuser1 (user=testuser1)
 
151
--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
 
152
connect (testuser1, localhost, testuser1, , db_datadict);
 
153
--source suite/funcs_1/datadict/datadict_bug_12777.inc
 
154
eval $my_select;
 
155
eval $my_show1;
 
156
--error ER_TABLEACCESS_DENIED_ERROR
 
157
eval $my_show2;
 
158
eval $my_show3;
 
159
 
 
160
--echo # Establish connection testuser2 (user=testuser2)
 
161
--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
 
162
connect (testuser2, localhost, testuser2, , db_datadict);
 
163
--source suite/funcs_1/datadict/datadict_bug_12777.inc
 
164
eval $my_select;
 
165
--error ER_TABLEACCESS_DENIED_ERROR
 
166
eval $my_show1;
 
167
eval $my_show2;
 
168
--error ER_TABLEACCESS_DENIED_ERROR
 
169
eval $my_show3;
 
170
 
 
171
--echo # Switch to connection default and close connections testuser1, testuser2
 
172
connection default;
 
173
disconnect testuser1;
 
174
disconnect testuser2;
 
175
 
 
176
# Cleanup
 
177
DROP USER 'testuser1'@'localhost';
 
178
DROP USER 'testuser2'@'localhost';
 
179
DROP DATABASE IF EXISTS db_datadict;
 
180
 
 
181
 
 
182
--echo ###############################################################################
 
183
--echo # Testcase 3.2.1.13+3.2.1.14+3.2.1.15: INFORMATION_SCHEMA.COLUMNS modifications
 
184
--echo ###############################################################################
 
185
# 3.2.1.13: Ensure that the creation of any new database object (e.g. table or
 
186
#           column) automatically inserts all relevant information on that
 
187
#           object into every appropriate INFORMATION_SCHEMA table.
 
188
# 3.2.1.14: Ensure that the alteration of any existing database object
 
189
#           automatically updates all relevant information on that object in
 
190
#           every appropriate INFORMATION_SCHEMA table.
 
191
# 3.2.1.15: Ensure that the dropping of any existing database object
 
192
#           automatically deletes all relevant information on that object from
 
193
#           every appropriate INFORMATION_SCHEMA table.
 
194
#
 
195
--disable_warnings
 
196
DROP TABLE IF EXISTS test.t1_my_table;
 
197
DROP DATABASE IF EXISTS db_datadict;
 
198
--enable_warnings
 
199
CREATE DATABASE db_datadict;
 
200
 
 
201
SELECT table_name FROM information_schema.columns
 
202
WHERE table_name LIKE 't1_my_table%';
 
203
--replace_result $engine_type <engine_type>
 
204
eval
 
205
CREATE TABLE test.t1_my_table (f1 CHAR(12))
 
206
DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci
 
207
ENGINE = $engine_type;
 
208
# Settings used in CREATE TABLE must be visible in information_schema.columns.
 
209
--vertical_results
 
210
SELECT * FROM information_schema.columns
 
211
WHERE table_name = 't1_my_table';
 
212
--horizontal_results
 
213
#
 
214
# Check modification of TABLE_NAME
 
215
SELECT table_name FROM information_schema.columns
 
216
WHERE table_name LIKE 't1_my_table%';
 
217
RENAME TABLE test.t1_my_table TO test.t1_my_tablex;
 
218
SELECT table_name FROM information_schema.columns
 
219
WHERE table_name LIKE 't1_my_table%';
 
220
#
 
221
# Check modification of TABLE_SCHEMA
 
222
SELECT table_schema,table_name FROM information_schema.columns
 
223
WHERE table_name = 't1_my_tablex';
 
224
RENAME TABLE test.t1_my_tablex TO db_datadict.t1_my_tablex;
 
225
SELECT table_schema,table_name FROM information_schema.columns
 
226
WHERE table_name = 't1_my_tablex';
 
227
#
 
228
# Check modification of COLUMN_NAME
 
229
SELECT table_name, column_name FROM information_schema.columns
 
230
WHERE table_name = 't1_my_tablex';
 
231
ALTER TABLE db_datadict.t1_my_tablex CHANGE COLUMN f1 first_col CHAR(12);
 
232
SELECT table_name, column_name FROM information_schema.columns
 
233
WHERE table_name = 't1_my_tablex';
 
234
#
 
235
# Check modification of COLUMN size
 
236
SELECT table_name, column_name, character_maximum_length,
 
237
       character_octet_length, column_type
 
238
FROM information_schema.columns
 
239
WHERE table_name = 't1_my_tablex';
 
240
ALTER TABLE db_datadict.t1_my_tablex
 
241
MODIFY COLUMN first_col CHAR(20);
 
242
SELECT table_name, column_name, character_maximum_length,
 
243
       character_octet_length, column_type
 
244
FROM information_schema.columns
 
245
WHERE table_name = 't1_my_tablex';
 
246
#
 
247
# Check modification of COLUMN type
 
248
SELECT table_name, column_name, character_maximum_length,
 
249
       character_octet_length, column_type
 
250
FROM information_schema.columns
 
251
WHERE table_name = 't1_my_tablex';
 
252
ALTER TABLE db_datadict.t1_my_tablex
 
253
MODIFY COLUMN first_col VARCHAR(20);
 
254
SELECT table_name, column_name, character_maximum_length,
 
255
       character_octet_length, column_type
 
256
FROM information_schema.columns
 
257
WHERE table_name = 't1_my_tablex';
 
258
#
 
259
# Check modify COLUMN DEFAULT
 
260
SELECT table_name, column_name, column_default
 
261
FROM information_schema.columns
 
262
WHERE table_name = 't1_my_tablex';
 
263
ALTER TABLE db_datadict.t1_my_tablex
 
264
MODIFY COLUMN first_col CHAR(10) DEFAULT 'hello';
 
265
SELECT table_name, column_name, column_default
 
266
FROM information_schema.columns
 
267
WHERE table_name = 't1_my_tablex';
 
268
#
 
269
# Check modify IS_NULLABLE
 
270
SELECT table_name, column_name, is_nullable
 
271
FROM information_schema.columns
 
272
WHERE table_name = 't1_my_tablex';
 
273
ALTER TABLE db_datadict.t1_my_tablex
 
274
MODIFY COLUMN first_col CHAR(10) NOT NULL;
 
275
SELECT table_name, column_name, is_nullable
 
276
FROM information_schema.columns
 
277
WHERE table_name = 't1_my_tablex';
 
278
#
 
279
# Check modify COLLATION
 
280
SELECT table_name, column_name, collation_name
 
281
FROM information_schema.columns
 
282
WHERE table_name = 't1_my_tablex';
 
283
ALTER TABLE db_datadict.t1_my_tablex
 
284
MODIFY COLUMN first_col CHAR(10) COLLATE 'latin1_general_cs';
 
285
SELECT table_name, column_name, collation_name
 
286
FROM information_schema.columns
 
287
WHERE table_name = 't1_my_tablex';
 
288
#
 
289
# Check modify CHARACTER SET
 
290
SELECT table_name, column_name, character_maximum_length,
 
291
       character_octet_length, character_set_name
 
292
FROM information_schema.columns
 
293
WHERE table_name = 't1_my_tablex';
 
294
ALTER TABLE db_datadict.t1_my_tablex
 
295
MODIFY COLUMN first_col CHAR(10) CHARACTER SET utf8;
 
296
SELECT table_name, column_name, character_maximum_length,
 
297
       character_octet_length, character_set_name
 
298
FROM information_schema.columns
 
299
WHERE table_name = 't1_my_tablex';
 
300
#
 
301
# Check modify COLUMN_COMMENT
 
302
SELECT table_name, column_name, column_comment
 
303
FROM information_schema.columns
 
304
WHERE table_name = 't1_my_tablex';
 
305
ALTER TABLE db_datadict.t1_my_tablex
 
306
MODIFY COLUMN first_col CHAR(10) COMMENT 'Hello';
 
307
SELECT table_name, column_name, column_comment
 
308
FROM information_schema.columns
 
309
WHERE table_name = 't1_my_tablex';
 
310
#
 
311
# Check ADD COLUMN
 
312
SELECT table_name, column_name
 
313
FROM information_schema.columns
 
314
WHERE table_name = 't1_my_tablex';
 
315
ALTER TABLE db_datadict.t1_my_tablex
 
316
ADD COLUMN second_col CHAR(10);
 
317
SELECT table_name, column_name
 
318
FROM information_schema.columns
 
319
WHERE table_name = 't1_my_tablex';
 
320
#
 
321
# Check switch ordinal position of column
 
322
SELECT table_name, column_name, ordinal_position
 
323
FROM information_schema.columns
 
324
WHERE table_name = 't1_my_tablex'
 
325
ORDER BY table_name, column_name;
 
326
ALTER TABLE db_datadict.t1_my_tablex
 
327
MODIFY COLUMN second_col CHAR(10) FIRST;
 
328
SELECT table_name, column_name, ordinal_position
 
329
FROM information_schema.columns
 
330
WHERE table_name = 't1_my_tablex'
 
331
ORDER BY table_name, column_name;
 
332
#
 
333
# Check DROP COLUMN
 
334
SELECT table_name, column_name
 
335
FROM information_schema.columns
 
336
WHERE table_name = 't1_my_tablex';
 
337
ALTER TABLE db_datadict.t1_my_tablex
 
338
DROP COLUMN first_col;
 
339
SELECT table_name, column_name
 
340
FROM information_schema.columns
 
341
WHERE table_name = 't1_my_tablex';
 
342
#
 
343
# Check set COLUMN UNIQUE
 
344
SELECT table_name, column_name, column_key
 
345
FROM information_schema.columns
 
346
WHERE table_name = 't1_my_tablex';
 
347
ALTER TABLE db_datadict.t1_my_tablex
 
348
ADD UNIQUE INDEX IDX(second_col);
 
349
SELECT table_name, column_name, column_key
 
350
FROM information_schema.columns
 
351
WHERE table_name = 't1_my_tablex';
 
352
#
 
353
# Check impact of DROP TABLE
 
354
SELECT table_name, column_name
 
355
FROM information_schema.columns
 
356
WHERE table_name = 't1_my_tablex';
 
357
DROP TABLE db_datadict.t1_my_tablex;
 
358
SELECT table_name, column_name
 
359
FROM information_schema.columns
 
360
WHERE table_name = 't1_my_tablex';
 
361
#
 
362
# Check a VIEW
 
363
CREATE VIEW test.t1_my_tablex
 
364
AS SELECT 1 AS "col1", 'A' collate latin1_german1_ci AS "col2";
 
365
--vertical_results
 
366
SELECT * FROM information_schema.columns
 
367
WHERE table_name = 't1_my_tablex'
 
368
ORDER BY table_name, column_name;
 
369
--horizontal_results
 
370
DROP VIEW test.t1_my_tablex;
 
371
SELECT table_name FROM information_schema.columns
 
372
WHERE table_name = 't1_my_tablex';
 
373
#
 
374
# Check impact of DROP SCHEMA
 
375
--replace_result $engine_type <engine_type>
 
376
eval
 
377
CREATE TABLE db_datadict.t1_my_tablex
 
378
ENGINE = $engine_type AS
 
379
SELECT 1;
 
380
SELECT table_name FROM information_schema.columns
 
381
WHERE table_name = 't1_my_tablex';
 
382
DROP DATABASE db_datadict;
 
383
SELECT table_name FROM information_schema.columns
 
384
WHERE table_name = 't1_my_tablex';
 
385
 
 
386
 
 
387
--echo ########################################################################
 
388
--echo # Testcases 3.2.1.3-3.2.1.5 + 3.2.1.8-3.2.1.12: INSERT/UPDATE/DELETE and
 
389
--echo #           DDL on INFORMATION_SCHEMA table are not supported
 
390
--echo ########################################################################
 
391
# 3.2.1.3:  Ensure that no user may execute an INSERT statement on any
 
392
#           INFORMATION_SCHEMA table.
 
393
# 3.2.1.4:  Ensure that no user may execute an UPDATE statement on any
 
394
#           INFORMATION_SCHEMA table.
 
395
# 3.2.1.5:  Ensure that no user may execute a DELETE statement on any
 
396
#           INFORMATION_SCHEMA table.
 
397
# 3.2.1.8:  Ensure that no user may create an index on an
 
398
#           INFORMATION_SCHEMA table.
 
399
# 3.2.1.9:  Ensure that no user may alter the definition of an
 
400
#           INFORMATION_SCHEMA table.
 
401
# 3.2.1.10: Ensure that no user may drop an INFORMATION_SCHEMA table.
 
402
# 3.2.1.11: Ensure that no user may move an INFORMATION_SCHEMA table to any
 
403
#           other database.
 
404
# 3.2.1.12: Ensure that no user may directly add to, alter, or delete any data
 
405
#           in an INFORMATION_SCHEMA table.
 
406
#
 
407
--disable_warnings
 
408
DROP DATABASE IF EXISTS db_datadict;
 
409
DROP TABLE IF EXISTS test.t1;
 
410
--enable_warnings
 
411
CREATE DATABASE db_datadict;
 
412
CREATE TABLE test.t1 (f1 BIGINT);
 
413
 
 
414
--error ER_DBACCESS_DENIED_ERROR
 
415
INSERT INTO information_schema.columns (table_schema,table_name,column_name)
 
416
VALUES('test','t1', 'f2');
 
417
--error ER_DBACCESS_DENIED_ERROR
 
418
INSERT INTO information_schema.columns (table_schema,table_name,column_name)
 
419
VALUES('test','t2', 'f1');
 
420
 
 
421
--error ER_DBACCESS_DENIED_ERROR
 
422
UPDATE information_schema.columns SET table_name = 't4' WHERE table_name = 't1';
 
423
 
 
424
--error ER_DBACCESS_DENIED_ERROR
 
425
DELETE FROM information_schema.columns WHERE table_name = 't1';
 
426
--error ER_DBACCESS_DENIED_ERROR
 
427
TRUNCATE information_schema.columns;
 
428
 
 
429
--error ER_DBACCESS_DENIED_ERROR
 
430
CREATE INDEX i3 ON information_schema.columns(table_name);
 
431
 
 
432
--error ER_DBACCESS_DENIED_ERROR
 
433
ALTER TABLE information_schema.columns ADD f1 INT;
 
434
 
 
435
--error ER_DBACCESS_DENIED_ERROR
 
436
DROP TABLE information_schema.columns;
 
437
 
 
438
--error ER_DBACCESS_DENIED_ERROR
 
439
ALTER TABLE information_schema.columns RENAME db_datadict.columns;
 
440
--error ER_DBACCESS_DENIED_ERROR
 
441
ALTER TABLE information_schema.columns RENAME information_schema.xcolumns;
 
442
 
 
443
# Cleanup
 
444
DROP TABLE test.t1;
 
445
DROP DATABASE db_datadict;
 
446