lob_null.phpt 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. --TEST--
  2. Test null data for CLOBs
  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. require __DIR__.'/connect.inc';
  13. error_reporting(E_ALL ^ E_DEPRECATED);
  14. // Initialization
  15. $s = oci_parse($c, 'drop table lob_null_tab');
  16. @oci_execute($s);
  17. $s = oci_parse($c, 'create table lob_null_tab (id number, data clob)');
  18. oci_execute($s);
  19. $s = oci_parse($c,
  20. 'create or replace procedure lob_null_proc_in (pid in number, pdata in CLOB)
  21. as begin
  22. insert into lob_null_tab (id, data) values (pid, pdata);
  23. end;');
  24. oci_execute($s);
  25. $s = oci_parse($c,
  26. 'create or replace procedure lob_null_proc_out (pid in number, pdata out clob)
  27. as begin
  28. select data into pdata from lob_null_tab where id = pid;
  29. end;');
  30. oci_execute($s);
  31. // TEMPORARY CLOB
  32. echo "Temporary CLOB: NULL\n";
  33. $s = oci_parse($c, "insert into lob_null_tab values (1, :b)");
  34. $lob = oci_new_descriptor($c, OCI_D_LOB);
  35. oci_bind_by_name($s, ':b', $lob, -1, OCI_B_CLOB);
  36. $lob->writeTemporary(null);
  37. $r = @oci_execute($s);
  38. if (!$r) {
  39. $m = oci_error($s);
  40. echo $m['message'], "\n";
  41. }
  42. else {
  43. $lob->close();
  44. }
  45. echo "Temporary CLOB: ''\n";
  46. $s = oci_parse($c, "insert into lob_null_tab values (2, :b)");
  47. $lob = oci_new_descriptor($c, OCI_D_LOB);
  48. oci_bind_by_name($s, ':b', $lob, -1, OCI_B_CLOB);
  49. $lob->writeTemporary('');
  50. $r = @oci_execute($s);
  51. if (!$r) {
  52. $m = oci_error($s);
  53. echo $m['message'], "\n";
  54. }
  55. else {
  56. $lob->close();
  57. }
  58. echo "Temporary CLOB: text\n";
  59. $s = oci_parse($c, "insert into lob_null_tab values (3, :b)");
  60. $lob = oci_new_descriptor($c, OCI_D_LOB);
  61. oci_bind_by_name($s, ':b', $lob, -1, OCI_B_CLOB);
  62. $lob->writeTemporary('Inserted via SQL statement');
  63. $r = @oci_execute($s);
  64. if (!$r) {
  65. $m = oci_error($s);
  66. echo $m['message'], "\n";
  67. }
  68. else {
  69. $lob->close();
  70. }
  71. // PROCEDURE PARAMETER
  72. echo "Procedure parameter: NULL\n";
  73. $s = oci_parse($c, "call lob_null_proc_in(4, :b)");
  74. $lob = oci_new_descriptor($c, OCI_D_LOB);
  75. oci_bind_by_name($s, ':b', $lob, -1, OCI_B_CLOB);
  76. $lob->writeTemporary(null);
  77. $r = @oci_execute($s);
  78. if (!$r) {
  79. $m = oci_error($s);
  80. echo $m['message'], "\n";
  81. }
  82. else {
  83. $lob->close();
  84. }
  85. echo "Procedure parameter: ''\n";
  86. $s = oci_parse($c, "call lob_null_proc_in(5, :b)");
  87. $lob = oci_new_descriptor($c, OCI_D_LOB);
  88. oci_bind_by_name($s, ':b', $lob, -1, OCI_B_CLOB);
  89. $lob->writeTemporary('');
  90. $r = @oci_execute($s);
  91. if (!$r) {
  92. $m = oci_error($s);
  93. echo $m['message'], "\n";
  94. }
  95. else {
  96. $lob->close();
  97. }
  98. echo "Procedure parameter: text\n";
  99. $s = oci_parse($c, "call lob_null_proc_in(6, :b)");
  100. $lob = oci_new_descriptor($c, OCI_D_LOB);
  101. oci_bind_by_name($s, ':b', $lob, -1, OCI_B_CLOB);
  102. $lob->writeTemporary('Inserted via procedure parameter');
  103. $r = @oci_execute($s);
  104. if (!$r) {
  105. $m = oci_error($s);
  106. echo $m['message'], "\n";
  107. }
  108. else {
  109. $lob->close();
  110. }
  111. // RETURNING INTO
  112. echo "RETURNING INTO: null\n";
  113. $s = oci_parse($c, "insert into lob_null_tab values (7, empty_clob()) returning data into :b");
  114. $lob = oci_new_descriptor($c, OCI_D_LOB);
  115. oci_bind_by_name($s, ':b', $lob, -1, OCI_B_CLOB);
  116. oci_execute($s, OCI_DEFAULT); // Must have OCI_DEFAULT here so locator is still valid
  117. $lob->save(null);
  118. echo "RETURNING INTO: ''\n";
  119. $s = oci_parse($c, "insert into lob_null_tab values (8, empty_clob()) returning data into :b");
  120. $lob = oci_new_descriptor($c, OCI_D_LOB);
  121. oci_bind_by_name($s, ':b', $lob, -1, OCI_B_CLOB);
  122. oci_execute($s, OCI_DEFAULT); // Must have OCI_DEFAULT here so locator is still valid
  123. $lob->save('');
  124. echo "RETURNING INTO: text\n";
  125. $s = oci_parse($c, "insert into lob_null_tab values (9, empty_clob()) returning data into :b");
  126. $lob = oci_new_descriptor($c, OCI_D_LOB);
  127. oci_bind_by_name($s, ':b', $lob, -1, OCI_B_CLOB);
  128. oci_execute($s, OCI_DEFAULT); // Must have OCI_DEFAULT here so locator is still valid
  129. $lob->save('Inserted with RETURNING INTO');
  130. echo "Fetch as string\n";
  131. $s = oci_parse ($c, 'select id, data from lob_null_tab order by id');
  132. oci_execute($s);
  133. oci_fetch_all($s, $res);
  134. var_dump($res);
  135. echo "\nFetch as a descriptor\n";
  136. $s = oci_parse ($c, 'select id, data from lob_null_tab order by id');
  137. oci_execute($s);
  138. while ($arr = oci_fetch_assoc($s)) {
  139. if (is_object($arr['DATA'])) {
  140. echo $arr['ID'] . " is an object: ";
  141. $r = $arr['DATA']->load();
  142. var_dump($r);
  143. }
  144. else {
  145. echo $arr['ID'] . " is not an object\n";
  146. }
  147. }
  148. echo "\nFetch via the procedure parameter\n";
  149. for ($i = 1; $i <= 9; $i++)
  150. {
  151. $s = oci_parse ($c, "call lob_null_proc_out($i, :b)");
  152. $lob = oci_new_descriptor($c, OCI_D_LOB);
  153. oci_bind_by_name($s, ':b', $lob, -1, OCI_B_CLOB);
  154. oci_execute($s);
  155. if (is_object($lob)) {
  156. echo $i . " is an object: ";
  157. $r = $lob->load();
  158. var_dump($r);
  159. }
  160. else {
  161. echo $i . " is not an object\n";
  162. }
  163. }
  164. // Cleanup
  165. $s = oci_parse($c, 'drop table lob_null_tab');
  166. @oci_execute($s);
  167. echo "Done\n";
  168. ?>
  169. --EXPECT--
  170. Temporary CLOB: NULL
  171. Temporary CLOB: ''
  172. Temporary CLOB: text
  173. Procedure parameter: NULL
  174. Procedure parameter: ''
  175. Procedure parameter: text
  176. RETURNING INTO: null
  177. RETURNING INTO: ''
  178. RETURNING INTO: text
  179. Fetch as string
  180. array(2) {
  181. ["ID"]=>
  182. array(9) {
  183. [0]=>
  184. string(1) "1"
  185. [1]=>
  186. string(1) "2"
  187. [2]=>
  188. string(1) "3"
  189. [3]=>
  190. string(1) "4"
  191. [4]=>
  192. string(1) "5"
  193. [5]=>
  194. string(1) "6"
  195. [6]=>
  196. string(1) "7"
  197. [7]=>
  198. string(1) "8"
  199. [8]=>
  200. string(1) "9"
  201. }
  202. ["DATA"]=>
  203. array(9) {
  204. [0]=>
  205. string(0) ""
  206. [1]=>
  207. string(0) ""
  208. [2]=>
  209. string(26) "Inserted via SQL statement"
  210. [3]=>
  211. string(0) ""
  212. [4]=>
  213. string(0) ""
  214. [5]=>
  215. string(32) "Inserted via procedure parameter"
  216. [6]=>
  217. string(0) ""
  218. [7]=>
  219. string(0) ""
  220. [8]=>
  221. string(28) "Inserted with RETURNING INTO"
  222. }
  223. }
  224. Fetch as a descriptor
  225. 1 is an object: string(0) ""
  226. 2 is an object: string(0) ""
  227. 3 is an object: string(26) "Inserted via SQL statement"
  228. 4 is an object: string(0) ""
  229. 5 is an object: string(0) ""
  230. 6 is an object: string(32) "Inserted via procedure parameter"
  231. 7 is an object: string(0) ""
  232. 8 is an object: string(0) ""
  233. 9 is an object: string(28) "Inserted with RETURNING INTO"
  234. Fetch via the procedure parameter
  235. 1 is an object: string(0) ""
  236. 2 is an object: string(0) ""
  237. 3 is an object: string(26) "Inserted via SQL statement"
  238. 4 is an object: string(0) ""
  239. 5 is an object: string(0) ""
  240. 6 is an object: string(32) "Inserted via procedure parameter"
  241. 7 is an object: string(0) ""
  242. 8 is an object: string(0) ""
  243. 9 is an object: string(28) "Inserted with RETURNING INTO"
  244. Done