~linuxjedi/drizzle/trunk-bug-667053

« back to all changes in this revision

Viewing changes to mysql-test/suite/funcs_1/storedproc/storedproc_10.inc

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#### suite/funcs_1/storedproc/storedproc_10.inc
 
2
#
 
3
--source suite/funcs_1/storedproc/load_sp_tb.inc
 
4
 
 
5
# ==============================================================================
 
6
# (numbering from requirement document TP v1.0, Last updated: 25 Jan 2005 01:00)
 
7
#
 
8
# 3.1.10 CALL checks:
 
9
#
 
10
## 1. Ensure that a properly defined procedure can always be called, assuming the appropriate privileges exist.
 
11
#- 2. Ensure that a procedure cannot be called if the appropriate privileges do not exist.
 
12
## 3. Ensure that a function can never be called.
 
13
## 4. Ensure that a properly defined function can always be executed, assuming the appropriate privileges exist.
 
14
#- 5. Ensure that a function cannot be executed if the appropriate privileges do not exist.
 
15
## 6. Ensure that a procedure can never be executed.
 
16
## 7. Ensure that the ROW_COUNT() SQL function always returns the correct number of rows affected by the execution of a stored procedure.
 
17
## 8. Ensure that the mysql_affected_rows() C API function always returns the correct number of rows affected by the execution of a stored procedure.
 
18
#
 
19
# ==============================================================================
 
20
let $message= Section 3.1.10 - CALL checks:;
 
21
--source include/show_msg80.inc
 
22
 
 
23
 
 
24
USE db_storedproc;
 
25
 
 
26
# ------------------------------------------------------------------------------
 
27
let $message= Testcase 3.1.10.2 + 3.1.10.5:;
 
28
--source include/show_msg.inc
 
29
let $message=
 
30
2. Ensure that a procedure cannot be called if the appropriate privileges do not
 
31
   exist.
 
32
5. Ensure that a function cannot be executed if the appropriate privileges do
 
33
   not exist.;
 
34
--source include/show_msg80.inc
 
35
 
 
36
--disable_warnings
 
37
DROP PROCEDURE IF EXISTS sp31102;
 
38
DROP FUNCTION  IF EXISTS fn31105;
 
39
--enable_warnings
 
40
 
 
41
# DEFINER
 
42
create user 'user_1'@'localhost';
 
43
# INVOKER
 
44
create user 'user_2'@'localhost';
 
45
 
 
46
GRANT CREATE ROUTINE ON db_storedproc.* TO 'user_1'@'localhost';
 
47
GRANT SELECT         ON db_storedproc.* TO 'user_2'@'localhost';
 
48
FLUSH PRIVILEGES;
 
49
 
 
50
--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
 
51
connect (user2_1, localhost, user_1, , db_storedproc);
 
52
--source suite/funcs_1/include/show_connection.inc
 
53
 
 
54
delimiter //;
 
55
CREATE PROCEDURE sp31102 () SQL SECURITY INVOKER
 
56
BEGIN
 
57
   SELECT * FROM db_storedproc.t1 WHERE f4=-5000 LIMIT 1;
 
58
END//
 
59
delimiter ;//
 
60
 
 
61
delimiter //;
 
62
CREATE FUNCTION fn31105(n INT) RETURNS INT
 
63
  BEGIN
 
64
  DECLARE res INT;
 
65
  SET res = n * n;
 
66
  RETURN res;
 
67
END//
 
68
delimiter ;//
 
69
 
 
70
disconnect user2_1;
 
71
 
 
72
--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
 
73
connect (user2_2, localhost, user_2, , db_storedproc);
 
74
--source suite/funcs_1/include/show_connection.inc
 
75
 
 
76
# no privileges exist
 
77
--error ER_PROCACCESS_DENIED_ERROR
 
78
CALL sp31102();
 
79
SELECT fn31105( 9 );
 
80
 
 
81
# now 'add' EXECUTE to INVOKER
 
82
--echo connection default;
 
83
connection default;
 
84
USE db_storedproc;
 
85
--source suite/funcs_1/include/show_connection.inc
 
86
# root can execute ...
 
87
CALL sp31102();
 
88
SELECT fn31105( 9 );
 
89
GRANT EXECUTE ON db_storedproc.* TO 'user_2'@'localhost';
 
90
FLUSH PRIVILEGES;
 
91
disconnect user2_2;
 
92
 
 
93
# new connection
 
94
--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
 
95
connect (user2_3, localhost, user_2, , db_storedproc);
 
96
--source suite/funcs_1/include/show_connection.inc
 
97
CALL sp31102();
 
98
SELECT fn31105( 9 );
 
99
disconnect user2_3;
 
100
 
 
101
# now 'remove' SELECT from INVOKER
 
102
--echo connection default;
 
103
connection default;
 
104
USE db_storedproc;
 
105
--source suite/funcs_1/include/show_connection.inc
 
106
REVOKE EXECUTE ON db_storedproc.* FROM 'user_2'@'localhost';
 
