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