summaryrefslogtreecommitdiff
path: root/mysql-test/t/sp-destruct.test
blob: 14c38a2fdb47c7629e4fe6e33a3c0b2949aa1b72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#
# Destructive stored procedure tests
#
# We do horrible things to the mysql.proc table here, so any unexpected
# failures here might leave it in an undetermined state.
#
# In the case of trouble you might want to skip this.
#

# embedded server returns different paths in error messages
# in lines like 'call bug14233();'
# mysqltest should be fixed to allow REPLACE_RESULT in error message
-- source include/not_embedded.inc

# Backup proc table
let $MYSQLD_DATADIR= `select @@datadir`;
--copy_file $MYSQLD_DATADIR/mysql/proc.frm $MYSQLTEST_VARDIR/tmp/proc.frm
--copy_file $MYSQLD_DATADIR/mysql/proc.MYD $MYSQLTEST_VARDIR/tmp/proc.MYD
--copy_file $MYSQLD_DATADIR/mysql/proc.MYI $MYSQLTEST_VARDIR/tmp/proc.MYI

use test;

--disable_warnings
drop procedure if exists bug14233;
drop function if exists bug14233;
drop table if exists t1;
drop view if exists v1;
--enable_warnings

create procedure bug14233()
  set @x = 42;

create function bug14233_f() returns int
  return 42;

create table t1 (id int);
create trigger t1_ai after insert on t1 for each row call bug14233();

# Unsupported tampering with the mysql.proc definition
alter table mysql.proc drop type;
--replace_result $MYSQL_TEST_DIR .
--error ER_SP_PROC_TABLE_CORRUPT
call bug14233();
--replace_result $MYSQL_TEST_DIR .
--error ER_SP_PROC_TABLE_CORRUPT
create view v1 as select bug14233_f();
--replace_result $MYSQL_TEST_DIR .
--error ER_SP_PROC_TABLE_CORRUPT
insert into t1 values (0);

flush table mysql.proc;

# Thrashing the .frm file
--remove_file $MYSQLD_DATADIR/mysql/proc.frm
--write_file $MYSQLD_DATADIR/mysql/proc.frm
saljdfa
EOF
--replace_result $MYSQLTEST_VARDIR . master-data// '' '\\' '/'
--error ER_NOT_FORM_FILE
call bug14233();
--replace_result $MYSQLTEST_VARDIR . master-data// '' '\\' '/'
--error ER_NOT_FORM_FILE
create view v1 as select bug14233_f();
--replace_result $MYSQLTEST_VARDIR . master-data// '' '\\' '/'
--error ER_NOT_FORM_FILE
insert into t1 values (0);

flush table mysql.proc;

# Drop the mysql.proc table
--remove_file $MYSQLD_DATADIR/mysql/proc.frm
--remove_file $MYSQLD_DATADIR/mysql/proc.MYD
--remove_file $MYSQLD_DATADIR/mysql/proc.MYI
--error ER_NO_SUCH_TABLE
call bug14233();
--error ER_NO_SUCH_TABLE
create view v1 as select bug14233_f();
--error ER_NO_SUCH_TABLE
insert into t1 values (0);

# Restore mysql.proc
--copy_file $MYSQLTEST_VARDIR/tmp/proc.frm $MYSQLD_DATADIR/mysql/proc.frm
--copy_file $MYSQLTEST_VARDIR/tmp/proc.MYD $MYSQLD_DATADIR/mysql/proc.MYD
--copy_file $MYSQLTEST_VARDIR/tmp/proc.MYI $MYSQLD_DATADIR/mysql/proc.MYI 
--remove_file $MYSQLTEST_VARDIR/tmp/proc.frm
--remove_file $MYSQLTEST_VARDIR/tmp/proc.MYD
--remove_file $MYSQLTEST_VARDIR/tmp/proc.MYI

flush table mysql.proc;
flush privileges;

delete from mysql.proc where name like 'bug14233%';

# Unsupported editing of mysql.proc, circumventing checks in "create ..."
insert into mysql.proc
(
  db, name, type, specific_name, language, sql_data_access, is_deterministic,
  security_type, param_list, returns, body, definer, created, modified,
  sql_mode, comment, character_set_client, collation_connection, db_collation,
  body_utf8
)
values
(
  'test', 'bug14233_1', 'FUNCTION', 'bug14233_1', 'SQL', 'READS_SQL_DATA', 'NO',
  'DEFINER', '', 'int(10)',
  'select count(*) from mysql.user',
  'root@localhost', NOW() , '0000-00-00 00:00:00', '', '',
  '', '', '',
  'select count(*) from mysql.user'
),
(
  'test', 'bug14233_2', 'FUNCTION', 'bug14233_2', 'SQL', 'READS_SQL_DATA', 'NO',
  'DEFINER', '', 'int(10)',
  'begin declare x int; select count(*) into x from mysql.user; end',
  'root@localhost', NOW() , '0000-00-00 00:00:00', '', '',
  '', '', '',
  'begin declare x int; select count(*) into x from mysql.user; end'
),
(
  'test', 'bug14233_3', 'PROCEDURE', 'bug14233_3', 'SQL', 'READS_SQL_DATA','NO',
  'DEFINER', '', '',
  'alksj wpsj sa ^#!@ ',
  'root@localhost', NOW() , '0000-00-00 00:00:00', '', '',
  '', '', '',
  'alksj wpsj sa ^#!@ '
);

--error ER_SP_PROC_TABLE_CORRUPT
select bug14233_1();
--error ER_SP_PROC_TABLE_CORRUPT
create view v1 as select bug14233_1();

--error ER_SP_PROC_TABLE_CORRUPT
select bug14233_2();
--error ER_SP_PROC_TABLE_CORRUPT
create view v1 as select bug14233_2();

--error ER_SP_PROC_TABLE_CORRUPT
call bug14233_3();
drop trigger t1_ai;
create trigger t1_ai after insert on t1 for each row call bug14233_3();
--error ER_SP_PROC_TABLE_CORRUPT
insert into t1 values (0);

# Clean-up
drop trigger t1_ai;
drop table t1;

#
# BUG#16303: erroneus stored procedures and functions should be droppable
#
drop function bug14233_1;
drop function bug14233_2;
drop procedure bug14233_3;
# Assert: These should show nothing.
show procedure status where db=DATABASE();
show function status where db=DATABASE();