Debian Codegraph @

mysql-test/suite/funcs_1/datadict/is_triggers.inc

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