|
| 1 | +--TEST-- |
| 2 | +LOB prefetching |
| 3 | +--EXTENSIONS-- |
| 4 | +oci8 |
| 5 | +--SKIPIF-- |
| 6 | +<?php |
| 7 | +$target_dbs = array('oracledb' => true, 'timesten' => false); // test runs on these DBs |
| 8 | +require(__DIR__.'/skipif.inc'); |
| 9 | +?> |
| 10 | +--FILE-- |
| 11 | +<?php |
| 12 | + |
| 13 | +require __DIR__.'/connect.inc'; |
| 14 | +require __DIR__.'/create_table.inc'; |
| 15 | + |
| 16 | +define("NUMROWS", 500); |
| 17 | +define("LOBSIZE", 64000); |
| 18 | + |
| 19 | +$ora_sql = |
| 20 | + "declare |
| 21 | + c clob; |
| 22 | + b blob; |
| 23 | + numrows number := 500; |
| 24 | + dest_offset integer := 1; |
| 25 | + src_offset integer := 1; |
| 26 | + warn integer; |
| 27 | + ctx integer := dbms_lob.default_lang_ctx; |
| 28 | + begin |
| 29 | + for j in 1..numrows |
| 30 | + loop |
| 31 | + c := DBMS_RANDOM.string('L',TRUNC(DBMS_RANDOM.value(1000,1000))); |
| 32 | + for i in 1..6 |
| 33 | + loop |
| 34 | + c := c||c; |
| 35 | + end loop; |
| 36 | + dbms_lob.createtemporary(b, false); |
| 37 | + dbms_lob.converttoblob(b, c, dbms_lob.lobmaxsize, dest_offset, src_offset, dbms_lob.default_csid, ctx, warn); |
| 38 | + insert /*+ APPEND */ into ${schema}${table_name} (id, clob, blob) values (j, c, b); |
| 39 | + end loop; |
| 40 | + commit; |
| 41 | + end;"; |
| 42 | + |
| 43 | +$statement = oci_parse($c,$ora_sql); |
| 44 | +oci_execute($statement); |
| 45 | + |
| 46 | + |
| 47 | +function get_clob_loc($c, $sql) { |
| 48 | + $stid = oci_parse($c, $sql); |
| 49 | + oci_execute($stid); |
| 50 | + $l = []; |
| 51 | + while (($row = oci_fetch_array($stid, OCI_ASSOC)) != false) { |
| 52 | + $l[] = $row['CLOB']->load(); |
| 53 | + $row['CLOB']->free(); |
| 54 | + if (strlen($l[0]) != LOBSIZE) { print("strlen(l) failure" . strlen($l)); exit; } |
| 55 | + } |
| 56 | + return($l); |
| 57 | +} |
| 58 | + |
| 59 | +function get_clob_inline($c, $sql) { |
| 60 | + $stid = oci_parse($c, $sql); |
| 61 | + oci_execute($stid); |
| 62 | + $l = []; |
| 63 | + while (($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_LOBS)) != false) { |
| 64 | + $l[] = $row['CLOB']; |
| 65 | + if (strlen($l[0]) != LOBSIZE) { print("strlen(l) failure" . strlen($l)); exit; } |
| 66 | + } |
| 67 | + return($l); |
| 68 | +} |
| 69 | + |
| 70 | +function check_clobs($locarr, $inlinearr) { |
| 71 | + print("Comparing CLOBS\n"); |
| 72 | + for ($i = 0; $i < NUMROWS; ++$i) { |
| 73 | + if (strlen($locarr[$i]) != LOBSIZE) { |
| 74 | + trigger_error("size mismatch at $i " . strlen($locarr[$i]), E_USER_ERROR); |
| 75 | + exit; |
| 76 | + } |
| 77 | + if (strcmp($locarr[$i], $inlinearr[$i])) { |
| 78 | + trigger_error("data mismatch at $i " . strlen($locarr[$i]) . " " . strlen($inlinearr[$i]), E_USER_ERROR); |
| 79 | + exit; |
| 80 | + } |
| 81 | + } |
| 82 | +} |
| 83 | + |
| 84 | +function get_blob_loc($c, $sql) { |
| 85 | + $stid = oci_parse($c, $sql); |
| 86 | + oci_execute($stid); |
| 87 | + $l = []; |
| 88 | + while (($row = oci_fetch_array($stid, OCI_ASSOC)) != false) { |
| 89 | + $l[] = $row['BLOB']->load(); |
| 90 | + $row['BLOB']->free(); |
| 91 | + if (strlen($l[0]) != LOBSIZE) { print("strlen(l) failure" . strlen($l)); exit; } |
| 92 | + } |
| 93 | + return($l); |
| 94 | +} |
| 95 | + |
| 96 | + |
| 97 | +print("Test 1\n"); |
| 98 | + |
| 99 | +$ig = ini_get("oci8.prefetch_lob_size"); |
| 100 | +var_dump($ig); |
| 101 | + |
| 102 | +$ig = ini_set("oci8.prefetch_lob_size", "100000"); |
| 103 | +var_dump($ig); |
| 104 | + |
| 105 | +$ig = ini_get("oci8.prefetch_lob_size"); |
| 106 | +var_dump($ig); |
| 107 | + |
| 108 | +print("Test 2 - CLOB prefetch_lob_size 100000\n"); |
| 109 | + |
| 110 | +$sql = "select clob from ${schema}${table_name}" . " order by id"; |
| 111 | +$locarr = get_clob_loc($c, $sql); |
| 112 | +$inlinearr = get_clob_inline($c, $sql); |
| 113 | + |
| 114 | +print(count($locarr) . "\n"); |
| 115 | +print(count($inlinearr) . "\n"); |
| 116 | +check_clobs($locarr, $inlinearr); |
| 117 | + |
| 118 | +print("Test 3 - CLOB prefetch_lob_size 100\n"); |
| 119 | + |
| 120 | +ini_set("oci8.prefetch_lob_size", "100"); |
| 121 | +$ig = ini_get("oci8.prefetch_lob_size"); |
| 122 | +var_dump($ig); |
| 123 | + |
| 124 | +$locarr = get_clob_loc($c, $sql); |
| 125 | +$inlinearr = get_clob_inline($c, $sql); |
| 126 | + |
| 127 | +print(count($locarr) . "\n"); |
| 128 | +print(count($inlinearr) . "\n"); |
| 129 | +check_clobs($locarr, $inlinearr); |
| 130 | + |
| 131 | +print("Test 4 - BLOB prefetch_lob_size 100000\n"); |
| 132 | + |
| 133 | +ini_set("oci8.prefetch_lob_size", "100000"); |
| 134 | +$ig = ini_get("oci8.prefetch_lob_size"); |
| 135 | +var_dump($ig); |
| 136 | + |
| 137 | +$sql = "select blob from ${schema}${table_name}" . " order by id"; |
| 138 | +$locarr = get_blob_loc($c, $sql); |
| 139 | + |
| 140 | +print(count($locarr) . "\n"); |
| 141 | + |
| 142 | +require __DIR__.'/drop_table.inc'; |
| 143 | + |
| 144 | +?> |
| 145 | +DONE |
| 146 | +--EXPECTF-- |
| 147 | +Test 1 |
| 148 | +string(1) "0" |
| 149 | +string(1) "0" |
| 150 | +string(6) "100000" |
| 151 | +Test 2 - CLOB prefetch_lob_size 100000 |
| 152 | +500 |
| 153 | +500 |
| 154 | +Comparing CLOBS |
| 155 | +Test 3 - CLOB prefetch_lob_size 100 |
| 156 | +string(3) "100" |
| 157 | +500 |
| 158 | +500 |
| 159 | +Comparing CLOBS |
| 160 | +Test 4 - BLOB prefetch_lob_size 100000 |
| 161 | +string(6) "100000" |
| 162 | +500 |
| 163 | +DONE |
0 commit comments