myisam_storedproc_10.result 13.3 KB
Newer Older
1
SET @@session.sql_mode = 'NO_ENGINE_SUBSTITUTION';
2 3 4 5 6 7 8 9 10 11 12

--source suite/funcs_1/storedproc/load_sp_tb.inc
--------------------------------------------------------------------------------

--source suite/funcs_1/storedproc/cleanup_sp_tb.inc
--------------------------------------------------------------------------------
DROP DATABASE IF EXISTS db_storedproc;
DROP DATABASE IF EXISTS db_storedproc_1;
CREATE DATABASE db_storedproc;
CREATE DATABASE db_storedproc_1;
USE db_storedproc;
unknown's avatar
unknown committed
13 14
create table t1(f1 char(20),f2 char(25),f3 date,f4 int,f5 char(25),f6 int)
engine = <engine_to_be_tested>;
15
load data infile '<MYSQLTEST_VARDIR>/std_data/funcs_1/t4.txt' into table t1;
unknown's avatar
unknown committed
16 17
create table t2(f1 char(20),f2 char(25),f3 date,f4 int,f5 char(25),f6 int)
engine = <engine_to_be_tested>;
18
load data infile '<MYSQLTEST_VARDIR>/std_data/funcs_1/t4.txt' into table t2;
unknown's avatar
unknown committed
19
create table t3(f1 char(20),f2 char(20),f3 integer) engine = <engine_to_be_tested>;
20
load data infile '<MYSQLTEST_VARDIR>/std_data/funcs_1/t3.txt' into table t3;
unknown's avatar
unknown committed
21 22
create table t4(f1 char(20),f2 char(25),f3 date,f4 int,f5 char(25),f6 int)
engine = <engine_to_be_tested>;
23
load data infile '<MYSQLTEST_VARDIR>/std_data/funcs_1/t4.txt' into table t4;
24
USE db_storedproc_1;
unknown's avatar
unknown committed
25 26
create table t6(f1 char(20),f2 char(25),f3 date,f4 int,f5 char(25),f6 int)
engine = <engine_to_be_tested>;
27
load data infile '<MYSQLTEST_VARDIR>/std_data/funcs_1/t4.txt' into table t6;
28
USE db_storedproc;
unknown's avatar
unknown committed
29 30
create table t7 (f1 char(20), f2 char(25), f3 date, f4 int)
engine = <engine_to_be_tested>;
31
load data infile '<MYSQLTEST_VARDIR>/std_data/funcs_1/t7.txt' into table t7;
32 33 34 35 36 37 38 39 40 41 42
Warnings:
Warning	1265	Data truncated for column 'f3' at row 1
Warning	1265	Data truncated for column 'f3' at row 2
Warning	1265	Data truncated for column 'f3' at row 3
Warning	1265	Data truncated for column 'f3' at row 4
Warning	1265	Data truncated for column 'f3' at row 5
Warning	1265	Data truncated for column 'f3' at row 6
Warning	1265	Data truncated for column 'f3' at row 7
Warning	1265	Data truncated for column 'f3' at row 8
Warning	1265	Data truncated for column 'f3' at row 9
Warning	1265	Data truncated for column 'f3' at row 10
unknown's avatar
unknown committed
43 44
create table t8 (f1 char(20), f2 char(25), f3 date, f4 int)
engine = <engine_to_be_tested>;
45
load data infile '<MYSQLTEST_VARDIR>/std_data/funcs_1/t7.txt' into table t8;
46 47 48 49 50 51 52 53 54 55 56
Warnings:
Warning	1265	Data truncated for column 'f3' at row 1
Warning	1265	Data truncated for column 'f3' at row 2
Warning	1265	Data truncated for column 'f3' at row 3
Warning	1265	Data truncated for column 'f3' at row 4
Warning	1265	Data truncated for column 'f3' at row 5
Warning	1265	Data truncated for column 'f3' at row 6
Warning	1265	Data truncated for column 'f3' at row 7
Warning	1265	Data truncated for column 'f3' at row 8
Warning	1265	Data truncated for column 'f3' at row 9
Warning	1265	Data truncated for column 'f3' at row 10
unknown's avatar
unknown committed
57
create table t9(f1 int, f2 char(25), f3 int) engine = <engine_to_be_tested>;
58
load data infile '<MYSQLTEST_VARDIR>/std_data/funcs_1/t9.txt' into table t9;
unknown's avatar
unknown committed
59 60
create table t10(f1 char(20),f2 char(25),f3 date,f4 int,f5 char(25),f6 int)
engine = <engine_to_be_tested>;
61
load data infile '<MYSQLTEST_VARDIR>/std_data/funcs_1/t4.txt' into table t10;
unknown's avatar
unknown committed
62 63
create table t11(f1 char(20),f2 char(25),f3 date,f4 int,f5 char(25),f6 int)
engine = <engine_to_be_tested>;
64
load data infile '<MYSQLTEST_VARDIR>/std_data/funcs_1/t4.txt' into table t11;
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88

