imp_res_insert.phpt 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. --TEST--
  2. Oracle Database 12c Implicit Result Sets: Commit modes
  3. --SKIPIF--
  4. <?php
  5. if (!extension_loaded('oci8')) die ("skip no oci8 extension");
  6. $target_dbs = array('oracledb' => true, 'timesten' => false); // test runs on these DBs
  7. require(dirname(__FILE__).'/skipif.inc');
  8. preg_match('/.*Release ([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)*/', oci_server_version($c), $matches);
  9. if (!(isset($matches[0]) && $matches[1] >= 12)) {
  10. die("skip expected output only valid when using Oracle Database 12c or greater");
  11. }
  12. preg_match('/^[[:digit:]]+/', oci_client_version(), $matches);
  13. if (!(isset($matches[0]) && $matches[0] >= 12)) {
  14. die("skip works only with Oracle 12c or greater version of Oracle client libraries");
  15. }
  16. ?>
  17. --FILE--
  18. <?php
  19. require(dirname(__FILE__).'/connect.inc');
  20. // Initialization
  21. $c2 = oci_new_connect($user, $password, $dbase);
  22. $stmtarray = array(
  23. "drop table imp_res_insert_tab",
  24. "create table imp_res_insert_tab (c1 number)",
  25. "create or replace procedure imp_res_insert_proc_nc (p1 in number) as
  26. c1 sys_refcursor;
  27. begin
  28. execute immediate 'insert into imp_res_insert_tab values ('||p1||')';
  29. open c1 for select * from imp_res_insert_tab order by 1;
  30. dbms_sql.return_result(c1);
  31. end;",
  32. "create or replace procedure imp_res_insert_proc_c (p1 in number) as
  33. c1 sys_refcursor;
  34. begin
  35. execute immediate 'insert into imp_res_insert_tab values ('||p1||')';
  36. commit;
  37. open c1 for select * from imp_res_insert_tab order by 1;
  38. dbms_sql.return_result(c1);
  39. end;"
  40. );
  41. oci8_test_sql_execute($c, $stmtarray);
  42. // Run Test
  43. echo "Test 1 - No commit in procedure, OCI_COMMIT_ON_SUCCESS mode\n";
  44. $s = oci_parse($c, "begin imp_res_insert_proc_nc(111); end;");
  45. oci_execute($s, OCI_COMMIT_ON_SUCCESS);
  46. while (($row = oci_fetch_row($s)) !== false)
  47. echo $row[0], "\n";
  48. $s2 = oci_parse($c2, "select * from imp_res_insert_tab order by 1");
  49. oci_execute($s2, OCI_NO_AUTO_COMMIT);
  50. oci_fetch_all($s2, $res);
  51. var_dump($res['C1']);
  52. echo "\nTest 2 - No commit in procedure, OCI_NO_AUTO_COMMIT mode\n";
  53. $s = oci_parse($c, "begin imp_res_insert_proc_nc(222); end;");
  54. oci_execute($s, OCI_NO_AUTO_COMMIT);
  55. while (($row = oci_fetch_row($s)) !== false)
  56. echo $row[0], "\n";
  57. // The 2nd connection won't see the newly inserted data
  58. $s2 = oci_parse($c2, "select * from imp_res_insert_tab order by 1");
  59. oci_execute($s2, OCI_NO_AUTO_COMMIT);
  60. oci_fetch_all($s2, $res);
  61. var_dump($res['C1']);
  62. echo "\nTest 3 - Commit in procedure, OCI_COMMIT_ON_SUCCESS mode\n";
  63. $s = oci_parse($c, "begin imp_res_insert_proc_c(333); end;");
  64. oci_execute($s, OCI_COMMIT_ON_SUCCESS);
  65. // The 2nd connection will now see the previously uncommitted data inserted in the previous test
  66. while (($row = oci_fetch_row($s)) !== false)
  67. echo $row[0], "\n";
  68. $s2 = oci_parse($c2, "select * from imp_res_insert_tab order by 1");
  69. oci_execute($s2, OCI_NO_AUTO_COMMIT);
  70. oci_fetch_all($s2, $res);
  71. var_dump($res['C1']);
  72. echo "\nTest 4 - Commit in procedure, OCI_NO_AUTO_COMMIT mode\n";
  73. $s = oci_parse($c, "begin imp_res_insert_proc_c(444); end;");
  74. oci_execute($s, OCI_NO_AUTO_COMMIT);
  75. while (($row = oci_fetch_row($s)) !== false)
  76. echo $row[0], "\n";
  77. $s2 = oci_parse($c2, "select * from imp_res_insert_tab order by 1");
  78. oci_execute($s2, OCI_NO_AUTO_COMMIT);
  79. oci_fetch_all($s2, $res);
  80. var_dump($res['C1']);
  81. // Clean up
  82. $stmtarray = array(
  83. "drop procedure imp_res_insert_proc_nc",
  84. "drop procedure imp_res_insert_proc_c",
  85. "drop table imp_res_insert_tab",
  86. );
  87. oci8_test_sql_execute($c, $stmtarray);
  88. ?>
  89. ===DONE===
  90. <?php exit(0); ?>
  91. --EXPECTF--
  92. Test 1 - No commit in procedure, OCI_COMMIT_ON_SUCCESS mode
  93. 111
  94. array(1) {
  95. [0]=>
  96. string(3) "111"
  97. }
  98. Test 2 - No commit in procedure, OCI_NO_AUTO_COMMIT mode
  99. 111
  100. 222
  101. array(1) {
  102. [0]=>
  103. string(3) "111"
  104. }
  105. Test 3 - Commit in procedure, OCI_COMMIT_ON_SUCCESS mode
  106. 111
  107. 222
  108. 333
  109. array(3) {
  110. [0]=>
  111. string(3) "111"
  112. [1]=>
  113. string(3) "222"
  114. [2]=>
  115. string(3) "333"
  116. }
  117. Test 4 - Commit in procedure, OCI_NO_AUTO_COMMIT mode
  118. 111
  119. 222
  120. 333
  121. 444
  122. array(4) {
  123. [0]=>
  124. string(3) "111"
  125. [1]=>
  126. string(3) "222"
  127. [2]=>
  128. string(3) "333"
  129. [3]=>
  130. string(3) "444"
  131. }
  132. ===DONE===