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