Section 3.1.10 - CALL checks:
--------------------------------------------------------------------------------
USE db_storedproc;

Testcase 3.1.10.2 + 3.1.10.5:
-----------------------------

2. Ensure that a procedure cannot be called if the appropriate privileges do not
exist.
5. Ensure that a function cannot be executed if the appropriate privileges do
not exist.
--------------------------------------------------------------------------------
DROP PROCEDURE IF EXISTS sp31102;
DROP FUNCTION  IF EXISTS fn31105;
create user 'user_1'@'localhost';
create user 'user_2'@'localhost';
GRANT CREATE ROUTINE ON db_storedproc.* TO 'user_1'@'localhost';
GRANT SELECT         ON db_storedproc.* TO 'user_2'@'localhost';
FLUSH PRIVILEGES;
	
user_1@localhost	db_storedproc
CREATE PROCEDURE sp31102 () SQL SECURITY INVOKER
BEGIN
unknown's avatar
unknown committed
89
SELECT * FROM db_storedproc.t1 WHERE f4=-5000 LIMIT 1;
90 91 92 93 94 95 96 97 98 99 100 101 102
END//
CREATE FUNCTION fn31105(n INT) RETURNS INT
BEGIN
DECLARE res INT;
SET res = n * n;
RETURN res;
END//
	
user_2@localhost	db_storedproc
CALL sp31102();
ERROR 42000: execute command denied to user 'user_2'@'localhost' for routine 'db_storedproc.sp31102'
SELECT fn31105( 9 );
ERROR 42000: execute command denied to user 'user_2'@'localhost' for routine 'db_storedproc.fn31105'
unknown's avatar
unknown committed
103 104
connection default;
USE db_storedproc;
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
	
root@localhost	db_storedproc
CALL sp31102();
f1	f2	f3	f4	f5	f6
a`	a`	1000-01-01	-5000	a`	-5000
SELECT fn31105( 9 );
fn31105( 9 )
81
GRANT EXECUTE ON db_storedproc.* TO 'user_2'@'localhost';
FLUSH PRIVILEGES;
	
user_2@localhost	db_storedproc
CALL sp31102();
f1	f2	f3	f4	f5	f6
a`	a`	1000-01-01	-5000	a`	-5000
SELECT fn31105( 9 );
fn31105( 9 )
81
unknown's avatar
unknown committed
123 124
connection default;
USE db_storedproc;
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
	
