edition_1.phpt 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. --TEST--
  2. Basic test for setting Oracle 11gR2 "edition" attribute
  3. --EXTENSIONS--
  4. oci8
  5. --SKIPIF--
  6. <?php
  7. require(__DIR__."/connect.inc");
  8. if (strcasecmp($user, "system") && strcasecmp($user, "sys")) {
  9. die("skip needs to be run as a DBA user");
  10. }
  11. if ($test_drcp) {
  12. die("skip as Output might vary with DRCP");
  13. }
  14. preg_match('/.*Release ([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)*/', oci_server_version($c), $matches);
  15. if (!(isset($matches[0]) &&
  16. (($matches[1] == 11 && $matches[2] >= 2) ||
  17. ($matches[1] >= 12)
  18. ))) {
  19. die("skip expected output only valid when using Oracle 11gR2 or greater database server");
  20. }
  21. preg_match('/^([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)/', oci_client_version(), $matches);
  22. if (!(isset($matches[0]) &&
  23. (($matches[1] == 11 && $matches[2] >= 2) ||
  24. ($matches[1] >= 12)
  25. ))) {
  26. die("skip test expected to work only with Oracle 11gR2 or greater version of client");
  27. }
  28. ?>
  29. --FILE--
  30. <?php
  31. /* In 11.2, there can only be one child edition. So this test will
  32. * fail to create the necessary editions if a child edition exists
  33. * already
  34. */
  35. $testuser = 'testuser_attr_1'; // Used in conn_attr.inc
  36. $testpassword = 'testuser';
  37. require(__DIR__."/conn_attr.inc");
  38. function select_fn($conn) {
  39. $s = oci_parse($conn,"select * from view_ed");
  40. oci_execute($s);
  41. while ($row = oci_fetch_row($s)) {
  42. var_dump($row);
  43. }
  44. }
  45. /* Create a editon MYEDITION
  46. create a view view_ed in MYEDITION1.
  47. create the same view 'view_ed' with a different definition in MYEDITION.
  48. select from both the editions and verify the contents. */
  49. set_edit_attr('MYEDITION');
  50. $conn = oci_connect($testuser,$testpassword,$dbase);
  51. if ($conn === false) {
  52. $m = oci_error();
  53. die("Error:" . $m['message']);
  54. }
  55. $stmtarray = array(
  56. "drop table edit_tab",
  57. "create table edit_tab (name varchar2(10),age number,job varchar2(50), salary number)",
  58. "insert into edit_tab values('mike',30,'Senior engineer',200)",
  59. "insert into edit_tab values('juan',25,'engineer',100)",
  60. "create or replace editioning view view_ed as select name,age,job from edit_tab",
  61. );
  62. oci8_test_sql_execute($conn, $stmtarray);
  63. // Check the current edition of the DB and the contents of view_ed.
  64. get_edit_attr($conn);
  65. select_fn($conn);
  66. // Create a different version of view_ed in MYEDITION1.
  67. set_edit_attr('MYEDITION1');
  68. $conn2 = oci_new_connect($testuser,$testpassword,$dbase);
  69. $stmt = "create or replace editioning view view_ed as select name,age,job,salary from edit_tab";
  70. $s = oci_parse($conn2, $stmt);
  71. oci_execute($s);
  72. // Check the current edition of the DB and the contents of view_ed.
  73. get_edit_attr($conn2);
  74. select_fn($conn2);
  75. // Verify the contents in MYEDITION EDITION.
  76. echo "version of view_ed in MYEDITION\n";
  77. get_edit_attr($conn);
  78. select_fn($conn);
  79. clean_up($c);
  80. oci_close($conn);
  81. oci_close($conn2);
  82. echo "Done\n";
  83. ?>
  84. --EXPECTF--
  85. The value of edition has been successfully set
  86. The value of current EDITION is MYEDITION
  87. array(3) {
  88. [0]=>
  89. string(%d) "mike"
  90. [1]=>
  91. string(%d) "30"
  92. [2]=>
  93. string(%d) "Senior engineer"
  94. }
  95. array(3) {
  96. [0]=>
  97. string(%d) "juan"
  98. [1]=>
  99. string(%d) "25"
  100. [2]=>
  101. string(%d) "engineer"
  102. }
  103. The value of edition has been successfully set
  104. The value of current EDITION is MYEDITION1
  105. array(4) {
  106. [0]=>
  107. string(%d) "mike"
  108. [1]=>
  109. string(%d) "30"
  110. [2]=>
  111. string(%d) "Senior engineer"
  112. [3]=>
  113. string(%d) "200"
  114. }
  115. array(4) {
  116. [0]=>
  117. string(%d) "juan"
  118. [1]=>
  119. string(%d) "25"
  120. [2]=>
  121. string(%d) "engineer"
  122. [3]=>
  123. string(%d) "100"
  124. }
  125. version of view_ed in MYEDITION
  126. The value of current EDITION is MYEDITION
  127. array(3) {
  128. [0]=>
  129. string(%d) "mike"
  130. [1]=>
  131. string(%d) "30"
  132. [2]=>
  133. string(%d) "Senior engineer"
  134. }
  135. array(3) {
  136. [0]=>
  137. string(%d) "juan"
  138. [1]=>
  139. string(%d) "25"
  140. [2]=>
  141. string(%d) "engineer"
  142. }
  143. Done