Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mariadb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
mariadb
Commits
4ca34093
Commit
4ca34093
authored
Feb 26, 2006
by
dlenev@mysql.com
Browse files
Options
Browse Files
Download
Plain Diff
Merge bk-internal.mysql.com:/home/bk/mysql-5.0-runtime
into mysql.com:/home/dlenev/src/mysql-5.0-bg13525
parents
49ad134e
480dcb7f
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
513 additions
and
36 deletions
+513
-36
mysql-test/r/trigger.result
mysql-test/r/trigger.result
+102
-1
mysql-test/t/trigger.test
mysql-test/t/trigger.test
+86
-1
sql/sql_rename.cc
sql/sql_rename.cc
+21
-2
sql/sql_table.cc
sql/sql_table.cc
+12
-1
sql/sql_trigger.cc
sql/sql_trigger.cc
+269
-21
sql/sql_trigger.h
sql/sql_trigger.h
+16
-1
sql/sql_yacc.yy
sql/sql_yacc.yy
+7
-9
No files found.
mysql-test/r/trigger.result
View file @
4ca34093
drop table if exists t1, t2, t3;
drop table if exists t1, t2, t3
, t4
;
drop view if exists v1;
drop database if exists mysqltest;
drop function if exists f1;
...
...
@@ -785,6 +785,107 @@ create trigger test.t1_bi before insert on t1 for each row set @a:=0;
ERROR 3D000: No database selected
drop trigger t1_bi;
ERROR 3D000: No database selected
create table t1 (id int);
create trigger t1_bi before insert on t1 for each row set @a:=new.id;
insert into t1 values (101);
select @a;
@a
101
select trigger_schema, trigger_name, event_object_schema,
event_object_table, action_statement from information_schema.triggers
where event_object_schema = 'test';
trigger_schema trigger_name event_object_schema event_object_table action_statement
test t1_bi test t1 set @a:=new.id
rename table t1 to t2;
insert into t2 values (102);
select @a;
@a
102
select trigger_schema, trigger_name, event_object_schema,
event_object_table, action_statement from information_schema.triggers
where event_object_schema = 'test';
trigger_schema trigger_name event_object_schema event_object_table action_statement
test t1_bi test t2 set @a:=new.id
alter table t2 rename to t3;
insert into t3 values (103);
select @a;
@a
103
select trigger_schema, trigger_name, event_object_schema,
event_object_table, action_statement from information_schema.triggers
where event_object_schema = 'test';
trigger_schema trigger_name event_object_schema event_object_table action_statement
test t1_bi test t3 set @a:=new.id
alter table t3 rename to t4, add column val int default 0;
insert into t4 values (104, 1);
select @a;
@a
104
select trigger_schema, trigger_name, event_object_schema,
event_object_table, action_statement from information_schema.triggers
where event_object_schema = 'test';
trigger_schema trigger_name event_object_schema event_object_table action_statement
test t1_bi test t4 set @a:=new.id
drop trigger t1_bi;
drop table t4;
create database mysqltest;
use mysqltest;
create table t1 (id int);
create trigger t1_bi before insert on t1 for each row set @a:=new.id;
insert into t1 values (101);
select @a;
@a
101
select trigger_schema, trigger_name, event_object_schema,
event_object_table, action_statement from information_schema.triggers
where event_object_schema = 'test' or event_object_schema = 'mysqltest';
trigger_schema trigger_name event_object_schema event_object_table action_statement
mysqltest t1_bi mysqltest t1 set @a:=new.id
rename table t1 to test.t2;
ERROR HY000: Trigger in wrong schema
insert into t1 values (102);
select @a;
@a
102
select trigger_schema, trigger_name, event_object_schema,
event_object_table, action_statement from information_schema.triggers
where event_object_schema = 'test' or event_object_schema = 'mysqltest';
trigger_schema trigger_name event_object_schema event_object_table action_statement
mysqltest t1_bi mysqltest t1 set @a:=new.id
drop trigger test.t1_bi;
ERROR HY000: Trigger does not exist
drop trigger t1_bi;
drop table t1;
drop database mysqltest;
use test;
create table t1 (id int);
create trigger t1_bi before insert on t1 for each row set @a:=new.id;
create trigger t1_ai after insert on t1 for each row set @b:=new.id;
insert into t1 values (101);
select @a, @b;
@a @b
101 101
select trigger_schema, trigger_name, event_object_schema,
event_object_table, action_statement from information_schema.triggers
where event_object_schema = 'test';
trigger_schema trigger_name event_object_schema event_object_table action_statement
test t1_bi test t1 set @a:=new.id
test t1_ai test t1 set @b:=new.id
rename table t1 to t2;
ERROR HY000: Can't create/write to file './test/t1_ai.TRN~' (Errcode: 13)
insert into t1 values (102);
select @a, @b;
@a @b
102 102
select trigger_schema, trigger_name, event_object_schema,
event_object_table, action_statement from information_schema.triggers
where event_object_schema = 'test';
trigger_schema trigger_name event_object_schema event_object_table action_statement
test t1_bi test t1 set @a:=new.id
test t1_ai test t1 set @b:=new.id
drop trigger t1_bi;
drop trigger t1_ai;
drop table t1;
create table t1 (i int);
create trigger t1_bi before insert on t1 for each row return 0;
ERROR 42000: RETURN is only allowed in a FUNCTION
...
...
mysql-test/t/trigger.test
View file @
4ca34093
...
...
@@ -3,7 +3,7 @@
#
--
disable_warnings
drop
table
if
exists
t1
,
t2
,
t3
;
drop
table
if
exists
t1
,
t2
,
t3
,
t4
;
drop
view
if
exists
v1
;
drop
database
if
exists
mysqltest
;
drop
function
if
exists
f1
;
...
...
@@ -959,6 +959,91 @@ create trigger test.t1_bi before insert on t1 for each row set @a:=0;
drop
trigger
t1_bi
;
connection
default
;
#
# Test for bug #13525 "Rename table does not keep info of triggers"
#
create
table
t1
(
id
int
);
create
trigger
t1_bi
before
insert
on
t1
for
each
row
set
@
a
:=
new
.
id
;
insert
into
t1
values
(
101
);
select
@
a
;
select
trigger_schema
,
trigger_name
,
event_object_schema
,
event_object_table
,
action_statement
from
information_schema
.
triggers
where
event_object_schema
=
'test'
;
rename
table
t1
to
t2
;
# Trigger should work after rename
insert
into
t2
values
(
102
);
select
@
a
;
select
trigger_schema
,
trigger_name
,
event_object_schema
,
event_object_table
,
action_statement
from
information_schema
.
triggers
where
event_object_schema
=
'test'
;
# Let us check that the same works for simple ALTER TABLE ... RENAME
alter
table
t2
rename
to
t3
;
insert
into
t3
values
(
103
);
select
@
a
;
select
trigger_schema
,
trigger_name
,
event_object_schema
,
event_object_table
,
action_statement
from
information_schema
.
triggers
where
event_object_schema
=
'test'
;
# And for more complex ALTER TABLE
alter
table
t3
rename
to
t4
,
add
column
val
int
default
0
;
insert
into
t4
values
(
104
,
1
);
select
@
a
;
select
trigger_schema
,
trigger_name
,
event_object_schema
,
event_object_table
,
action_statement
from
information_schema
.
triggers
where
event_object_schema
=
'test'
;
# .TRN file should be updated with new table name
drop
trigger
t1_bi
;
drop
table
t4
;
# Rename between different databases if triggers exist should fail
create
database
mysqltest
;
use
mysqltest
;
create
table
t1
(
id
int
);
create
trigger
t1_bi
before
insert
on
t1
for
each
row
set
@
a
:=
new
.
id
;
insert
into
t1
values
(
101
);
select
@
a
;
select
trigger_schema
,
trigger_name
,
event_object_schema
,
event_object_table
,
action_statement
from
information_schema
.
triggers
where
event_object_schema
=
'test'
or
event_object_schema
=
'mysqltest'
;
--
error
ER_TRG_IN_WRONG_SCHEMA
rename
table
t1
to
test
.
t2
;
insert
into
t1
values
(
102
);
select
@
a
;
select
trigger_schema
,
trigger_name
,
event_object_schema
,
event_object_table
,
action_statement
from
information_schema
.
triggers
where
event_object_schema
=
'test'
or
event_object_schema
=
'mysqltest'
;
# There should be no fantom .TRN files
--
error
ER_TRG_DOES_NOT_EXIST
drop
trigger
test
.
t1_bi
;
drop
trigger
t1_bi
;
drop
table
t1
;
drop
database
mysqltest
;
use
test
;
# And now let us check that the properly handle rename if there is some
# error during it (that we rollback such renames completely).
create
table
t1
(
id
int
);
create
trigger
t1_bi
before
insert
on
t1
for
each
row
set
@
a
:=
new
.
id
;
create
trigger
t1_ai
after
insert
on
t1
for
each
row
set
@
b
:=
new
.
id
;
insert
into
t1
values
(
101
);
select
@
a
,
@
b
;
select
trigger_schema
,
trigger_name
,
event_object_schema
,
event_object_table
,
action_statement
from
information_schema
.
triggers
where
event_object_schema
=
'test'
;
# Trick which makes update of second .TRN file impossible
system
echo
dummy
>
var
/
master
-
data
/
test
/
t1_ai
.
TRN
~
;
system
chmod
000
var
/
master
-
data
/
test
/
t1_ai
.
TRN
~
;
--
error
1
rename
table
t1
to
t2
;
# 't1' should be still there and triggers should work correctly
insert
into
t1
values
(
102
);
select
@
a
,
@
b
;
select
trigger_schema
,
trigger_name
,
event_object_schema
,
event_object_table
,
action_statement
from
information_schema
.
triggers
where
event_object_schema
=
'test'
;
system
chmod
600
var
/
master
-
data
/
test
/
t1_ai
.
TRN
;
# Let us check that updates to .TRN files were rolled back too
drop
trigger
t1_bi
;
drop
trigger
t1_ai
;
drop
table
t1
;
# Test for bug #16829 "Firing trigger with RETURN crashes the server"
# RETURN is not supposed to be used anywhere except functions, so error
# should be returned when one attempts to create trigger with RETURN.
...
...
sql/sql_rename.cc
View file @
4ca34093
...
...
@@ -19,6 +19,7 @@
*/
#include "mysql_priv.h"
#include "sql_trigger.h"
static
TABLE_LIST
*
rename_tables
(
THD
*
thd
,
TABLE_LIST
*
table_list
,
...
...
@@ -176,8 +177,26 @@ rename_tables(THD *thd, TABLE_LIST *table_list, bool skip_error)
if
(
table_type
==
DB_TYPE_UNKNOWN
)
my_error
(
ER_FILE_NOT_FOUND
,
MYF
(
0
),
name
,
my_errno
);
else
rc
=
mysql_rename_table
(
table_type
,
ren_table
->
db
,
old_alias
,
new_table
->
db
,
new_alias
);
{
if
(
!
(
rc
=
mysql_rename_table
(
table_type
,
ren_table
->
db
,
old_alias
,
new_table
->
db
,
new_alias
)))
{
if
((
rc
=
Table_triggers_list
::
change_table_name
(
thd
,
ren_table
->
db
,
old_alias
,
new_table
->
db
,
new_alias
)))
{
/*
We've succeeded in renaming table's .frm and in updating
corresponding handler data, but have failed to update table's
triggers appropriately. So let us revert operations on .frm
and handler's data and report about failure to rename table.
*/
(
void
)
mysql_rename_table
(
table_type
,
new_table
->
db
,
new_alias
,
ren_table
->
db
,
old_alias
);
}
}
}
break
;
}
case
FRMTYPE_VIEW
:
...
...
sql/sql_table.cc
View file @
4ca34093
...
...
@@ -3293,6 +3293,13 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
close_cached_table
(
thd
,
table
);
if
(
mysql_rename_table
(
old_db_type
,
db
,
table_name
,
new_db
,
new_alias
))
error
=
-
1
;
else
if
(
Table_triggers_list
::
change_table_name
(
thd
,
db
,
table_name
,
new_db
,
new_alias
))
{
VOID
(
mysql_rename_table
(
old_db_type
,
new_db
,
new_alias
,
db
,
table_name
));
error
=
-
1
;
}
}
VOID
(
pthread_mutex_unlock
(
&
LOCK_open
));
}
...
...
@@ -3841,7 +3848,11 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
VOID
(
quick_rm_table
(
new_db_type
,
new_db
,
tmp_name
));
}
else
if
(
mysql_rename_table
(
new_db_type
,
new_db
,
tmp_name
,
new_db
,
new_alias
))
new_alias
)
||
(
new_name
!=
table_name
||
new_db
!=
db
)
&&
// we also do rename
Table_triggers_list
::
change_table_name
(
thd
,
db
,
table_name
,
new_db
,
new_alias
))
{
// Try to get everything back
error
=
1
;
VOID
(
quick_rm_table
(
new_db_type
,
new_db
,
new_alias
));
...
...
sql/sql_trigger.cc
View file @
4ca34093
This diff is collapsed.
Click to expand it.
sql/sql_trigger.h
View file @
4ca34093
...
...
@@ -46,6 +46,11 @@ class Table_triggers_list: public Sql_alloc
used in CREATE/DROP TRIGGER for looking up trigger by name.
*/
List
<
LEX_STRING
>
names_list
;
/*
List of "ON table_name" parts in trigger definitions, used for
updating trigger definitions during RENAME TABLE.
*/
List
<
LEX_STRING
>
on_table_names_list
;
/*
Key representing triggers for this table in set of all stored
routines used by statement.
...
...
@@ -97,7 +102,10 @@ public:
static
bool
check_n_load
(
THD
*
thd
,
const
char
*
db
,
const
char
*
table_name
,
TABLE
*
table
,
bool
names_only
);
static
bool
drop_all_triggers
(
THD
*
thd
,
char
*
db
,
char
*
table_name
);
static
bool
change_table_name
(
THD
*
thd
,
const
char
*
db
,
const
char
*
old_table
,
const
char
*
new_db
,
const
char
*
new_table
);
bool
has_delete_triggers
()
{
return
(
bodies
[
TRG_EVENT_DELETE
][
TRG_ACTION_BEFORE
]
||
...
...
@@ -117,6 +125,13 @@ public:
private:
bool
prepare_record1_accessors
(
TABLE
*
table
);
LEX_STRING
*
change_table_name_in_trignames
(
const
char
*
db_name
,
LEX_STRING
*
new_table_name
,
LEX_STRING
*
stopper
);
bool
change_table_name_in_triggers
(
THD
*
thd
,
const
char
*
db_name
,
LEX_STRING
*
old_table_name
,
LEX_STRING
*
new_table_name
);
};
extern
const
LEX_STRING
trg_action_time_type_names
[];
...
...
sql/sql_yacc.yy
View file @
4ca34093
...
...
@@ -9126,8 +9126,8 @@ view_check_option:
**************************************************************************/
trigger_tail:
TRIGGER_SYM remember_name sp_name trg_action_time trg_event
ON
table_ident
FOR_SYM EACH_SYM ROW_SYM
TRIGGER_SYM remember_name sp_name trg_action_time trg_event
ON
remember_name table_ident remember_end
FOR_SYM EACH_SYM ROW_SYM
{
LEX *lex= Lex;
sp_head *sp;
...
...
@@ -9144,7 +9144,9 @@ trigger_tail:
sp->init(lex);
lex->trigger_definition_begin= $2;
lex->ident.str= $7;
lex->ident.length= $9 - $7;
sp->m_type= TYPE_ENUM_TRIGGER;
lex->sphead= sp;
lex->spname= $3;
...
...
@@ -9181,15 +9183,11 @@ trigger_tail:
We have to do it after parsing trigger body, because some of
sp_proc_stmt alternatives are not saving/restoring LEX, so
lex->query_tables can be wiped out.
QQ: What are other consequences of this?
QQ: Could we loosen lock type in certain cases ?
*/
if (!lex->select_lex.add_table_to_list(YYTHD, $
7,
if (!lex->select_lex.add_table_to_list(YYTHD, $
8,
(LEX_STRING*) 0,
TL_OPTION_UPDATING,
TL_WRIT
E))
TL_IGNOR
E))
YYABORT;
}
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment