~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to mysql-test/t/init_connect.test

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# Test of init_connect variable
 
3
#
 
4
 
 
5
# should work with embedded server after mysqltest is fixed
 
6
--source include/not_embedded.inc
 
7
 
 
8
# Save the initial number of concurrent sessions
 
9
--source include/count_sessions.inc
 
10
 
 
11
--source include/add_anonymous_users.inc
 
12
 
 
13
connect (con0,localhost,root,,);
 
14
connection con0;
 
15
select hex(@a);
 
16
connect (con1,localhost,user_1,,);
 
17
connection con1;
 
18
select hex(@a);
 
19
connection con0;
 
20
set global init_connect="set @a=2;set @b=3";
 
21
connect (con2,localhost,user_1,,);
 
22
connection con2;
 
23
select @a, @b;
 
24
connection con0;
 
25
set GLOBAL init_connect=DEFAULT;
 
26
connect (con3,localhost,user_1,,);
 
27
connection con3;
 
28
select @a;
 
29
connection con0;
 
30
set global init_connect="drop table if exists t1; create table t1(a char(10));\
 
31
insert into t1 values ('\0');insert into t1 values('abc')";
 
32
connect (con4,localhost,user_1,,);
 
33
connection con4;
 
34
select hex(a) from t1;
 
35
connection con0;
 
36
set GLOBAL init_connect="adsfsdfsdfs";
 
37
connect (con5,localhost,user_1,,);
 
38
connection con5;
 
39
--error 2013,2006
 
40
select @a;
 
41
connection con0;
 
42
drop table t1;
 
43
 
 
44
disconnect con1;
 
45
disconnect con2;
 
46
disconnect con3;
 
47
disconnect con4;
 
48
disconnect con5;
 
49
 
 
50
--source include/delete_anonymous_users.inc
 
51
 
 
52
--echo End of 4.1 tests
 
53
#
 
54
# Test 5.* features
 
55
#
 
56
 
 
57
create table t1 (x int);
 
58
insert into t1 values (3), (5), (7);
 
59
create table t2 (y int);
 
60
 
 
61
create user mysqltest1@localhost;
 
62
grant all privileges on test.* to mysqltest1@localhost;
 
63
#
 
64
# Create a simple procedure
 
65
#
 
66
set global init_connect="create procedure p1() select * from t1";
 
67
connect (con1,localhost,mysqltest1,,);
 
68
connection con1;
 
69
call p1();
 
70
drop procedure p1;
 
71
 
 
72
connection con0;
 
73
disconnect con1;
 
74
#
 
75
# Create a multi-result set procedure
 
76
#
 
77
set global init_connect="create procedure p1(x int)\
 
78
begin\
 
79
  select count(*) from t1;\
 
80
  select * from t1;\
 
81
  set @x = x;
 
82
end";
 
83
connect (con1,localhost,mysqltest1,,);
 
84
connection con1;
 
85
call p1(42);
 
86
select @x;
 
87
 
 
88
connection con0;
 
89
disconnect con1;
 
90
#
 
91
# Just call it - this will not generate any output
 
92
#
 
93
set global init_connect="call p1(4711)";
 
94
connect (con1,localhost,mysqltest1,,);
 
95
connection con1;
 
96
select @x;
 
97
 
 
98
connection con0;
 
99
disconnect con1;
 
100
#
 
101
# Drop the procedure
 
102
#
 
103
set global init_connect="drop procedure if exists p1";
 
104
connect (con1,localhost,mysqltest1,,);
 
105
connection con1;
 
106
--error ER_SP_DOES_NOT_EXIST
 
107
call p1();
 
108
 
 
109
connection con0;
 
110
disconnect con1;
 
111
#
 
112
# Execution of a more complex procedure
 
113
#
 
114
delimiter |;
 
115
create procedure p1(out sum int)
 
116
begin
 
117
  declare n int default 0;
 
118
  declare c cursor for select * from t1;
 
119
  declare exit handler for not found
 
120
    begin
 
121
      close c;
 
122
      set sum = n;
 
123
    end;
 
124
 
 
125
  open c;
 
126
  loop
 
127
    begin
 
128
      declare x int;
 
129
 
 
130
      fetch c into x;
 
131
      if x > 3 then
 
132
        set n = n + x;
 
133
      end if;
 
134
    end;
 
135
  end loop;
 
136
end|
 
137
delimiter ;|
 
138
# Call the procedure with a cursor
 
139
set global init_connect="call p1(@sum)";
 
140
connect (con1,localhost,mysqltest1,,);
 
141
connection con1;
 
142
select @sum;
 
143
 
 
144
connection con0;
 
145
disconnect con1;
 
146
drop procedure p1;
 
147
#
 
148
# Test Dynamic SQL
 
149
#
 
150
delimiter |;
 
151
create procedure p1(tbl char(10), v int)
 
152
begin
 
153
  set @s = concat('insert into ', tbl, ' values (?)');
 
154
  set @v = v;
 
155
  prepare stmt1 from @s;
 
156
  execute stmt1 using @v;
 
157
  deallocate prepare stmt1;
 
158
end|
 
159
delimiter ;|
 
160
# Call the procedure with prepared statements
 
161
set global init_connect="call p1('t1', 11)";
 
162
connect (con1,localhost,mysqltest1,,);
 
163
connection con1;
 
164
select * from t1;
 
165
 
 
166
connection con0;
 
167
disconnect con1;
 
168
drop procedure p1;
 
169
#
 
170
# Stored functions
 
171
#
 
172
delimiter |;
 
173
create function f1() returns int
 
174
begin
 
175
  declare n int;
 
176
 
 
177
  select count(*) into n from t1;
 
178
  return n;
 
179
end|
 
180
delimiter ;|
 
181
# Invoke a function
 
182
set global init_connect="set @x = f1()";
 
183
connect (con1,localhost,mysqltest1,,);
 
184
connection con1;
 
185
select @x;
 
186
 
 
187
connection con0;
 
188
disconnect con1;
 
189
#
 
190
# Create a view
 
191
#
 
192
set global init_connect="create view v1 as select f1()";
 
193
connect (con1,localhost,mysqltest1,,);
 
194
connection con1;
 
195
select * from v1;
 
196
 
 
197
connection con0;
 
198
disconnect con1;
 
199
#
 
200
# Drop the view
 
201
#
 
202
set global init_connect="drop view v1";
 
203
connect (con1,localhost,mysqltest1,,);
 
204
connection con1;
 
205
--error ER_NO_SUCH_TABLE
 
206
select * from v1;
 
207
 
 
208
connection con0;
 
209
disconnect con1;
 
210
drop function f1;
 
211
 
 
212
# We can't test "create trigger", since this requires super privileges
 
213
# in 5.0, but with super privileges, init_connect is not executed.
 
214
# (However, this can be tested in 5.1)
 
215
#
 
216
#set global init_connect="create trigger trg1\
 
217
#  after insert on t2\
 
218
#  for each row\
 
219
#  insert into t1 values (new.y)";
 
220
#connect (con1,localhost,mysqltest1,,);
 
221
#connection con1;
 
222
#insert into t2 values (2), (4);
 
223
#select * from t1;
 
224
#
 
225
#connection con0;
 
226
#disconnect con1;
 
227
 
 
228
create trigger trg1
 
229
  after insert on t2
 
230
  for each row
 
231
  insert into t1 values (new.y);
 
232
 
 
233
# Invoke trigger
 
234
set global init_connect="insert into t2 values (13), (17), (19)";
 
235
connect (con1,localhost,mysqltest1,,);
 
236
connection con1;
 
237
select * from t1;
 
238
 
 
239
connection default;
 
240
disconnect con0;
 
241
disconnect con1;
 
242
 
 
243
drop trigger trg1;
 
244
# Set init connect back to the value provided in init_connect-master.opt
 
245
# doesn't matter as server will be restarted
 
246
set global init_connect="set @a='a\\0c'";
 
247
 
 
248
revoke all privileges, grant option from mysqltest1@localhost;
 
249
drop user mysqltest1@localhost;
 
250
drop table t1, t2;
 
251
 
 
252
# Wait till all disconnects are completed
 
253
--source include/wait_until_count_sessions.inc
 
254