107
FLUSH PRIVILEGES;
 
108
 
 
109
# root can still execute
 
110
CALL sp31102();
 
111
SELECT fn31105( 9 );
 
112
 
 
113
--replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
 
114
connect (user2_4, localhost, user_2, , db_storedproc);
 
115
--source suite/funcs_1/include/show_connection.inc
 
116
CALL sp31102();
 
117
SELECT fn31105( 9 );
 
118
disconnect user2_4;
 
119
 
 
120
# cleanup
 
121
connection default;
 
122
USE db_storedproc;
 
123
 
 
124
--source suite/funcs_1/include/show_connection.inc
 
125
DROP PROCEDURE sp31102;
 
126
DROP FUNCTION  fn31105;
 
127
DROP USER 'user_1'@'localhost';
 
128
DROP USER 'user_2'@'localhost';
 
129
 
 
130
 
 
131
# ------------------------------------------------------------------------------
 
132
let $message= Testcase 3.1.10.3:;
 
133
--source include/show_msg.inc
 
134
let $message=
 
135
Ensure that a function can never be called.;
 
136
--source include/show_msg80.inc
 
137
 
 
138
--disable_warnings
 
139
DROP FUNCTION IF EXISTS fn1;
 
140
--enable_warnings
 
141
 
 
142
delimiter //;
 
143
CREATE FUNCTION fn1(a int) returns int
 
144
BEGIN
 
145
    set @b = 0.9 * a;
 
146
    return @b;
 
147
END//
 
148
delimiter ;//
 
149
 
 
150
--error ER_SP_DOES_NOT_EXIST
 
151
CALL fn1();
 
152
 
 
153
# cleanup
 
154
DROP FUNCTION fn1;
 
155
 
 
156
 
 
157
# ------------------------------------------------------------------------------
 
158
let $message= Testcase 3.1.10.6:;
 
159
--source include/show_msg.inc
 
160
let $message=
 
161
Ensure that a procedure can never be executed.;
 
162
--source include/show_msg80.inc
 
163
 
 
164
--disable_warnings
 
165
DROP PROCEDURE IF EXISTS sp1;
 
166
DROP FUNCTION IF EXISTS sp1;
 
167
--enable_warnings
 
168
 
 
169
delimiter //;
 
170
CREATE PROCEDURE sp1()
 
171
BEGIN
 
172
    SELECT * from t10;
 
173
END//
 
174
delimiter ;//
 
175
 
 
176
--error ER_SP_DOES_NOT_EXIST
 
177
  SELECT sp1();
 
178
 
 
179
# cleanup
 
180
DROP PROCEDURE sp1;
 
181
 
 
182
 
 
183
# ------------------------------------------------------------------------------
 
184
let $message= Testcase 3.1.10.7:;
 
185
--source include/show_msg.inc
 
186
let $message=
 
187
Ensure that the ROW_COUNT() SQL function always returns the correct number of
 
188
rows affected by the execution of a stored procedure.;
 
189
--source include/show_msg80.inc
 
190
# Note(mleich): Information taken from a comments in
 
191
#     Bug#21818 Return value of ROW_COUNT() is incorrect for
 
192
#               ALTER TABLE, LOAD DATA
 
193
#     ROW_COUNT() is -1 following any statement which is not DELETE, INSERT
 
194
#     or UPDATE.
 
195
#     Also, after a CALL statement, ROW_COUNT() will return the value of the
 
196
#     last statement in the stored procedure.
 
197
 
 
198
--disable_warnings
 
199
DROP PROCEDURE IF EXISTS sp_ins_1;
 
200
DROP PROCEDURE IF EXISTS sp_ins_3;
 
201
DROP PROCEDURE IF EXISTS sp_upd;
 
202
DROP PROCEDURE IF EXISTS sp_ins_upd;
 
203
DROP PROCEDURE IF EXISTS sp_del;
 
204
DROP PROCEDURE IF EXISTS sp_with_rowcount;
 
205
--enable_warnings
 
206
 
 
207
CREATE TABLE temp(f1 CHAR(20),f2 CHAR(25),f3 DATE,f4 INT,f5 CHAR(25),f6 INT);
 
208
INSERT INTO temp SELECT * FROM t10;
 
209
 
 
210
delimiter //;
 
211
CREATE PROCEDURE sp_ins_1()
 
212
BEGIN
 
213
  INSERT INTO temp VALUES ('abc', 'abc', '20051003', 100, 'uvw', 1000);
 
214
END//
 
215
 
 
216
CREATE PROCEDURE sp_ins_3()
 
217
BEGIN
 
218
  INSERT INTO temp VALUES  ('abc', 'xyz', '19490523',   100, 'uvw', 1000);
 
219
  INSERT INTO temp VALUES  ('abc', 'xyz', '1989-11-09', 100, 'uvw', 1000);
 
220
  INSERT INTO temp VALUES  ('abc', 'xyz', '2005-10-24', 100, 'uvw', 1000);
 
