Annotation of embedaddon/php/ext/oci8/tests/bug43497_92.phpt, revision 1.1.1.2
1.1 misho 1: --TEST--
2: Bug #43497 (OCI8 XML/getClobVal aka temporary LOBs leak UGA memory)
3: --SKIPIF--
4: <?php
5: $target_dbs = array('oracledb' => true, 'timesten' => false); // test runs on these DBs
6: require(dirname(__FILE__).'/skipif.inc');
7: if (getenv('SKIP_SLOW_TESTS')) die('skip slow tests excluded by request');
1.1.1.2 ! misho 8: ob_start();
! 9: phpinfo(INFO_MODULES);
! 10: $phpinfo = ob_get_clean();
! 11: $iv = preg_match('/Oracle .*Version => (9\.2)/', $phpinfo);
! 12: if ($iv != 1) {
! 13: die ("skip tests a feature that works only with Oracle 9iR2 client");
1.1 misho 14: }
15: ?>
16: --FILE--
17: <?php
18:
19: require dirname(__FILE__).'/connect.inc';
20:
21: function sessionid($c) // determines and returns current session ID
22: {
23: $query = "select sid from v\$session where audsid = userenv('sessionid')";
24:
25: $stmt = oci_parse($c, $query);
26:
27: if (oci_execute($stmt, OCI_DEFAULT)) {
28: $row = oci_fetch($stmt);
29: return oci_result($stmt, 1);
30: }
31:
32: return null;
33: }
34:
35:
36: function templobs($c, $sid) // returns number of temporary LOBs
37: {
38: $query = "select abstract_lobs from v\$temporary_lobs where sid = " . $sid;
39:
40: $stmt = oci_parse($c, $query);
41:
42: if (oci_execute($stmt, OCI_DEFAULT)) {
43: $row = oci_fetch($stmt);
44: $val = oci_result($stmt, 1);
45: oci_free_statement($stmt);
46: return $val;
47: }
48: return null;
49: }
50:
51:
52: // Read all XML data using explicit LOB locator
53: function readxmltab_ex($c)
54: {
55: $stmt = oci_parse($c, "select extract(xml, '/').getclobval() from bug43497_tab");
56:
57: $cntchk = 0;
58: if (oci_execute($stmt)) {
59: while ($result = oci_fetch_array($stmt, OCI_NUM)) {
60: $result[0]->free(); // cleanup properly
61: ++$cntchk;
62: }
63: }
64: echo "Loop count check = $cntchk\n";
65: }
66:
67: // Read all XML data using explicit LOB locator but without freeing the temp lobs
68: function readxmltab_ex_nofree($c)
69: {
70: $stmt = oci_parse($c, "select extract(xml, '/').getclobval() from bug43497_tab");
71:
72: $cntchk = 0;
73: if (oci_execute($stmt)) {
74: while ($result = oci_fetch_array($stmt, OCI_NUM)) {
75: ++$cntchk;
76: }
77: }
78: echo "Loop count check = $cntchk\n";
79: }
80:
81: // Read all XML data using implicit LOB locator
82: function readxmltab_im($c)
83: {
84: $stmt = oci_parse($c, "select extract(xml, '/').getclobval() from bug43497_tab");
85:
86: $cntchk = 0;
87: if (oci_execute($stmt)) {
88: while ($result = oci_fetch_array($stmt, OCI_NUM+OCI_RETURN_LOBS)) {
89: ++$cntchk;
90: }
91: }
92: echo "Loop count check = $cntchk\n";
93: }
94:
95: function createxmltab($c) // create table w/ field of XML type
96: {
97: @dropxmltab($c);
98: $stmt = oci_parse($c, "create table bug43497_tab (id number primary key, xml xmltype)");
99: oci_execute($stmt);
100: }
101:
102: function dropxmltab($c) // delete table
103: {
104: $stmt = oci_parse($c, "drop table bug43497_tab");
105: oci_execute($stmt);
106: }
107:
108:
109: function fillxmltab($c)
110: {
111: for ($id = 1; $id <= 100; $id++) {
112:
113: // create an XML element string with random data
114: $s = "<data>";
115: for ($j = 0; $j < 128; $j++) {
116: $s .= rand();
117: }
118: $s .= "</data>\n";
119: for ($j = 0; $j < 4; $j++) {
120: $s .= $s;
121: }
122: $data = "<?xml version=\"1.0\"?><records>" . $s . "</records>";
123:
124: // insert XML data into database
125:
126: $stmt = oci_parse($c, "insert into bug43497_tab(id, xml) values (:id, sys.xmltype.createxml(:xml))");
127: oci_bind_by_name($stmt, ":id", $id);
128: $clob = oci_new_descriptor($c, OCI_D_LOB);
129: oci_bind_by_name($stmt, ":xml", $clob, -1, OCI_B_CLOB);
130: $clob->writetemporary($data);
131: oci_execute($stmt);
132:
133: $clob->close();
134: $clob->free();
135: }
136: }
137:
138:
139: // Initialize
140:
141: createxmltab($c);
142: fillxmltab($c);
143:
144: // Run Test
145:
146: $sid = sessionid($c);
147:
148: echo "Explicit LOB use\n";
149: for ($i = 1; $i <= 10; $i++) {
150: echo "\nRun = " . $i . "\n";
151: echo "Temporary LOBs = " . templobs($c, $sid) . "\n";
152: readxmltab_ex($c);
153: }
154:
155: echo "\nImplicit LOB use\n";
156: for ($i = 1; $i <= 10; $i++) {
157: echo "\nRun = " . $i . "\n";
158: echo "Temporary LOBs = " . templobs($c, $sid) . "\n";
159: readxmltab_im($c);
160: }
161:
162: echo "\nExplicit LOB with no free (i.e. a temp lob leak)\n";
163: for ($i = 1; $i <= 10; $i++) {
164: echo "\nRun = " . $i . "\n";
165: echo "Temporary LOBs = " . templobs($c, $sid) . "\n";
166: readxmltab_ex_nofree($c);
167: }
168:
169:
170:
171: // Cleanup
172:
173: dropxmltab($c);
174:
175: oci_close($c);
176:
177: echo "Done\n";
178: ?>
179: --EXPECT--
180: Explicit LOB use
181:
182: Run = 1
183: Temporary LOBs = 0
184: Loop count check = 100
185:
186: Run = 2
187: Temporary LOBs = 100
188: Loop count check = 100
189:
190: Run = 3
191: Temporary LOBs = 200
192: Loop count check = 100
193:
194: Run = 4
195: Temporary LOBs = 300
196: Loop count check = 100
197:
198: Run = 5
199: Temporary LOBs = 400
200: Loop count check = 100
201:
202: Run = 6
203: Temporary LOBs = 500
204: Loop count check = 100
205:
206: Run = 7
207: Temporary LOBs = 600
208: Loop count check = 100
209:
210: Run = 8
211: Temporary LOBs = 700
212: Loop count check = 100
213:
214: Run = 9
215: Temporary LOBs = 800
216: Loop count check = 100
217:
218: Run = 10
219: Temporary LOBs = 900
220: Loop count check = 100
221:
222: Implicit LOB use
223:
224: Run = 1
225: Temporary LOBs = 1000
226: Loop count check = 100
227:
228: Run = 2
229: Temporary LOBs = 1100
230: Loop count check = 100
231:
232: Run = 3
233: Temporary LOBs = 1200
234: Loop count check = 100
235:
236: Run = 4
237: Temporary LOBs = 1300
238: Loop count check = 100
239:
240: Run = 5
241: Temporary LOBs = 1400
242: Loop count check = 100
243:
244: Run = 6
245: Temporary LOBs = 1500
246: Loop count check = 100
247:
248: Run = 7
249: Temporary LOBs = 1600
250: Loop count check = 100
251:
252: Run = 8
253: Temporary LOBs = 1700
254: Loop count check = 100
255:
256: Run = 9
257: Temporary LOBs = 1800
258: Loop count check = 100
259:
260: Run = 10
261: Temporary LOBs = 1900
262: Loop count check = 100
263:
264: Explicit LOB with no free (i.e. a temp lob leak)
265:
266: Run = 1
267: Temporary LOBs = 2000
268: Loop count check = 100
269:
270: Run = 2
271: Temporary LOBs = 2100
272: Loop count check = 100
273:
274: Run = 3
275: Temporary LOBs = 2200
276: Loop count check = 100
277:
278: Run = 4
279: Temporary LOBs = 2300
280: Loop count check = 100
281:
282: Run = 5
283: Temporary LOBs = 2400
284: Loop count check = 100
285:
286: Run = 6
287: Temporary LOBs = 2500
288: Loop count check = 100
289:
290: Run = 7
291: Temporary LOBs = 2600
292: Loop count check = 100
293:
294: Run = 8
295: Temporary LOBs = 2700
296: Loop count check = 100
297:
298: Run = 9
299: Temporary LOBs = 2800
300: Loop count check = 100
301:
302: Run = 10
303: Temporary LOBs = 2900
304: Loop count check = 100
305: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>