~vkolesnikov/pbxt/pbxt-07-diskfull

« back to all changes in this revision

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

  • Committer: paul-mccullagh
  • Date: 2006-10-23 09:14:04 UTC
  • Revision ID: paul-mccullagh-918861e03d351978a9541168a96e58cc826734ee
Initial import

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