xref: /PHP-8.3/ext/oci8/tests/define6.phpt (revision a53e5617)
1--TEST--
2oci_define_by_name tests with REF CURSORs
3--EXTENSIONS--
4oci8
5--SKIPIF--
6<?php
7require_once 'skipifconnectfailure.inc';
8$target_dbs = array('oracledb' => true, 'timesten' => false);  // test runs on these DBs
9require __DIR__.'/skipif.inc';
10?>
11--FILE--
12<?php
13
14require __DIR__.'/connect.inc';
15
16// Initialization
17
18$stmtarray = array(
19    "drop table define6_tab",
20    "create table define6_tab (id number)",
21    "insert into define6_tab values (1)"
22);
23
24oci8_test_sql_execute($c, $stmtarray);
25
26// Run Test
27
28$sql =
29"DECLARE
30  TYPE curtype IS REF CURSOR;
31  cursor_var curtype;
32BEGIN
33  OPEN cursor_var FOR SELECT id FROM define6_tab;
34  :curs := cursor_var;
35END;";
36
37echo "Test 1 - define last\n";
38
39$s1 = oci_parse($c, $sql);
40$cursor1 = oci_new_cursor($c);
41oci_bind_by_name($s1, ":curs", $cursor1, -1, OCI_B_CURSOR);
42oci_execute($s1);
43oci_execute($cursor1);
44oci_define_by_name($cursor1, 'ID', $id1);
45while (oci_fetch_row($cursor1)) {
46    var_dump($id1);
47}
48
49
50echo "Test 2 - define last with preset var\n";
51
52$s2 = oci_parse($c, $sql);
53$cursor2 = oci_new_cursor($c);
54oci_bind_by_name($s2, ":curs", $cursor2, -1, OCI_B_CURSOR);
55oci_execute($s2);
56oci_execute($cursor2);
57$id2 = '';
58oci_define_by_name($cursor2, 'ID', $id2);
59while (oci_fetch_row($cursor2)) {
60    var_dump($id2);
61}
62
63
64echo "Test 3 - define before cursor execute\n";
65
66$s3 = oci_parse($c, $sql);
67$cursor3 = oci_new_cursor($c);
68oci_bind_by_name($s3, ":curs", $cursor3, -1, OCI_B_CURSOR);
69oci_execute($s3);
70oci_define_by_name($cursor3, 'ID', $id3);
71oci_execute($cursor3);
72while (oci_fetch_row($cursor3)) {
73    var_dump($id3);
74}
75
76
77echo "Test 4 - define before top level execute\n";
78
79$s4 = oci_parse($c, $sql);
80$cursor4 = oci_new_cursor($c);
81oci_bind_by_name($s4, ":curs", $cursor4, -1, OCI_B_CURSOR);
82oci_define_by_name($cursor4, 'ID', $id4);
83oci_execute($s4);
84oci_execute($cursor4);
85while (oci_fetch_row($cursor4)) {
86    var_dump($id4);
87}
88
89
90echo "Test 5 - define before bind\n";
91
92$s5 = oci_parse($c, $sql);
93$cursor5 = oci_new_cursor($c);
94oci_define_by_name($cursor5, 'ID', $id5);
95oci_bind_by_name($s5, ":curs", $cursor5, -1, OCI_B_CURSOR);
96oci_execute($s5);
97oci_execute($cursor5);
98while (oci_fetch_row($cursor5)) {
99    var_dump($id5);
100}
101
102
103echo "Test 6 - fetch on wrong handle\n";
104
105$s6 = oci_parse($c, $sql);
106$cursor6 = oci_new_cursor($c);
107oci_define_by_name($cursor6, 'ID', $id6);
108oci_bind_by_name($s6, ":curs", $cursor6, -1, OCI_B_CURSOR);
109oci_execute($s6);
110oci_execute($cursor6);
111while (oci_fetch_row($s6)) {
112    var_dump($id6);
113}
114
115
116// Clean up
117
118$stmtarray = array(
119    "drop table define6_tab"
120);
121
122oci8_test_sql_execute($c, $stmtarray);
123
124?>
125--EXPECTF--
126Test 1 - define last
127NULL
128Test 2 - define last with preset var
129string(0) ""
130Test 3 - define before cursor execute
131string(1) "1"
132Test 4 - define before top level execute
133string(1) "1"
134Test 5 - define before bind
135string(1) "1"
136Test 6 - fetch on wrong handle
137
138Warning: oci_fetch_row(): ORA-24374: %s in %sdefine6.php on line %d
139