bind_boolean_1.phpt 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. --TEST--
  2. Basic PL/SQL "BOOLEAN" (SQLT_BOL) bind test
  3. --EXTENSIONS--
  4. oci8
  5. --SKIPIF--
  6. <?php
  7. require(__DIR__.'/connect.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(__DIR__.'/connect.inc');
  20. // Run Test
  21. echo "Test 1\n";
  22. $sql = "begin
  23. :output1 := true;
  24. :output2 := false;
  25. end;";
  26. $s = oci_parse($c, $sql);
  27. oci_bind_by_name($s, ':output1', $output1, -1, OCI_B_BOL);
  28. oci_bind_by_name($s, ':output2', $output2, -1, OCI_B_BOL);
  29. oci_execute($s);
  30. var_dump($output1);
  31. var_dump($output2);
  32. echo "Test 2\n";
  33. $b = "abc"; // bind var type will change
  34. $sql = "begin :b := true; end;";
  35. $s = oci_parse($c, $sql);
  36. oci_bind_by_name($s, ':b', $b, -1, OCI_B_BOL);
  37. oci_execute($s);
  38. var_dump($b);
  39. echo "Test 3\n";
  40. $sql =
  41. "begin
  42. if (:input < 10) then
  43. :output := true;
  44. else
  45. :output := false;
  46. end if;
  47. end;";
  48. $s = oci_parse($c, $sql);
  49. oci_bind_by_name($s, ':output', $output, -1, OCI_B_BOL);
  50. for ($input = 5; $input < 15; ++$input) {
  51. oci_bind_by_name($s, ':input', $input);
  52. oci_execute($s);
  53. var_dump($output);
  54. }
  55. echo "Test 4\n";
  56. $sql =
  57. "begin
  58. if (mod(:userid,2) = 0) then
  59. :b := true;
  60. else
  61. :b := false;
  62. end if;
  63. end;";
  64. $s = oci_parse($c, $sql);
  65. oci_bind_by_name($s, ':b', $b, -1, OCI_B_BOL);
  66. for ($userid = 1; $userid <= 10; ++$userid) {
  67. oci_bind_by_name($s, ':userid', $userid, -1, SQLT_INT);
  68. oci_execute($s);
  69. var_dump($b);
  70. }
  71. echo "Test 5\n";
  72. $sql =
  73. "declare
  74. l boolean;
  75. begin
  76. l := :b1;
  77. :b1 := :b2;
  78. :b2 := l;
  79. end;";
  80. $s = oci_parse($c, $sql);
  81. $b1 = true;
  82. $b2 = false;
  83. var_dump($b1, $b2);
  84. oci_bind_by_name($s, ':b1', $b1, -1, OCI_B_BOL);
  85. oci_bind_by_name($s, ':b2', $b2, -1, OCI_B_BOL);
  86. oci_execute($s);
  87. var_dump($b1, $b2);
  88. ?>
  89. --EXPECT--
  90. Test 1
  91. bool(true)
  92. bool(false)
  93. Test 2
  94. bool(true)
  95. Test 3
  96. bool(true)
  97. bool(true)
  98. bool(true)
  99. bool(true)
  100. bool(true)
  101. bool(false)
  102. bool(false)
  103. bool(false)
  104. bool(false)
  105. bool(false)
  106. Test 4
  107. bool(false)
  108. bool(true)
  109. bool(false)
  110. bool(true)
  111. bool(false)
  112. bool(true)
  113. bool(false)
  114. bool(true)
  115. bool(false)
  116. bool(true)
  117. Test 5
  118. bool(true)
  119. bool(false)
  120. bool(false)
  121. bool(true)