<div class="news_item">#207<div class="news_title">MySQL: CREATE TRIGGER `some_table___select` BEFORE SELECT ON `some_table`
Posted by dandriff on Monday February 18, 2008@03:56PM
I just found a really interesting BLAHG post by some guy who did some sneaky mysql functionry to emulate CREATE TRIGGER `some_table___select` BEFORE SELECT ON `some_table` functionality in mysql.
Hm, the article contained in the link above was written in mid-late-2005. It is now the beginnig of 2008. I wondered if his little khack would still work..
The first step worked fine. Once I hit the function creation step, I ran into a problem though:
mysql> create function f_log_select(
-> p_log_schema varchar(64)
-> , p_log_view varchar(64)
-> )
-> returns int unsigned
-> NOT DETERMINISTIC
-> begin
-> insert
-> into select_log(
-> log_who
-> , log_conn
-> , log_when
-> , log_schema
-> , log_view
-> ) values (
-> current_user()
-> , connection_id()
-> , now()
-> , p_log_schema
-> , p_log_view
-> );
-> return last_insert_id();
-> end;
-> $$
ERROR 1418 (HY000): This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its
declaration and binary logging is enabled (you *might* want to use the less safe
log_bin_trust_function_creators variable)
SET GLOBAL log_bin_trust_function_creators=1;
I followed the rest of the steps documented and I can confirm that as of February, 2008, MySQL 5.x still allows this functionality/behavior!
Very neat indeed!