2
--source suite/funcs_1/storedproc/load_sp_tb.inc
3
--------------------------------------------------------------------------------
5
--source suite/funcs_1/storedproc/cleanup_sp_tb.inc
6
--------------------------------------------------------------------------------
7
DROP DATABASE IF EXISTS db_storedproc;
8
DROP DATABASE IF EXISTS db_storedproc_1;
9
CREATE DATABASE db_storedproc;
10
CREATE DATABASE db_storedproc_1;
12
create table t1(f1 char(20),f2 char(25),f3 date,f4 int,f5 char(25),f6 int) engine = myisam;
13
load data infile 'MYSQL_TEST_DIR/suite/funcs_1/data/t4.txt' into table t1;
14
create table t2(f1 char(20),f2 char(25),f3 date,f4 int,f5 char(25),f6 int) engine = myisam;
15
load data infile 'MYSQL_TEST_DIR/suite/funcs_1/data/t4.txt' into table t2;
16
create table t3(f1 char(20),f2 char(20),f3 integer) engine = myisam;
17
load data infile 'MYSQL_TEST_DIR/suite/funcs_1/data/t3.txt' into table t3;
18
create table t4(f1 char(20),f2 char(25),f3 date,f4 int,f5 char(25),f6 int) engine = myisam;
19
load data infile 'MYSQL_TEST_DIR/suite/funcs_1/data/t4.txt' into table t4;
21
create table t6(f1 char(20),f2 char(25),f3 date,f4 int,f5 char(25),f6 int) engine = myisam;
22
load data infile 'MYSQL_TEST_DIR/suite/funcs_1/data/t4.txt' into table t6;
24
create table t7 (f1 char(20), f2 char(25), f3 date, f4 int) engine = myisam;
25
load data infile 'MYSQL_TEST_DIR/suite/funcs_1/data/t7.txt' into table t7;
27
Warning 1265 Data truncated for column 'f3' at row 1
28
Warning 1265 Data truncated for column 'f3' at row 2
29
Warning 1265 Data truncated for column 'f3' at row 3
30
Warning 1265 Data truncated for column 'f3' at row 4
31
Warning 1265 Data truncated for column 'f3' at row 5
32
Warning 1265 Data truncated for column 'f3' at row 6
33
Warning 1265 Data truncated for column 'f3' at row 7
34
Warning 1265 Data truncated for column 'f3' at row 8
35
Warning 1265 Data truncated for column 'f3' at row 9
36
Warning 1265 Data truncated for column 'f3' at row 10
37
create table t8 (f1 char(20), f2 char(25), f3 date, f4 int) engine = myisam;
38
load data infile 'MYSQL_TEST_DIR/suite/funcs_1/data/t7.txt' into table t8;
40
Warning 1265 Data truncated for column 'f3' at row 1
41
Warning 1265 Data truncated for column 'f3' at row 2
42
Warning 1265 Data truncated for column 'f3' at row 3
43
Warning 1265 Data truncated for column 'f3' at row 4
44
Warning 1265 Data truncated for column 'f3' at row 5
45
Warning 1265 Data truncated for column 'f3' at row 6
46
Warning 1265 Data truncated for column 'f3' at row 7
47
Warning 1265 Data truncated for column 'f3' at row 8
48
Warning 1265 Data truncated for column 'f3' at row 9
49
Warning 1265 Data truncated for column 'f3' at row 10
50
create table t9(f1 int, f2 char(25), f3 int) engine = myisam;
51
load data infile 'MYSQL_TEST_DIR/suite/funcs_1/data/t9.txt' into table t9;
52
create table t10(f1 char(20),f2 char(25),f3 date,f4 int,f5 char(25),f6 int) engine = myisam;
53
load data infile 'MYSQL_TEST_DIR/suite/funcs_1/data/t4.txt' into table t10;
54
create table t11(f1 char(20),f2 char(25),f3 date,f4 int,f5 char(25),f6 int) engine = myisam;
55
load data infile 'MYSQL_TEST_DIR/suite/funcs_1/data/t4.txt' into table t11;
57
Section 3.1.10 - CALL checks:
58
--------------------------------------------------------------------------------
61
Testcase 3.1.10.2 + 3.1.10.5:
62
-----------------------------
64
2. Ensure that a procedure cannot be called if the appropriate privileges do not
66
5. Ensure that a function cannot be executed if the appropriate privileges do
68
--------------------------------------------------------------------------------
69
DROP PROCEDURE IF EXISTS sp31102;
70
DROP FUNCTION IF EXISTS fn31105;
71
create user 'user_1'@'localhost';
72
create user 'user_2'@'localhost';
73
GRANT CREATE ROUTINE ON db_storedproc.* TO 'user_1'@'localhost';
74
GRANT SELECT ON db_storedproc.* TO 'user_2'@'localhost';
76
connect(localhost,user_1,,db_storedproc,MYSQL_PORT,MYSQL_SOCK);
78
user_1@localhost db_storedproc
79
CREATE PROCEDURE sp31102 () SQL SECURITY INVOKER
81
SELECT * FROM db_storedproc.t1 WHERE f4=-5000 LIMIT 1;
83
CREATE FUNCTION fn31105(n INT) RETURNS INT
89
connect(localhost,user_2,,db_storedproc,MYSQL_PORT,MYSQL_SOCK);
91
user_2@localhost db_storedproc
93
ERROR 42000: execute command denied to user 'user_2'@'localhost' for routine 'db_storedproc.sp31102'
95
ERROR 42000: execute command denied to user 'user_2'@'localhost' for routine 'db_storedproc.fn31105'
99
root@localhost db_storedproc
102
a` a` 1000-01-01 -5000 a` -5000
106
GRANT EXECUTE ON db_storedproc.* TO 'user_2'@'localhost';
108
connect(localhost,user_2,,db_storedproc,MYSQL_PORT,MYSQL_SOCK);
110
user_2@localhost db_storedproc
113
a` a` 1000-01-01 -5000 a` -5000
120
root@localhost db_storedproc
121
REVOKE EXECUTE ON db_storedproc.* FROM 'user_2'@'localhost';
125
a` a` 1000-01-01 -5000 a` -5000
129
connect(localhost,user_2,,db_storedproc,MYSQL_PORT,MYSQL_SOCK);
131
user_2@localhost db_storedproc
133
ERROR 42000: execute command denied to user 'user_2'@'localhost' for routine 'db_storedproc.sp31102'
135
ERROR 42000: execute command denied to user 'user_2'@'localhost' for routine 'db_storedproc.fn31105'
138
root@localhost db_storedproc
139
DROP PROCEDURE sp31102;
140
DROP FUNCTION fn31105;
141
DROP USER 'user_1'@'localhost';
142
DROP USER 'user_2'@'localhost';
147
Ensure that a function can never be called.
148
--------------------------------------------------------------------------------
149
DROP FUNCTION IF EXISTS fn1;
150
CREATE FUNCTION fn1(a int) returns int
156
ERROR 42000: PROCEDURE db_storedproc.fn1 does not exist
162
Ensure that a procedure can never be executed.
163
--------------------------------------------------------------------------------
164
DROP PROCEDURE IF EXISTS sp1;
165
DROP FUNCTION IF EXISTS sp1;
166
CREATE PROCEDURE sp1()
171
ERROR 42000: FUNCTION db_storedproc.sp1 does not exist
177
Ensure that the ROW_COUNT() SQL function always returns the correct number of
178
rows affected by the execution of a stored procedure.
179
--------------------------------------------------------------------------------
180
DROP PROCEDURE IF EXISTS sp_ins_1;
181
DROP PROCEDURE IF EXISTS sp_ins_3;
182
DROP PROCEDURE IF EXISTS sp_upd;
183
DROP PROCEDURE IF EXISTS sp_ins_upd;
184
DROP PROCEDURE IF EXISTS sp_del;
185
DROP PROCEDURE IF EXISTS sp_with_rowcount;
186
CREATE TABLE temp(f1 CHAR(20),f2 CHAR(25),f3 DATE,f4 INT,f5 CHAR(25),f6 INT);
187
INSERT INTO temp SELECT * FROM t10;
188
CREATE PROCEDURE sp_ins_1()
190
INSERT INTO temp VALUES ('abc', 'abc', '20051003', 100, 'uvw', 1000);
192
CREATE PROCEDURE sp_ins_3()
194
INSERT INTO temp VALUES ('abc', 'xyz', '19490523', 100, 'uvw', 1000);
195
INSERT INTO temp VALUES ('abc', 'xyz', '1989-11-09', 100, 'uvw', 1000);
196
INSERT INTO temp VALUES ('abc', 'xyz', '2005-10-24', 100, 'uvw', 1000);
198
CREATE PROCEDURE sp_upd()
200
UPDATE temp SET temp.f1 = 'updated' WHERE temp.f1 ='abc';
202
CREATE PROCEDURE sp_ins_upd()
205
INSERT INTO temp VALUES ('qwe', 'abc', '1989-11-09', 100, 'uvw', 1000);
206
INSERT INTO temp VALUES ('qwe', 'xyz', '1998-03-26', 100, 'uvw', 1000);
207
INSERT INTO temp VALUES ('qwe', 'abc', '2000-11-09', 100, 'uvw', 1000);
208
INSERT INTO temp VALUES ('qwe', 'abc', '2005-11-07', 100, 'uvw', 1000);
210
SELECT COUNT( f1 ), f1 FROM temp GROUP BY f1;
211
UPDATE temp SET temp.f1 = 'updated_2' WHERE temp.f1 ='qwe' AND temp.f2 = 'abc';
213
CREATE PROCEDURE sp_del()
215
DELETE FROM temp WHERE temp.f1 ='qwe' OR temp.f1 = 'updated_2';
217
CREATE PROCEDURE sp_with_rowcount()
220
INSERT INTO temp VALUES ('qwe', 'abc', '1989-11-09', 100, 'uvw', 1000),
221
('qwe', 'xyz', '1998-03-26', 100, 'uvw', 1000),
222
('qwe', 'abc', '2000-11-09', 100, 'uvw', 1000),
223
('qwe', 'xyz', '2005-11-07', 100, 'uvw', 1000);
225
SELECT row_count() AS 'row_count() after insert';
226
SELECT row_count() AS 'row_count() after select row_count()';
227
SELECT f1,f2,f3 FROM temp ORDER BY f1,f2,f3;
228
UPDATE temp SET temp.f1 = 'updated_2' WHERE temp.f2 = 'abc';
229
SELECT row_count() AS 'row_count() after update';
230
SELECT f1,f2,f3 FROM temp ORDER BY f1,f2,f3;
231
DELETE FROM temp WHERE temp.f1 = 'updated_2';
232
SELECT row_count() AS 'row_count() after delete';
240
a^aaaaaaaa a^aaaaaaaa 1000-01-09 -4992 a^aaaaaaaa -4992
241
a_aaaaaaaaa a_aaaaaaaaa 1000-01-10 -4991 a_aaaaaaaaa -4991
242
a` a` 1000-01-01 -5000 a` -5000
243
aaa aaa 1000-01-02 -4999 aaa -4999
244
abaa abaa 1000-01-03 -4998 abaa -4998
245
abc abc 2005-10-03 100 uvw 1000
246
acaaa acaaa 1000-01-04 -4997 acaaa -4997
247
adaaaa adaaaa 1000-01-05 -4996 adaaaa -4996
248
aeaaaaa aeaaaaa 1000-01-06 -4995 aeaaaaa -4995
249
afaaaaaa afaaaaaa 1000-01-07 -4994 afaaaaaa -4994
250
agaaaaaaa agaaaaaaa 1000-01-08 -4993 agaaaaaaa -4993
257
a^aaaaaaaa a^aaaaaaaa 1000-01-09 -4992 a^aaaaaaaa -4992
258
a_aaaaaaaaa a_aaaaaaaaa 1000-01-10 -4991 a_aaaaaaaaa -4991
259
a` a` 1000-01-01 -5000 a` -5000
260
aaa aaa 1000-01-02 -4999 aaa -4999
261
abaa abaa 1000-01-03 -4998 abaa -4998
262
abc abc 2005-10-03 100 uvw 1000
263
abc xyz 1949-05-23 100 uvw 1000
264
abc xyz 1989-11-09 100 uvw 1000
265
abc xyz 2005-10-24 100 uvw 1000
266
acaaa acaaa 1000-01-04 -4997 acaaa -4997
267
adaaaa adaaaa 1000-01-05 -4996 adaaaa -4996
268
aeaaaaa aeaaaaa 1000-01-06 -4995 aeaaaaa -4995
269
afaaaaaa afaaaaaa 1000-01-07 -4994 afaaaaaa -4994
270
agaaaaaaa agaaaaaaa 1000-01-08 -4993 agaaaaaaa -4993
277
a^aaaaaaaa a^aaaaaaaa 1000-01-09 -4992 a^aaaaaaaa -4992
278
a_aaaaaaaaa a_aaaaaaaaa 1000-01-10 -4991 a_aaaaaaaaa -4991
279
a` a` 1000-01-01 -5000 a` -5000
280
aaa aaa 1000-01-02 -4999 aaa -4999
281
abaa abaa 1000-01-03 -4998 abaa -4998
282
acaaa acaaa 1000-01-04 -4997 acaaa -4997
283
adaaaa adaaaa 1000-01-05 -4996 adaaaa -4996
284
aeaaaaa aeaaaaa 1000-01-06 -4995 aeaaaaa -4995
285
afaaaaaa afaaaaaa 1000-01-07 -4994 afaaaaaa -4994
286
agaaaaaaa agaaaaaaa 1000-01-08 -4993 agaaaaaaa -4993
287
updated abc 2005-10-03 100 uvw 1000
288
updated xyz 1949-05-23 100 uvw 1000
289
updated xyz 1989-11-09 100 uvw 1000
290
updated xyz 2005-10-24 100 uvw 1000
310
a^aaaaaaaa a^aaaaaaaa 1000-01-09 -4992 a^aaaaaaaa -4992
311
a_aaaaaaaaa a_aaaaaaaaa 1000-01-10 -4991 a_aaaaaaaaa -4991
312
a` a` 1000-01-01 -5000 a` -5000
313
aaa aaa 1000-01-02 -4999 aaa -4999
314
abaa abaa 1000-01-03 -4998 abaa -4998
315
acaaa acaaa 1000-01-04 -4997 acaaa -4997
316
adaaaa adaaaa 1000-01-05 -4996 adaaaa -4996
317
aeaaaaa aeaaaaa 1000-01-06 -4995 aeaaaaa -4995
318
afaaaaaa afaaaaaa 1000-01-07 -4994 afaaaaaa -4994
319
agaaaaaaa agaaaaaaa 1000-01-08 -4993 agaaaaaaa -4993
320
qwe xyz 1998-03-26 100 uvw 1000
321
updated abc 2005-10-03 100 uvw 1000
322
updated xyz 1949-05-23 100 uvw 1000
323
updated xyz 1989-11-09 100 uvw 1000
324
updated xyz 2005-10-24 100 uvw 1000
325
updated_2 abc 1989-11-09 100 uvw 1000
326
updated_2 abc 2000-11-09 100 uvw 1000
327
updated_2 abc 2005-11-07 100 uvw 1000
334
a^aaaaaaaa a^aaaaaaaa 1000-01-09 -4992 a^aaaaaaaa -4992
335
a_aaaaaaaaa a_aaaaaaaaa 1000-01-10 -4991 a_aaaaaaaaa -4991
336
a` a` 1000-01-01 -5000 a` -5000
337
aaa aaa 1000-01-02 -4999 aaa -4999
338
abaa abaa 1000-01-03 -4998 abaa -4998
339
acaaa acaaa 1000-01-04 -4997 acaaa -4997
340
adaaaa adaaaa 1000-01-05 -4996 adaaaa -4996
341
aeaaaaa aeaaaaa 1000-01-06 -4995 aeaaaaa -4995
342
afaaaaaa afaaaaaa 1000-01-07 -4994 afaaaaaa -4994
343
agaaaaaaa agaaaaaaa 1000-01-08 -4993 agaaaaaaa -4993
344
updated abc 2005-10-03 100 uvw 1000
345
updated xyz 1949-05-23 100 uvw 1000
346
updated xyz 1989-11-09 100 uvw 1000
347
updated xyz 2005-10-24 100 uvw 1000
349
CALL sp_with_rowcount();
350
row_count() after insert
352
row_count() after select row_count()
359
row_count() after update
364
updated_2 abc 1989-11-09
365
updated_2 abc 2000-11-09
366
row_count() after delete
373
qwe xyz 1998-03-26 100 uvw 1000
374
qwe xyz 2005-11-07 100 uvw 1000
375
DROP PROCEDURE sp_ins_1;
376
DROP PROCEDURE sp_ins_3;
377
DROP PROCEDURE sp_upd;
378
DROP PROCEDURE sp_ins_upd;
379
DROP PROCEDURE sp_del;
380
DROP PROCEDURE sp_with_rowcount;
386
Ensure that the mysql_affected_rows() C API function always returns the correct
387
number of rows affected by the execution of a stored procedure.
388
--------------------------------------------------------------------------------
390
--source suite/funcs_1/storedproc/cleanup_sp_tb.inc
391
--------------------------------------------------------------------------------
392
DROP DATABASE IF EXISTS db_storedproc;
393
DROP DATABASE IF EXISTS db_storedproc_1;
395
. +++ END OF SCRIPT +++
396
--------------------------------------------------------------------------------