Annotation of embedaddon/php/ext/oci8/tests/bug43497.phpt, revision 1.1.1.1

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>