~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_triggers.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_triggers.test
 
2
#
 
3
# Check the layout of information_schema.triggers and the impact of
 
4
# CREATE/ALTER/DROP TABLE/VIEW/SCHEMA ... on it.
 
5
#
 
6
# Note:
 
7
#    This test is not intended
 
8
#    - to show information about the all time existing triggers
 
9
#      (there are no in the moment) within the databases information_schema
 
10
#      and mysql
 
11
#    - for checking storage engine properties
 
12
#      Therefore please do not alter $engine_type and $other_engine_type.
 
13
#
 
14
# Author:
 
15
# 2008-01-23 mleich WL#4203 Reorganize and fix the data dictionary tests of
 
16
#                           testsuite funcs_1
 
17
#                   Create this script based on older scripts and new code.
 
18
#
 
19
 
 
20
# --source suite/funcs_1/datadict/datadict.pre
 
21
 
 
22
let $engine_type       = MEMORY;
 
23
let $other_engine_type = MyISAM;
 
24
 
 
25
let $is_table = TRIGGERS;
 
26
 
 
27
# The table INFORMATION_SCHEMA.TRIGGERS 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.12.1: INFORMATION_SCHEMA.TRIGGERS layout
 
41
--echo #########################################################################
 
42
# Ensure that the INFORMATION_SCHEMA.TRIGGERS table has the following columns,
 
43
# in the following order:
 
44
#
 
45
# TRIGGER_CATALOG             NULL
 
46
# TRIGGER_SCHEMA              name of the database in which the trigger occurs
 
47
# TRIGGER_NAME
 
48
# EVENT_MANIPULATION          event associated with the trigger
 
49
#                             ('INSERT', 'DELETE', or 'UPDATE')
 
50
# EVENT_OBJECT_CATALOG        NULL
 
51
# EVENT_OBJECT_SCHEMA         database in which the table associated with the
 
52
#                             trigger occurs
 
53
# EVENT_OBJECT_TABLE          name of the table associated with the trigger
 
54
# ACTION_ORDER                0
 
55
# ACTION_CONDITION            NULL
 
56
# ACTION_STATEMENT
 
57
# ACTION_ORIENTATION          ROW
 
58
# ACTION_TIMING               'BEFORE' or 'AFTER'
 
59
# ACTION_REFERENCE_OLD_TABLE  NULL
 
60
# ACTION_REFERENCE_NEW_TABLE  NULL
 
61
# ACTION_REFERENCE_OLD_ROW    OLD
 
62
# ACTION_REFERENCE_NEW_ROW    NEW
 
63
# CREATED                     NULL (0)
 
64
# SQL_MODE                    server SQL mode that was in effect at the time
 
65
#                             when the trigger was created
 
66
#                             (also used during trigger execution)
 
67
# DEFINER                     who defined the trigger
 
68
#
 
69
--source suite/funcs_1/datadict/datadict_bug_12777.inc
 
70
eval DESCRIBE          information_schema.$is_table;
 
71
--source suite/funcs_1/datadict/datadict_bug_12777.inc
 
72
eval SHOW CREATE TABLE information_schema.$is_table;
 
73
--source suite/funcs_1/datadict/datadict_bug_12777.inc
 
74
eval SHOW COLUMNS FROM information_schema.$is_table;
 
75
 
 
76
 
 
77
# Note: Retrieval of information within information_schema.columns about
 
78
#       information_schema.tables is in is_columns_is.test.
 
79
 
 
80
# Show that several columns are always NULL.
 
81
SELECT * FROM information_schema.triggers
 
82
WHERE trigger_catalog IS NOT NULL OR event_object_catalog IS NOT NULL
 
83
   OR action_condition IS NOT NULL OR action_reference_old_table IS NOT NULL
 
84
   OR action_reference_new_table IS NOT NULL;
 
85
 
 
86
 
 
87
--echo ##################################################################################
 
88
--echo # Testcase 3.2.18.2 + 3.2.18.3: INFORMATION_SCHEMA.TRIGGERS accessible information
 
89
--echo ##################################################################################
 
90
# 3.2.18.2: Ensure that the table shows the relevant information on every
 
91
#           trigger on which the current user or PUBLIC has privileges.
 
92
# 3.2.18.3: Ensure that the table does not show any information on any trigger
 
93
#           on which the current user and public have no privileges.
 
94
# The SUPER (before 5.1.22) or TRIGGER (since 5.1.22) privilege is required for
 
95
# - creation of triggers
 
