imp_res_lob.phpt 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. --TEST--
  2. Oracle Database 12c Implicit Result Sets: LOBs
  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. preg_match('/.*Release ([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)*/', oci_server_version($c), $matches);
  10. if (!(isset($matches[0]) && $matches[1] >= 12)) {
  11. die("skip expected output only valid when using Oracle Database 12c or greater");
  12. }
  13. preg_match('/^[[:digit:]]+/', oci_client_version(), $matches);
  14. if (!(isset($matches[0]) && $matches[0] >= 12)) {
  15. die("skip works only with Oracle 12c or greater version of Oracle client libraries");
  16. }
  17. ?>
  18. --FILE--
  19. <?php
  20. require(__DIR__.'/connect.inc');
  21. // Initialization
  22. $stmtarray = array(
  23. "drop table imp_res_lob_tab",
  24. "create table imp_res_lob_tab (c1 number, c2 clob, c3 varchar2(10))",
  25. "insert into imp_res_lob_tab values (1, 'aaaaa', 'a')",
  26. "insert into imp_res_lob_tab values (2, 'bbbbb', 'b')",
  27. "insert into imp_res_lob_tab values (3, 'ccccc', 'c')",
  28. "insert into imp_res_lob_tab values (4, 'ddddd', 'd')",
  29. "create or replace procedure imp_res_lob_proc as
  30. c1 sys_refcursor;
  31. begin
  32. open c1 for select * from imp_res_lob_tab order by 1;
  33. dbms_sql.return_result(c1);
  34. open c1 for select * from dual;
  35. dbms_sql.return_result(c1);
  36. open c1 for select c2 from imp_res_lob_tab order by c1;
  37. dbms_sql.return_result(c1);
  38. end;"
  39. );
  40. oci8_test_sql_execute($c, $stmtarray);
  41. // Run Test
  42. echo "Test 1\n";
  43. $s = oci_parse($c, "begin imp_res_lob_proc(); end;");
  44. oci_execute($s);
  45. while (($row = oci_fetch_row($s)) != false) {
  46. foreach ($row as $item) {
  47. if (is_object($item)) {
  48. echo " " . $item->load();
  49. } else {
  50. echo " " . $item;
  51. }
  52. }
  53. echo "\n";
  54. }
  55. echo "\nTest 2 - don't fetch all rows\n";
  56. $s = oci_parse($c, "begin imp_res_lob_proc(); end;");
  57. oci_execute($s);
  58. $row = oci_fetch_row($s);
  59. foreach ($row as $item) {
  60. if (is_object($item)) {
  61. echo " " . $item->load();
  62. } else {
  63. echo " " . $item;
  64. }
  65. }
  66. echo "\n";
  67. // Clean up
  68. $stmtarray = array(
  69. "drop procedure imp_res_lob_proc",
  70. "drop table imp_res_lob_tab",
  71. );
  72. oci8_test_sql_execute($c, $stmtarray);
  73. ?>
  74. --EXPECT--
  75. Test 1
  76. 1 aaaaa a
  77. 2 bbbbb b
  78. 3 ccccc c
  79. 4 ddddd d
  80. X
  81. aaaaa
  82. bbbbb
  83. ccccc
  84. ddddd
  85. Test 2 - don't fetch all rows
  86. 1 aaaaa a