imp_res_insert.phpt 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. --TEST--
  2. Oracle Database 12c Implicit Result Sets: Commit modes
  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. $c2 = oci_new_connect($user, $password, $dbase);
  23. $stmtarray = array(
  24. "drop table imp_res_insert_tab",
  25. "create table imp_res_insert_tab (c1 number)",
  26. "create or replace procedure imp_res_insert_proc_nc (p1 in number) as
  27. c1 sys_refcursor;
  28. begin
  29. execute immediate 'insert into imp_res_insert_tab values ('||p1||')';
  30. open c1 for select * from imp_res_insert_tab order by 1;
  31. dbms_sql.return_result(c1);
  32. end;",
  33. "create or replace procedure imp_res_insert_proc_c (p1 in number) as
  34. c1 sys_refcursor;
  35. begin
  36. execute immediate 'insert into imp_res_insert_tab values ('||p1||')';
  37. commit;
  38. open c1 for select * from imp_res_insert_tab order by 1;
  39. dbms_sql.return_result(c1);
  40. end;"
  41. );
  42. oci8_test_sql_execute($c, $stmtarray);
  43. // Run Test
  44. echo "Test 1 - No commit in procedure, OCI_COMMIT_ON_SUCCESS mode\n";
  45. $s = oci_parse($c, "begin imp_res_insert_proc_nc(111); end;");
  46. oci_execute($s, OCI_COMMIT_ON_SUCCESS);
  47. while (($row = oci_fetch_row($s)) !== false)
  48. echo $row[0], "\n";
  49. $s2 = oci_parse($c2, "select * from imp_res_insert_tab order by 1");
  50. oci_execute($s2, OCI_NO_AUTO_COMMIT);
  51. oci_fetch_all($s2, $res);
  52. var_dump($res['C1']);
  53. echo "\nTest 2 - No commit in procedure, OCI_NO_AUTO_COMMIT mode\n";
  54. $s = oci_parse($c, "begin imp_res_insert_proc_nc(222); end;");
  55. oci_execute($s, OCI_NO_AUTO_COMMIT);
  56. while (($row = oci_fetch_row($s)) !== false)
  57. echo $row[0], "\n";
  58. // The 2nd connection won't see the newly inserted data
  59. $s2 = oci_parse($c2, "select * from imp_res_insert_tab order by 1");
  60. oci_execute($s2, OCI_NO_AUTO_COMMIT);
  61. oci_fetch_all($s2, $res);
  62. var_dump($res['C1']);
  63. echo "\nTest 3 - Commit in procedure, OCI_COMMIT_ON_SUCCESS mode\n";
  64. $s = oci_parse($c, "begin imp_res_insert_proc_c(333); end;");
  65. oci_execute($s, OCI_COMMIT_ON_SUCCESS);
  66. // The 2nd connection will now see the previously uncommitted data inserted in the previous test
  67. while (($row = oci_fetch_row($s)) !== false)
  68. echo $row[0], "\n";
  69. $s2 = oci_parse($c2, "select * from imp_res_insert_tab order by 1");
  70. oci_execute($s2, OCI_NO_AUTO_COMMIT);
  71. oci_fetch_all($s2, $res);
  72. var_dump($res['C1']);
  73. echo "\nTest 4 - Commit in procedure, OCI_NO_AUTO_COMMIT mode\n";
  74. $s = oci_parse($c, "begin imp_res_insert_proc_c(444); end;");
  75. oci_execute($s, OCI_NO_AUTO_COMMIT);
  76. while (($row = oci_fetch_row($s)) !== false)
  77. echo $row[0], "\n";
  78. $s2 = oci_parse($c2, "select * from imp_res_insert_tab order by 1");
  79. oci_execute($s2, OCI_NO_AUTO_COMMIT);
  80. oci_fetch_all($s2, $res);
  81. var_dump($res['C1']);
  82. // Clean up
  83. $stmtarray = array(
  84. "drop procedure imp_res_insert_proc_nc",
  85. "drop procedure imp_res_insert_proc_c",
  86. "drop table imp_res_insert_tab",
  87. );
  88. oci8_test_sql_execute($c, $stmtarray);
  89. ?>
  90. --EXPECT--
  91. Test 1 - No commit in procedure, OCI_COMMIT_ON_SUCCESS mode
  92. 111
  93. array(1) {
  94. [0]=>
  95. string(3) "111"
  96. }
  97. Test 2 - No commit in procedure, OCI_NO_AUTO_COMMIT mode
  98. 111
  99. 222
  100. array(1) {
  101. [0]=>
  102. string(3) "111"
  103. }
  104. Test 3 - Commit in procedure, OCI_COMMIT_ON_SUCCESS mode
  105. 111
  106. 222
  107. 333
  108. array(3) {
  109. [0]=>
  110. string(3) "111"
  111. [1]=>
  112. string(3) "222"
  113. [2]=>
  114. string(3) "333"
  115. }
  116. Test 4 - Commit in procedure, OCI_NO_AUTO_COMMIT mode
  117. 111
  118. 222
  119. 333
  120. 444
  121. array(4) {
  122. [0]=>
  123. string(3) "111"
  124. [1]=>
  125. string(3) "222"
  126. [2]=>
  127. string(3) "333"
  128. [3]=>
  129. string(3) "444"
  130. }