96
# - retrieval in INFORMATION_SCHEMA.TRIGGERS (affects size of result set)
 
97
#
 
98
--disable_warnings
 
99
DROP DATABASE IF EXISTS db_datadict;
 
100
--enable_warnings
 
101
CREATE DATABASE db_datadict;
 
102
--error 0,ER_CANNOT_USER
 
103
DROP   USER 'testuser1'@'localhost';
 
104
CREATE USER 'testuser1'@'localhost';
 
105
--error 0,ER_CANNOT_USER
 
106
DROP   USER 'testuser2'@'localhost';
 
107
CREATE USER 'testuser2'@'localhost';
 
108
--error 0,ER_CANNOT_USER
 
109
DROP   USER 'testuser3'@'localhost';
 
110
CREATE USER 'testuser3'@'localhost';
 
111
--error 0,ER_CANNOT_USER
 
112
DROP   USER 'testuser4'@'localhost';
 
113
CREATE USER 'testuser4'@'localhost';
 
114
 
 
115
GRANT TRIGGER ON *.* TO 'testuser1'@'localhost';
 
116
GRANT TRIGGER ON *.* TO 'testuser3'@'localhost';
 
117
GRANT TRIGGER ON *.* TO 'testuser4'@'localhost';
 
118
GRANT ALL ON db_datadict.* TO 'testuser1'@'localhost' WITH GRANT OPTION;
 
119
 
 
120
let $my_select = SELECT * FROM information_schema.triggers
 
121
WHERE trigger_name = 'trg1';
 
122
let $my_show =   SHOW TRIGGERS FROM db_datadict;
 
123
--echo # Establish connection testuser1 (user=testuser1)
 
124
--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
 
125
connect (testuser1, localhost, testuser1, , db_datadict);
 
126
--replace_result $engine_type <engine_type>
 
127
eval
 
128
CREATE TABLE db_datadict.t1 (f1 INT, f2 INT, f3 INT)
 
129
ENGINE = $engine_type;
 
130
CREATE TRIGGER trg1 BEFORE INSERT
 
131
ON db_datadict.t1 FOR EACH ROW SET @test_before = 2, new.f1 = @test_before;
 
132
GRANT ALL ON db_datadict.t1 TO 'testuser2'@'localhost';
 
133
REVOKE TRIGGER ON db_datadict.t1 FROM 'testuser2'@'localhost';
 
134
GRANT SELECT ON db_datadict.t1 TO 'testuser3'@'localhost';
 
135
eval $my_select;
 
136
eval $my_show;
 
137
 
 
138
--echo # Establish connection testuser2 (user=testuser2)
 
139
--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
 
140
connect (testuser2, localhost, testuser2, , db_datadict);
 
141
SHOW GRANTS FOR 'testuser2'@'localhost';
 
142
--echo # No TRIGGER Privilege --> no result for query
 
143
eval $my_select;
 
144
eval $my_show;
 
145
 
 
146
--echo # Establish connection testuser3 (user=testuser3)
 
147
--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
 
148
connect (testuser3, localhost, testuser3, , test);
 
149
SHOW GRANTS FOR 'testuser3'@'localhost';
 
150
--echo # TRIGGER Privilege + SELECT Privilege on t1 --> result for query
 
151
eval $my_select;
 
152
eval $my_show;
 
153
 
 
154
--echo # Establish connection testuser4 (user=testuser4)
 
155
--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
 
156
connect (testuser4, localhost, testuser4, , test);
 
157
SHOW GRANTS FOR 'testuser4'@'localhost';
 
158
--echo # TRIGGER Privilege + no SELECT Privilege on t1 --> result for query
 
159
--disable_abort_on_error
 
160
SELECT * FROM db_datadict.t1;
 
161
DESC db_datadict.t1;
 
162
eval $my_select;
 
163
eval $my_show;
 
164
 
 
165
--echo # Switch to connection default and close connections testuser1 - testuser4
 
166
connection default;
 
167
disconnect testuser1;
 
168
disconnect testuser2;
 
169
disconnect testuser3;
 
170
disconnect testuser4;
 
171
eval $my_select;
 
172
eval $my_show;
 
173
DROP USER 'testuser1'@'localhost';
 
174
DROP USER 'testuser2'@'localhost';
 
175
DROP USER 'testuser3'@'localhost';
 
176
DROP USER 'testuser4'@'localhost';
 
177
DROP DATABASE db_datadict;
 
178
 
 
179
 
 
180
--echo #########################################################################
 