root@localhost	db_storedproc
REVOKE EXECUTE ON db_storedproc.* FROM 'user_2'@'localhost';
FLUSH PRIVILEGES;
CALL sp31102();
f1	f2	f3	f4	f5	f6
a`	a`	1000-01-01	-5000	a`	-5000
SELECT fn31105( 9 );
fn31105( 9 )
81
	
user_2@localhost	db_storedproc
CALL sp31102();
ERROR 42000: execute command denied to user 'user_2'@'localhost' for routine 'db_storedproc.sp31102'
SELECT fn31105( 9 );
ERROR 42000: execute command denied to user 'user_2'@'localhost' for routine 'db_storedproc.fn31105'
unknown's avatar
unknown committed
141
USE db_storedproc;
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
	
root@localhost	db_storedproc
DROP PROCEDURE sp31102;
DROP FUNCTION  fn31105;
DROP USER 'user_1'@'localhost';
DROP USER 'user_2'@'localhost';

Testcase 3.1.10.3:
------------------

Ensure that a function can never be called.
--------------------------------------------------------------------------------
DROP FUNCTION IF EXISTS fn1;
CREATE FUNCTION fn1(a int) returns int
BEGIN
set @b = 0.9 * a;
return @b;
END//
CALL fn1();
ERROR 42000: PROCEDURE db_storedproc.fn1 does not exist
DROP FUNCTION fn1;

Testcase 3.1.10.6:
------------------

Ensure that a procedure can never be executed.
--------------------------------------------------------------------------------
DROP PROCEDURE IF EXISTS sp1;
DROP FUNCTION IF EXISTS sp1;
CREATE PROCEDURE sp1()
BEGIN
SELECT * from t10;
END//
SELECT sp1();
ERROR 42000: FUNCTION db_storedproc.sp1 does not exist
DROP PROCEDURE sp1;

Testcase 3.1.10.7:
------------------

Ensure that the ROW_COUNT() SQL function always returns the correct number of
rows affected by the execution of a stored procedure.
--------------------------------------------------------------------------------
DROP PROCEDURE IF EXISTS sp_ins_1;
DROP PROCEDURE IF EXISTS sp_ins_3;
DROP PROCEDURE IF EXISTS sp_upd;
DROP PROCEDURE IF EXISTS sp_ins_upd;
unknown's avatar
unknown committed
189 190
DROP PROCEDURE IF EXISTS sp_del;
DROP PROCEDURE IF EXISTS sp_with_rowcount;
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
CREATE TABLE temp(f1 CHAR(20),f2 CHAR(25),f3 DATE,f4 INT,f5 CHAR(25),f6 INT);
INSERT INTO temp SELECT * FROM t10;
CREATE PROCEDURE sp_ins_1()
BEGIN
INSERT INTO temp VALUES ('abc', 'abc', '20051003', 100, 'uvw', 1000);
END//
CREATE PROCEDURE sp_ins_3()
BEGIN
INSERT INTO temp VALUES  ('abc', 'xyz', '19490523',   100, 'uvw', 1000);
INSERT INTO temp VALUES  ('abc', 'xyz', '1989-11-09', 100, 'uvw', 1000);
INSERT INTO temp VALUES  ('abc', 'xyz', '2005-10-24', 100, 'uvw', 1000);
END//
CREATE PROCEDURE sp_upd()
BEGIN
UPDATE temp SET temp.f1 = 'updated' WHERE temp.f1 ='abc';
END//
CREATE PROCEDURE sp_ins_upd()
BEGIN
BEGIN
INSERT INTO temp VALUES  ('qwe', 'abc', '1989-11-09', 100, 'uvw', 1000);
INSERT INTO temp VALUES  ('qwe', 'xyz', '1998-03-26', 100, 'uvw', 1000);
INSERT INTO temp VALUES  ('qwe', 'abc', '2000-11-09', 100, 'uvw', 1000);
INSERT INTO temp VALUES  ('qwe', 'abc', '2005-11-07', 100, 'uvw', 1000);
END;
SELECT COUNT( f1 ), f1 FROM temp GROUP BY f1;
UPDATE temp SET temp.f1 = 'updated_2' WHERE temp.f1 ='qwe' AND temp.f2 = 'abc';
END//
unknown's avatar
unknown committed
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
CREATE PROCEDURE sp_del()
BEGIN
DELETE FROM temp WHERE temp.f1 ='qwe' OR temp.f1 = 'updated_2';
END//
CREATE PROCEDURE sp_with_rowcount()
BEGIN
BEGIN
INSERT INTO temp VALUES  ('qwe', 'abc', '1989-11-09', 100, 'uvw', 1000),
('qwe', 'xyz', '1998-03-26', 100, 'uvw', 1000),
('qwe', 'abc', '2000-11-09', 100, 'uvw', 1000),
('qwe', 'xyz', '2005-11-07', 100, 'uvw', 1000);
END;
SELECT row_count() AS 'row_count() after insert';
SELECT row_count() AS 'row_count() after select row_count()';
SELECT f1,f2,f3 FROM temp ORDER BY f1,f2,f3;
UPDATE temp SET temp.f1 = 'updated_2' WHERE temp.f2 = 'abc';
SELECT row_count() AS 'row_count() after update';
SELECT f1,f2,f3 FROM temp ORDER BY f1,f2,f3;
DELETE FROM temp WHERE temp.f1 = 'updated_2';
SELECT row_count() AS 'row_count() after delete';
END//
239 240 241 242 243 244
CALL sp_ins_1();
SELECT row_count();
row_count()
1
SELECT * FROM temp;
f1	f2	f3	f4	f5	f6
unknown's avatar
unknown committed
245 246
a^aaaaaaaa	a^aaaaaaaa	1000-01-09	-4992	a^aaaaaaaa	-4992
a_aaaaaaaaa	a_aaaaaaaaa	1000-01-10	-4991	a_aaaaaaaaa	-4991
247 248 249
a`	a`	1000-01-01	-5000	a`	-5000
aaa	aaa	1000-01-02	-4999	aaa	-4999
abaa	abaa	1000-01-03	-4998	abaa	-4998
unknown's avatar
unknown committed
250
abc	abc	2005-10-03	100	uvw	1000
251 252 253 254 255 256 257 258 259 260 261
acaaa	acaaa	1000-01-04	-4997	acaaa	-4997
adaaaa	adaaaa	1000-01-05	-4996	adaaaa	-4996
aeaaaaa	aeaaaaa	1000-01-06	-4995	aeaaaaa	-4995
afaaaaaa	afaaaaaa	1000-01-07	-4994	afaaaaaa	-4994
agaaaaaaa	agaaaaaaa	1000-01-08	-4993	agaaaaaaa	-4993
CALL sp_ins_3();
SELECT row_count();
row_count()
1
SELECT * FROM temp;
f1	f2	f3	f4	f5	f6
unknown's avatar
unknown committed
262 263
a^aaaaaaaa	a^aaaaaaaa	1000-01-09	-4992	a^aaaaaaaa	-4992
a_aaaaaaaaa	a_aaaaaaaaa	1000-01-10	-4991	a_aaaaaaaaa	-4991
264 265 266
a`	a`	1000-01-01	-5000	a`	-5000
aaa	aaa	1000-01-02	-4999	aaa	-4999
abaa	abaa	1000-01-03	-4998	abaa	-4998
unknown's avatar
unknown committed
267 268 269 270
abc	abc	2005-10-03	100	uvw	1000
abc	xyz	1949-05-23	100	uvw	1000
abc	xyz	1989-11-09	100	uvw	1000
abc	xyz	2005-10-24	100	uvw	1000
271 272 273 274 275 276 277 278 279 280 281
acaaa	acaaa	1000-01-04	-4997	acaaa	-4997
adaaaa	adaaaa	1000-01-05	-4996	adaaaa	-4996
aeaaaaa	aeaaaaa	1000-01-06	-4995	aeaaaaa	-4995
afaaaaaa	afaaaaaa	1000-01-07	-4994	afaaaaaa	-4994
agaaaaaaa	agaaaaaaa	1000-01-08	-4993	agaaaaaaa	-4993
CALL sp_upd();
SELECT row_count();
row_count()
4
SELECT * FROM temp;
f1	f2	f3	f4	f5	f6
unknown's avatar
unknown committed
282 283
a^aaaaaaaa	a^aaaaaaaa	1000-01-09	-4992	a^aaaaaaaa	-4992
a_aaaaaaaaa	a_aaaaaaaaa	1000-01-10	-4991	a_aaaaaaaaa	-4991
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
a`	a`	1000-01-01	-5000	a`	-5000
aaa	aaa	1000-01-02	-4999	aaa	-4999
abaa	abaa	1000-01-03	-4998	abaa	-4998
acaaa	acaaa	1000-01-04	-4997	acaaa	-4997
adaaaa	adaaaa	1000-01-05	-4996	adaaaa	-4996
aeaaaaa	aeaaaaa	1000-01-06	-4995	aeaaaaa	-4995
afaaaaaa	afaaaaaa	1000-01-07	-4994	afaaaaaa	-4994
agaaaaaaa	agaaaaaaa	1000-01-08	-4993	agaaaaaaa	-4993
updated	abc	2005-10-03	100	uvw	1000
updated	xyz	1949-05-23	100	uvw	1000
updated	xyz	1989-11-09	100	uvw	1000
updated	xyz	2005-10-24	100	uvw	1000
CALL sp_ins_upd();
COUNT( f1 )	f1
1	aaa
1	abaa
1	acaaa
1	adaaaa
1	aeaaaaa
1	afaaaaaa
1	agaaaaaaa
1	a^aaaaaaaa
1	a_aaaaaaaaa
1	a`
4	qwe
4	updated
SELECT row_count();
row_count()
3
SELECT * FROM temp;
f1	f2	f3	f4	f5	f6
unknown's avatar
unknown committed
315 316
a^aaaaaaaa	a^aaaaaaaa	1000-01-09	-4992	a^aaaaaaaa	-4992
a_aaaaaaaaa	a_aaaaaaaaa	1000-01-10	-4991	a_aaaaaaaaa	-4991
317 318 319 320 321 322 323 324
a`	a`	1000-01-01	-5000	a`	-5000
aaa	aaa	1000-01-02	-4999	aaa	-4999
abaa	abaa	1000-01-03	-4998	abaa	-4998
acaaa	acaaa	1000-01-04	-4997	acaaa	-4997
adaaaa	adaaaa	1000-01-05	-4996	adaaaa	-4996
aeaaaaa	aeaaaaa	1000-01-06	-4995	aeaaaaa	-4995
afaaaaaa	afaaaaaa	1000-01-07	-4994	afaaaaaa	-4994
agaaaaaaa	agaaaaaaa	1000-01-08	-4993	agaaaaaaa	-4993
unknown's avatar
unknown committed
325
qwe	xyz	1998-03-26	100	uvw	1000
326 327 328 329 330 331 332
updated	abc	2005-10-03	100	uvw	1000
updated	xyz	1949-05-23	100	uvw	1000
updated	xyz	1989-11-09	100	uvw	1000
updated	xyz	2005-10-24	100	uvw	1000
updated_2	abc	1989-11-09	100	uvw	1000
updated_2	abc	2000-11-09	100	uvw	1000
updated_2	abc	2005-11-07	100	uvw	1000
unknown's avatar
unknown committed
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
CALL sp_del();
SELECT row_count();
row_count()
4
SELECT * FROM temp;
f1	f2	f3	f4	f5	f6
a^aaaaaaaa	a^aaaaaaaa	1000-01-09	-4992	a^aaaaaaaa	-4992
a_aaaaaaaaa	a_aaaaaaaaa	1000-01-10	-4991	a_aaaaaaaaa	-4991
a`	a`	1000-01-01	-5000	a`	-5000
aaa	aaa	1000-01-02	-4999	aaa	-4999
abaa	abaa	1000-01-03	-4998	abaa	-4998
acaaa	acaaa	1000-01-04	-4997	acaaa	-4997
adaaaa	adaaaa	1000-01-05	-4996	adaaaa	-4996
aeaaaaa	aeaaaaa	1000-01-06	-4995	aeaaaaa	-4995
afaaaaaa	afaaaaaa	1000-01-07	-4994	afaaaaaa	-4994
agaaaaaaa	agaaaaaaa	1000-01-08	-4993	agaaaaaaa	-4993
updated	abc	2005-10-03	100	uvw	1000
updated	xyz	1949-05-23	100	uvw	1000
updated	xyz	1989-11-09	100	uvw	1000
updated	xyz	2005-10-24	100	uvw	1000
DELETE FROM temp;
CALL sp_with_rowcount();
row_count() after insert
4
row_count() after select row_count()
-1
f1	f2	f3
qwe	abc	1989-11-09
qwe	abc	2000-11-09
qwe	xyz	1998-03-26
qwe	xyz	2005-11-07
row_count() after update
2
f1	f2	f3
qwe	xyz	1998-03-26
qwe	xyz	2005-11-07
updated_2	abc	1989-11-09
updated_2	abc	2000-11-09
row_count() after delete
2
SELECT row_count();
row_count()
-1
SELECT * FROM temp;
f1	f2	f3	f4	f5	f6
qwe	xyz	1998-03-26	100	uvw	1000
qwe	xyz	2005-11-07	100	uvw	1000
380 381 382 383
DROP PROCEDURE sp_ins_1;
DROP PROCEDURE sp_ins_3;
DROP PROCEDURE sp_upd;
DROP PROCEDURE sp_ins_upd;
unknown's avatar
unknown committed
384 385
DROP PROCEDURE sp_del;
DROP PROCEDURE sp_with_rowcount;
386 387 388 389 390
DROP TABLE temp;

Testcase 3.1.10.8:
------------------

unknown's avatar
unknown committed
391
Ensure that the mysql_affected_rows() C API function always returns the correct
392 393 394 395 396 397 398 399 400 401
number of rows affected by the execution of a stored procedure.
--------------------------------------------------------------------------------

--source suite/funcs_1/storedproc/cleanup_sp_tb.inc
--------------------------------------------------------------------------------
DROP DATABASE IF EXISTS db_storedproc;
DROP DATABASE IF EXISTS db_storedproc_1;

.                               +++ END OF SCRIPT +++
--------------------------------------------------------------------------------