summaryrefslogtreecommitdiff
path: root/ext/oci8/tests/conn_attr.inc
blob: f05f3bc064438e6f193b96784399c9bd601e4cfc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php

require(dirname(__FILE__)."/connect.inc");

preg_match('/.*Release ([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)*/', oci_server_version($c), $matches);
if ((isset($matches[1]) && $matches[1] >= 11)) {
    // Server is Oracle 11.2+
    $stmtarray = array(
        "drop user $testuser cascade",
        "create user $testuser identified by $testpassword",  // $testuser should be set by the file that includes conn_attr.inc
        "grant connect,resource,dba to $testuser",
        "alter user $testuser enable editions",
        "drop edition myedition1 cascade",
        "drop edition myedition cascade",
        "grant create any edition to $testuser",
        "create edition myedition",
        "create edition myedition1 as child of myedition",
        "grant use on edition myedition to $testuser",
        "grant use on edition myedition1 to $testuser",
    );
} else {
    // Server is Pre 11.2
    $stmtarray = array(
        "drop user $testuser cascade",
        "create user $testuser identified by $testpassword",
        "grant connect,resource,dba to $testuser",
    );
}

foreach ($stmtarray as $stmt) {
    $s = oci_parse($c, $stmt);
    $r = @oci_execute($s);
	if (!$r) {
		$m = oci_error($s);
		if (!in_array($m['code'], array(   // ignore expected errors
                        942 // table or view does not exist
                     , 1918 // user does not exist
                     , 2289 // sequence does not exist
                     , 4080 // trigger does not exist
                    , 38802 // edition does not exist
                ))) {
			echo "Error:" . $stmt . PHP_EOL . $m['message'] . PHP_EOL;
            if ($m['code'] == 38807) {
                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;
            }
            die;
		}
	}
}

function get_attr($conn,$attr)
{
    $sel_stmt="select " .$attr. " from v\$session where sid =
	(select sid from v\$session where audsid =
	sys_context('userenv','sessionid')) order by 1";
    $s2 = oci_parse($conn,$sel_stmt);
    oci_execute($s2,OCI_DEFAULT);
    while (oci_fetch($s2)) {
        echo "The value of ".$attr ." is ".oci_result($s2,1)."\n";
    }
}

/* Pass $conn_type=1 for a connection with oci_connect()
   Pass $conn_type=2 for ooci_pconnect
   Default will give a oci_new_connect */

function get_conn($conn_type)
{
	$user = $GLOBALS['testuser'];
	$password = $GLOBALS['testpassword'];
	$dbase = $GLOBALS['dbase'];
	switch($conn_type) {
        case 1:
            echo "Testing with oci_connect()\n";
            return(oci_connect($user,$password,$dbase));
            break;
        case 2:
            echo "Testing with oci_pconnect()\n";
            return(oci_pconnect($user,$password,$dbase));
            break;
        default:
            echo "Testing with oci_new_connect()\n";
            return(oci_new_connect($user,$password,$dbase));
            break;
	}
}

function set_attr($conn,$attr,$sufix)
{
	if (!strcmp($attr,'MODULE'))
		$r = oci_set_module_name($conn,'PHP TEST'.$sufix);
	else if (!strcmp($attr,'ACTION'))
        $r = oci_set_action($conn,'TASK'.$sufix);
	else if (!strcmp($attr,'CLIENT_INFO'))
        $r = oci_set_client_info($conn,'INFO1'.$sufix);
	else if (!strcmp($attr,'CLIENT_IDENTIFIER'))
        $r = oci_set_client_identifier($conn,'ID00'.$sufix);
	else
		echo "Pass one of the above four attributes!!!\n";
	if ($r) {
		echo "Value of $attr has been set successfully\n";
    }

	//Do a round-trip here
	oci_server_version($conn);
	return $r;
}

function set_edit_attr($value)
{
	$r = oci_set_edition($value);
    if ($r) {
		echo " The value of edition has been successfully set\n";
    }
	return $r;
}

function get_edit_attr ($conn) {
	$sel_stmt = "select sys_context('USERENV', 'CURRENT_EDITION_NAME') from dual";
    $s2 = oci_parse($conn,$sel_stmt);
    oci_execute($s2,OCI_DEFAULT);
    while (oci_fetch($s2)) {
        echo "The value of current EDITION is ".oci_result($s2,1)."\n";
    }
}

function get_sys_attr($conn,$attr)
{
	$sel_stmt="select " .$attr. " from v\$session where sid =
	(select sid from v\$session where audsid = sys_context('userenv','sessionid')) order by 1";
    $s2 = oci_parse($conn,$sel_stmt);
    oci_execute($s2,OCI_DEFAULT);
    while (oci_fetch($s2)) {
        echo "The value of ".$attr ." is ".oci_result($s2,1)."\n";
    }
}

function clean_up($c) {
	$stmtarray = array(
        "drop edition myedition1 cascade",
        "drop edition myedition cascade",
        "drop user " . $GLOBALS['testuser'] . " cascade",
	);

	foreach ($stmtarray as $stmt) {
        $s = oci_parse($c, $stmt);
        @oci_execute($s);
	}
}