lob_null.phpt 6.5 KB

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