221
END//
 
222
 
 
223
CREATE PROCEDURE sp_upd()
 
224
BEGIN
 
225
  UPDATE temp SET temp.f1 = 'updated' WHERE temp.f1 ='abc';
 
226
END//
 
227
 
 
228
CREATE PROCEDURE sp_ins_upd()
 
229
BEGIN
 
230
   BEGIN
 
231
      INSERT INTO temp VALUES  ('qwe', 'abc', '1989-11-09', 100, 'uvw', 1000);
 
232
      INSERT INTO temp VALUES  ('qwe', 'xyz', '1998-03-26', 100, 'uvw', 1000);
 
233
      INSERT INTO temp VALUES  ('qwe', 'abc', '2000-11-09', 100, 'uvw', 1000);
 
234
      INSERT INTO temp VALUES  ('qwe', 'abc', '2005-11-07', 100, 'uvw', 1000);
 
235
   END;
 
236
   SELECT COUNT( f1 ), f1 FROM temp GROUP BY f1;
 
237
   UPDATE temp SET temp.f1 = 'updated_2' WHERE temp.f1 ='qwe' AND temp.f2 = 'abc';
 
238
END//
 
239
 
 
240
CREATE PROCEDURE sp_del()
 
241
BEGIN
 
242
  DELETE FROM temp WHERE temp.f1 ='qwe' OR temp.f1 = 'updated_2';
 
243
END//
 
244
 
 
245
CREATE PROCEDURE sp_with_rowcount()
 
246
BEGIN
 
247
   BEGIN
 
248
      INSERT INTO temp VALUES  ('qwe', 'abc', '1989-11-09', 100, 'uvw', 1000),
 
249
                               ('qwe', 'xyz', '1998-03-26', 100, 'uvw', 1000),
 
250
                               ('qwe', 'abc', '2000-11-09', 100, 'uvw', 1000),
 
251
                               ('qwe', 'xyz', '2005-11-07', 100, 'uvw', 1000);
 
252
   END;
 
253
   SELECT row_count() AS 'row_count() after insert';
 
254
   SELECT row_count() AS 'row_count() after select row_count()';
 
255
   SELECT f1,f2,f3 FROM temp ORDER BY f1,f2,f3;
 
256
   UPDATE temp SET temp.f1 = 'updated_2' WHERE temp.f2 = 'abc';
 
257
   SELECT row_count() AS 'row_count() after update';
 
258
   SELECT f1,f2,f3 FROM temp ORDER BY f1,f2,f3;
 
259
   DELETE FROM temp WHERE temp.f1 = 'updated_2';
 
260
   SELECT row_count() AS 'row_count() after delete';
 
261
END//
 
262
delimiter ;//
 
263
 
 
264
CALL sp_ins_1();
 
265
SELECT row_count();
 
266
--sorted_result
 
267
SELECT * FROM temp;
 
268
 
 
269
CALL sp_ins_3();
 
270
SELECT row_count();
 
271
--sorted_result
 
272
SELECT * FROM temp;
 
273
 
 
274
CALL sp_upd();
 
275
SELECT row_count();
 
276
--sorted_result
 
277
SELECT * FROM temp;
 
278
 
 
279
CALL sp_ins_upd();
 
280
SELECT row_count();
 
281
--sorted_result
 
282
SELECT * FROM temp;
 
283
 
 
284
CALL sp_del();
 
285
SELECT row_count();
 
286
--sorted_result
 
287
SELECT * FROM temp;
 
288
 
 
289
DELETE FROM temp;
 
290
CALL sp_with_rowcount();
 
291
SELECT row_count();
 
292
--sorted_result
 
293
SELECT * FROM temp;
 
294
 
 
295
 
 
296
# cleanup
 
297
DROP PROCEDURE sp_ins_1;
 
298
DROP PROCEDURE sp_ins_3;
 
299
DROP PROCEDURE sp_upd;
 
300
DROP PROCEDURE sp_ins_upd;
 
301
DROP PROCEDURE sp_del;
 
302
DROP PROCEDURE sp_with_rowcount;
 
303
DROP TABLE temp;
 
304
 
 
305
 
 
306
# ------------------------------------------------------------------------------
 
307
let $message= Testcase 3.1.10.8:;
 
308
--source include/show_msg.inc
 
309
let $message=
 
310
Ensure that the mysql_affected_rows() C API function always returns the correct 
 
311
number of rows affected by the execution of a stored procedure.;
 
312
--source include/show_msg80.inc
 
313
 
 
314
#FIXME: 3.1.10.8: to be added later.
 
315
 
 
316
# ==============================================================================
 
317
# USE the same .inc to cleanup before and after the test
 
318
--source suite/funcs_1/storedproc/cleanup_sp_tb.inc
 
319
 
 
320
# ==============================================================================
 
321
let $message= .                               +++ END OF SCRIPT +++;
 
322
--source include/show_msg80.inc
 
323
# ==============================================================================