181
--echo # 3.2.1.13+3.2.1.14+3.2.1.15: INFORMATION_SCHEMA.TRIGGERS modifications
 
182
--echo #########################################################################
 
183
# 3.2.1.13: Ensure that the creation of any new database object (e.g. table or
 
184
#           column) automatically inserts all relevant information on that
 
185
#           object into every appropriate INFORMATION_SCHEMA table.
 
186
# 3.2.1.14: Ensure that the alteration of any existing database object
 
187
#           automatically updates all relevant information on that object in
 
188
#           every appropriate INFORMATION_SCHEMA table.
 
189
# 3.2.1.15: Ensure that the dropping of any existing database object
 
190
#           automatically deletes all relevant information on that object from
 
191
#           every appropriate INFORMATION_SCHEMA table.
 
192
# FIXME: To be implemented
 
193
 
 
194
 
 
195
--echo ########################################################################
 
196
--echo # Testcases 3.2.1.3-3.2.1.5 + 3.2.1.8-3.2.1.12: INSERT/UPDATE/DELETE and
 
197
--echo #           DDL on INFORMATION_SCHEMA tables are not supported
 
198
--echo ########################################################################
 
199
# 3.2.1.3:  Ensure that no user may execute an INSERT statement on any
 
200
#           INFORMATION_SCHEMA table.
 
201
# 3.2.1.4:  Ensure that no user may execute an UPDATE statement on any
 
202
#           INFORMATION_SCHEMA table.
 
203
# 3.2.1.5:  Ensure that no user may execute a DELETE statement on any
 
204
#           INFORMATION_SCHEMA table.
 
205
# 3.2.1.8:  Ensure that no user may create an index on an
 
206
#           INFORMATION_SCHEMA table.
 
207
# 3.2.1.9:  Ensure that no user may alter the definition of an
 
208
#           INFORMATION_SCHEMA table.
 
209
# 3.2.1.10: Ensure that no user may drop an INFORMATION_SCHEMA table.
 
210
# 3.2.1.11: Ensure that no user may move an INFORMATION_SCHEMA table to any
 
211
#           other database.
 
212
# 3.2.1.12: Ensure that no user may directly add to, alter, or delete any data
 
213
#           in an INFORMATION_SCHEMA table.
 
214
#
 
215
--disable_warnings
 
216
DROP DATABASE IF EXISTS db_datadict;
 
217
--enable_warnings
 
218
CREATE DATABASE db_datadict;
 
219
--replace_result $engine_type <engine_type>
 
220
eval
 
221
CREATE TABLE db_datadict.t1 (f1 BIGINT)
 
222
ENGINE = $engine_type;
 
223
CREATE TRIGGER db_datadict.trg1 BEFORE INSERT
 
224
ON db_datadict.t1 FOR EACH ROW SET @test_before = 2, new.f1 = @test_before;
 
225
 
 
226
--error ER_DBACCESS_DENIED_ERROR
 
227
INSERT INTO information_schema.triggers
 
228
SELECT * FROM information_schema.triggers;
 
229
 
 
230
--error ER_DBACCESS_DENIED_ERROR
 
231
UPDATE information_schema.triggers SET trigger_schema = 'test'
 
232
WHERE table_name = 't1';
 
233
 
 
234
--error ER_DBACCESS_DENIED_ERROR
 
235
DELETE FROM information_schema.triggers WHERE trigger_name = 't1';
 
236
--error ER_DBACCESS_DENIED_ERROR
 
237
TRUNCATE information_schema.triggers;
 
238
 
 
239
--error ER_DBACCESS_DENIED_ERROR
 
240
CREATE INDEX my_idx_on_triggers ON information_schema.triggers(trigger_schema);
 
241
 
 
242
--error ER_DBACCESS_DENIED_ERROR
 
243
ALTER TABLE information_schema.triggers DROP PRIMARY KEY;
 
244
--error ER_DBACCESS_DENIED_ERROR
 
245
ALTER TABLE information_schema.triggers ADD f1 INT;
 
246
 
 
247
--error ER_DBACCESS_DENIED_ERROR
 
248
DROP TABLE information_schema.triggers;
 
249
 
 
250
--error ER_DBACCESS_DENIED_ERROR
 
251
ALTER TABLE information_schema.triggers RENAME db_datadict.triggers;
 
252
--error ER_DBACCESS_DENIED_ERROR
 
253
ALTER TABLE information_schema.triggers RENAME information_schema.xtriggers;
 
254
 
 
255
# Cleanup
 
256
DROP DATABASE db_datadict;
 
257