mariadb/mysql-test/suite/funcs_1/triggers/triggers_03e_prepare.inc

179 lines
5.4 KiB
PHP
Raw Normal View History

#======================================================================
#
# Trigger Tests
# test cases for TRIGGER privilege on db, table and column level
# These tests ensure that at activation time (execute statement)
# the user must have trigger privilege.
#======================================================================
--disable_abort_on_error
###########################################################
################ Section 3.5.3 ############################
# Check for the trigger privilege in case of prepare/exec #
###########################################################
# General setup to be used in all testcases
let $message= #### Testcase for trigger privilege on execution time ########;
--source include/show_msg.inc
--disable_warnings
drop database if exists priv_db;
--enable_warnings
create database priv_db;
use priv_db;
eval create table t1 (f1 char(20)) engine= $engine_type;
create User test_yesprivs@localhost;
set password for test_yesprivs@localhost = password('PWD');
create User test_useprivs@localhost;
set password for test_useprivs@localhost = password('PWD');
revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
revoke ALL PRIVILEGES, GRANT OPTION FROM test_useprivs@localhost;
connect (yes_privs,localhost,test_yesprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
connection default;
select current_user;
MDEV-6112 multiple triggers per table This is similar to MysQL Worklog 3253, but with a different implementation. The disk format and SQL syntax is identical with MySQL 5.7. Fetures supported: - "Any" ammount of any trigger - Supports FOLLOWS and PRECEDES to be able to put triggers in a certain execution order. Implementation details: - Class Trigger added to hold information about a trigger. Before this trigger information was stored in a set of lists in Table_triggers_list and in Table_triggers_list::bodies - Each Trigger has a next field that poinst to the next Trigger with the same action and time. - When accessing a trigger, we now always access all linked triggers - The list are now only used to load and save trigger files. - MySQL trigger test case (trigger_wl3253) added and we execute these identically. - Even more gracefully handling of wrong trigger files than before. This is useful if a trigger file uses functions or syntax not provided by the server. - Each trigger now has a "Created" field that shows when the trigger was created, with 2 decimals. Other comments: - Many of the changes in test files was done because of the new "Created" field in the trigger file. This shows up in SHOW ... TRIGGER and when using information_schema.trigger. - Don't check if all memory is released if on uses --gdb; This is needed to be able to get a list from safemalloc of not freed memory while debugging. - Added option to trim_whitespace() to know how many prefix characters was skipped. - Changed a few ulonglong sql_mode to sql_mode_t, to find some wrong usage of sql_mode.
2016-10-02 15:35:08 +03:00
--replace_column 6 #
show triggers;
grant select, insert, update ,trigger
on priv_db.t1 to test_yesprivs@localhost
with grant option;
grant select
on priv_db.t1 to test_useprivs@localhost;
show grants for test_yesprivs@localhost;
connection yes_privs;
select current_user;
use priv_db;
create trigger trg1_1 before INSERT on t1 for each row
set new.f1 = 'trig 1_1-yes';
grant insert on t1 to test_useprivs@localhost;
prepare ins1 from 'insert into t1 (f1) values (''insert1-no'')';
execute ins1;
select f1 from t1 order by f1;
prepare ins1 from 'insert into t1 (f1) values (''insert2-no'')';
connect (use_privs,localhost,test_useprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
select current_user;
use priv_db;
prepare ins1 from 'insert into t1 (f1) values (''insert3-no'')';
execute ins1;
select f1 from t1 order by f1;
connection default;
select current_user;
revoke TRIGGER on priv_db.t1 from test_yesprivs@localhost;
show grants for test_yesprivs@localhost;
connection yes_privs;
select current_user;
--error ER_TABLEACCESS_DENIED_ERROR
execute ins1;
select f1 from t1 order by f1;
prepare ins1 from 'insert into t1 (f1) values (''insert4-no'')';
connection use_privs;
select current_user;
prepare ins1 from 'insert into t1 (f1) values (''insert5-no'')';
--error ER_TABLEACCESS_DENIED_ERROR
execute ins1;
select f1 from t1 order by f1;
connection default;
select current_user;
grant TRIGGER on priv_db.t1 to test_yesprivs@localhost;
show grants for test_yesprivs@localhost;
connection yes_privs;
select current_user;
execute ins1;
select f1 from t1 order by f1;
prepare ins1 from 'insert into t1 (f1) values (''insert6-no'')';
connection use_privs;
select current_user;
execute ins1;
select f1 from t1 order by f1;
prepare ins1 from 'insert into t1 (f1) values (''insert7-no'')';
connection default;
select current_user;
revoke TRIGGER on priv_db.t1 from test_yesprivs@localhost;
show grants for test_yesprivs@localhost;
connection yes_privs;
select current_user;
--error ER_TABLEACCESS_DENIED_ERROR
execute ins1;
select f1 from t1 order by f1;
connection use_privs;
select current_user;
--error ER_TABLEACCESS_DENIED_ERROR
execute ins1;
select f1 from t1 order by f1;
connection default;
select current_user;
grant TRIGGER on priv_db.t1 to test_yesprivs@localhost;
show grants for test_yesprivs@localhost;
connection yes_privs;
select current_user;
execute ins1;
select f1 from t1 order by f1;
connection use_privs;
select current_user;
execute ins1;
select f1 from t1 order by f1;
connection default;
select current_user;
revoke TRIGGER on priv_db.t1 from test_yesprivs@localhost;
show grants for test_yesprivs@localhost;
connection yes_privs;
select current_user;
execute ins1;
select f1 from t1 order by f1;
deallocate prepare ins1;
connection use_privs;
select current_user;
execute ins1;
select f1 from t1 order by f1;
deallocate prepare ins1;
connection default;
select current_user;
grant TRIGGER on priv_db.t1 to test_yesprivs@localhost;
show grants for test_yesprivs@localhost;
connection yes_privs;
select current_user;
drop trigger trg1_1;
connection default;
select current_user;
# Cleanup prepare
--disable_warnings
disconnect yes_privs;
connection default;
select current_user;
--enable_warnings
# general Cleanup
--disable_warnings
drop database if exists priv_db;
drop user test_yesprivs@localhost;
drop user test_useprivs@localhost;
--enable_warnings