-
Notifications
You must be signed in to change notification settings - Fork 195
/
test_200_MultipleRsltsetsUniformColDefs.py
247 lines (232 loc) · 5.43 KB
/
test_200_MultipleRsltsetsUniformColDefs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
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
189
190
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#
# Licensed Materials - Property of IBM
#
# (c) Copyright IBM Corp. 2007-2008
#
from __future__ import print_function
import sys
import unittest
import ibm_db
import config
from testfunctions import IbmDbTestFunctions
from unittest import TestCase
TestCase.maxDiff=None
class IbmDbTestCase(unittest.TestCase):
def test_200_MultipleRsltsetsUniformColDefs(self):
obj = IbmDbTestFunctions()
obj.assert_expect(self.run_test_200)
self.maxDiff = None
def run_test_200(self):
conn = ibm_db.connect(config.database, config.user, config.password)
serverinfo = ibm_db.server_info( conn )
server = serverinfo.DBMS_NAME[0:3]
if (server == 'IDS'):
procedure = """
CREATE FUNCTION multiResults()
RETURNING CHAR(16), INT;
DEFINE p_name CHAR(16);
DEFINE p_id INT;
FOREACH c1 FOR
SELECT name, id
INTO p_name, p_id
FROM animals
ORDER BY name
RETURN p_name, p_id WITH RESUME;
END FOREACH;
END FUNCTION;
"""
else:
procedure = """
CREATE PROCEDURE multiResults ()
RESULT SETS 3
LANGUAGE SQL
BEGIN
DECLARE c1 CURSOR WITH RETURN FOR
SELECT name, id
FROM animals
ORDER BY name;
DECLARE c2 CURSOR WITH RETURN FOR
SELECT name, id
FROM animals
WHERE id < 4
ORDER BY name DESC;
DECLARE c3 CURSOR WITH RETURN FOR
SELECT name, id
FROM animals
WHERE weight < 5.0
ORDER BY name;
OPEN c1;
OPEN c2;
OPEN c3;
END
"""
if conn:
try:
ibm_db.exec_immediate(conn, 'DROP PROCEDURE multiResults')
except:
pass
ibm_db.exec_immediate(conn, procedure)
if sys.platform == 'zos':
stmt = ibm_db.exec_immediate(conn, 'CALL MULTIRESULTS()')
else:
stmt = ibm_db.exec_immediate(conn, 'CALL multiresults()')
#print(stmt)
print("Fetching first result set")
row = ibm_db.fetch_tuple(stmt)
while ( row ):
for i in row:
print(i)
row = ibm_db.fetch_tuple(stmt)
if (server == 'IDS'):
print("Fetching second result set (should fail -- IDS does not support multiple result sets)")
else:
print("Fetching second result set")
#print(stmt)
res = ibm_db.next_result (stmt)
if res:
row = ibm_db.fetch_tuple(res)
while ( row ):
for i in row:
print(i)
row = ibm_db.fetch_tuple(res)
if (server == 'IDS'):
print("Fetching third result set (should fail -- IDS does not support multiple result sets)")
else:
print("Fetching third result set")
res2 = ibm_db.next_result(stmt)
if res2:
row = ibm_db.fetch_tuple(res2)
while ( row ):
for i in row:
print(i)
row = ibm_db.fetch_tuple(res2)
print("Fetching fourth result set (should fail)")
res3 = ibm_db.next_result(stmt)
if res3:
row = ibm_db.fetch_tuple(res3)
while ( row ):
for i in row:
print(i)
row = ibm_db.fetch_tuple(res3)
ibm_db.close(conn)
else:
print("Connection failed.")
#__END__
#__LUW_EXPECTED__
#Fetching first result set
#Bubbles
#3
#Gizmo
#4
#Peaches
#1
#Pook
#0
#Rickety Ride
#5
#Smarty
#2
#Sweater
#6
#Fetching second result set
#Smarty
#2
#Pook
#0
#Peaches
#1
#Bubbles
#3
#Fetching third result set
#Bubbles
#3
#Gizmo
#4
#Pook
#0
#Fetching fourth result set (should fail)
#__ZOS_EXPECTED__
#Fetching first result set
#Bubbles
#3
#Gizmo
#4
#Peaches
#1
#Pook
#0
#Rickety Ride
#5
#Smarty
#2
#Sweater
#6
#Fetching second result set
#Smarty
#2
#Pook
#0
#Peaches
#1
#Bubbles
#3
#Fetching third result set
#Bubbles
#3
#Gizmo
#4
#Pook
#0
#Fetching fourth result set (should fail)
#__SYSTEMI_EXPECTED__
#Fetching first result set
#Bubbles
#3
#Gizmo
#4
#Peaches
#1
#Pook
#0
#Rickety Ride
#5
#Smarty
#2
#Sweater
#6
#Fetching second result set
#Smarty
#2
#Pook
#0
#Peaches
#1
#Bubbles
#3
#Fetching third result set
#Bubbles
#3
#Gizmo
#4
#Pook
#0
#Fetching fourth result set (should fail)
#__IDS_EXPECTED__
#Fetching first result set
#Bubbles
#3
#Gizmo
#4
#Peaches
#1
#Pook
#0
#Rickety Ride
#5
#Smarty
#2
#Sweater
#6
#Fetching second result set (should fail -- IDS does not support multiple result sets)
#Fetching third result set (should fail -- IDS does not support multiple result sets)
#Fetching fourth result set (should fail)