bind_boolean_1.phpt 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. --TEST--
  2. Basic PL/SQL "BOOLEAN" (SQLT_BOL) bind test
  3. --SKIPIF--
  4. <?php
  5. if (!extension_loaded('oci8')) die ("skip no oci8 extension");
  6. require(dirname(__FILE__).'/connect.inc');
  7. preg_match('/.*Release ([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)*/', oci_server_version($c), $matches);
  8. if (!(isset($matches[0]) && $matches[1] >= 12)) {
  9. die("skip expected output only valid when using Oracle Database 12c or greater");
  10. }
  11. preg_match('/^[[:digit:]]+/', oci_client_version(), $matches);
  12. if (!(isset($matches[0]) && $matches[0] >= 12)) {
  13. die("skip works only with Oracle 12c or greater version of Oracle client libraries");
  14. }
  15. ?>
  16. --FILE--
  17. <?php
  18. require(dirname(__FILE__).'/connect.inc');
  19. // Run Test
  20. echo "Test 1\n";
  21. $sql = "begin
  22. :output1 := true;
  23. :output2 := false;
  24. end;";
  25. $s = oci_parse($c, $sql);
  26. oci_bind_by_name($s, ':output1', $output1, -1, OCI_B_BOL);
  27. oci_bind_by_name($s, ':output2', $output2, -1, OCI_B_BOL);
  28. oci_execute($s);
  29. var_dump($output1);
  30. var_dump($output2);
  31. echo "Test 2\n";
  32. $b = "abc"; // bind var type will change
  33. $sql = "begin :b := true; end;";
  34. $s = oci_parse($c, $sql);
  35. oci_bind_by_name($s, ':b', $b, -1, OCI_B_BOL);
  36. oci_execute($s);
  37. var_dump($b);
  38. echo "Test 3\n";
  39. $sql =
  40. "begin
  41. if (:input < 10) then
  42. :output := true;
  43. else
  44. :output := false;
  45. end if;
  46. end;";
  47. $s = oci_parse($c, $sql);
  48. oci_bind_by_name($s, ':output', $output, -1, OCI_B_BOL);
  49. for ($input = 5; $input < 15; ++$input) {
  50. oci_bind_by_name($s, ':input', $input);
  51. oci_execute($s);
  52. var_dump($output);
  53. }
  54. echo "Test 4\n";
  55. $sql =
  56. "begin
  57. if (mod(:userid,2) = 0) then
  58. :b := true;
  59. else
  60. :b := false;
  61. end if;
  62. end;";
  63. $s = oci_parse($c, $sql);
  64. oci_bind_by_name($s, ':b', $b, -1, OCI_B_BOL);
  65. for ($userid = 1; $userid <= 10; ++$userid) {
  66. oci_bind_by_name($s, ':userid', $userid, -1, SQLT_INT);
  67. oci_execute($s);
  68. var_dump($b);
  69. }
  70. echo "Test 5\n";
  71. $sql =
  72. "declare
  73. l boolean;
  74. begin
  75. l := :b1;
  76. :b1 := :b2;
  77. :b2 := l;
  78. end;";
  79. $s = oci_parse($c, $sql);
  80. $b1 = true;
  81. $b2 = false;
  82. var_dump($b1, $b2);
  83. oci_bind_by_name($s, ':b1', $b1, -1, OCI_B_BOL);
  84. oci_bind_by_name($s, ':b2', $b2, -1, OCI_B_BOL);
  85. oci_execute($s);
  86. var_dump($b1, $b2);
  87. ?>
  88. ===DONE===
  89. <?php exit(0); ?>
  90. --EXPECTF--
  91. Test 1
  92. bool(true)
  93. bool(false)
  94. Test 2
  95. bool(true)
  96. Test 3
  97. bool(true)
  98. bool(true)
  99. bool(true)
  100. bool(true)
  101. bool(true)
  102. bool(false)
  103. bool(false)
  104. bool(false)
  105. bool(false)
  106. bool(false)
  107. Test 4
  108. bool(false)
  109. bool(true)
  110. bool(false)
  111. bool(true)
  112. bool(false)
  113. bool(true)
  114. bool(false)
  115. bool(true)
  116. bool(false)
  117. bool(true)
  118. Test 5
  119. bool(true)
  120. bool(false)
  121. bool(false)
  122. bool(true)
  123. ===DONE===