xref: /PHP-7.2/ext/oci8/tests/conn_attr.inc (revision a2c0f872)
1<?php
2
3require(dirname(__FILE__)."/connect.inc");
4
5preg_match('/.*Release ([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)*/', oci_server_version($c), $matches);
6if ((isset($matches[1]) && $matches[1] >= 11)) {
7    // Server is Oracle 11.2+
8    $stmtarray = array(
9        "drop user $testuser cascade",
10        "create user $testuser identified by $testpassword",  // $testuser should be set by the file that includes conn_attr.inc
11        "grant connect,resource,dba to $testuser",
12        "alter user $testuser enable editions",
13        "drop edition myedition1 cascade",
14        "drop edition myedition cascade",
15        "grant create any edition to $testuser",
16        "create edition myedition",
17        "create edition myedition1 as child of myedition",
18        "grant use on edition myedition to $testuser",
19        "grant use on edition myedition1 to $testuser",
20    );
21} else {
22    // Server is Pre 11.2
23    $stmtarray = array(
24        "drop user $testuser cascade",
25        "create user $testuser identified by $testpassword",
26        "grant connect,resource,dba to $testuser",
27    );
28}
29
30foreach ($stmtarray as $stmt) {
31    $s = oci_parse($c, $stmt);
32    $r = @oci_execute($s);
33	if (!$r) {
34		$m = oci_error($s);
35		if (!in_array($m['code'], array(   // ignore expected errors
36                        942 // table or view does not exist
37                     , 1918 // user does not exist
38                     , 2289 // sequence does not exist
39                     , 4080 // trigger does not exist
40                    , 38802 // edition does not exist
41                ))) {
42			echo "Error:" . $stmt . PHP_EOL . $m['message'] . PHP_EOL;
43            if ($m['code'] == 38807) {
44                echo "You appear to already have an edition in use that prevents this PHP test from running.  Query DBA_EDITIONS to see existing editions.". PHP_EOL;
45            }
46            die;
47		}
48	}
49}
50
51function get_attr($conn,$attr)
52{
53    $sel_stmt="select " .$attr. " from v\$session where sid =
54	(select sid from v\$session where audsid =
55	sys_context('userenv','sessionid')) order by 1";
56    $s2 = oci_parse($conn,$sel_stmt);
57    oci_execute($s2,OCI_DEFAULT);
58    while (oci_fetch($s2)) {
59        echo "The value of ".$attr ." is ".oci_result($s2,1)."\n";
60    }
61}
62
63/* Pass $conn_type=1 for a connection with oci_connect()
64   Pass $conn_type=2 for ooci_pconnect
65   Default will give a oci_new_connect */
66
67function get_conn($conn_type)
68{
69	$user = $GLOBALS['testuser'];
70	$password = $GLOBALS['testpassword'];
71	$dbase = $GLOBALS['dbase'];
72	switch($conn_type) {
73        case 1:
74            echo "Testing with oci_connect()\n";
75            return(oci_connect($user,$password,$dbase));
76            break;
77        case 2:
78            echo "Testing with oci_pconnect()\n";
79            return(oci_pconnect($user,$password,$dbase));
80            break;
81        default:
82            echo "Testing with oci_new_connect()\n";
83            return(oci_new_connect($user,$password,$dbase));
84            break;
85	}
86}
87
88function set_attr($conn,$attr,$sufix)
89{
90	if (!strcmp($attr,'MODULE'))
91		$r = oci_set_module_name($conn,'PHP TEST'.$sufix);
92	else if (!strcmp($attr,'ACTION'))
93        $r = oci_set_action($conn,'TASK'.$sufix);
94	else if (!strcmp($attr,'CLIENT_INFO'))
95        $r = oci_set_client_info($conn,'INFO1'.$sufix);
96	else if (!strcmp($attr,'CLIENT_IDENTIFIER'))
97        $r = oci_set_client_identifier($conn,'ID00'.$sufix);
98	else
99		echo "Pass one of the above four attributes!!!\n";
100	if ($r) {
101		echo "Value of $attr has been set successfully\n";
102    }
103
104	//Do a round-trip here
105	oci_server_version($conn);
106	return $r;
107}
108
109function set_edit_attr($value)
110{
111	$r = oci_set_edition($value);
112    if ($r) {
113		echo " The value of edition has been successfully set\n";
114    }
115	return $r;
116}
117
118function get_edit_attr ($conn) {
119	$sel_stmt = "select sys_context('USERENV', 'CURRENT_EDITION_NAME') from dual";
120    $s2 = oci_parse($conn,$sel_stmt);
121    oci_execute($s2,OCI_DEFAULT);
122    while (oci_fetch($s2)) {
123        echo "The value of current EDITION is ".oci_result($s2,1)."\n";
124    }
125}
126
127function get_sys_attr($conn,$attr)
128{
129	$sel_stmt="select " .$attr. " from v\$session where sid =
130	(select sid from v\$session where audsid = sys_context('userenv','sessionid')) order by 1";
131    $s2 = oci_parse($conn,$sel_stmt);
132    oci_execute($s2,OCI_DEFAULT);
133    while (oci_fetch($s2)) {
134        echo "The value of ".$attr ." is ".oci_result($s2,1)."\n";
135    }
136}
137
138function clean_up($c) {
139	$stmtarray = array(
140        "drop edition myedition1 cascade",
141        "drop edition myedition cascade",
142        "drop user " . $GLOBALS['testuser'] . " cascade",
143	);
144
145	foreach ($stmtarray as $stmt) {
146        $s = oci_parse($c, $stmt);
147        @oci_execute($s);
148	}
149}
150