xref: /PHP-8.3/ext/oci8/tests/conn_attr_4.phpt (revision a53e5617)
1--TEST--
2Set and get of connection attributes with errors.
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';
10if (getenv('SKIP_SLOW_TESTS')) die('skip slow tests excluded by request');
11
12if (strcasecmp($user, "system") && strcasecmp($user, "sys")) die("skip needs to be run as a DBA user");
13if ($test_drcp) die("skip output might vary with DRCP");
14
15preg_match('/.*Release ([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)*/', oci_server_version($c), $matches);
16if (!(isset($matches[0]) &&
17      (($matches[1] == 11 && $matches[2] >= 2) ||
18       ($matches[1] >= 12)
19       ))) {
20    // Bug fixed in 11.2 prevents client_info being reset
21    die("skip expected output only valid when using Oracle 11gR2 or greater database server");
22}
23?>
24--FILE--
25<?php
26
27error_reporting(E_ALL ^ E_DEPRECATED);
28
29$testuser     = 'testuser_attr_4';  // Used in conn_attr.inc
30$testpassword = 'testuser';
31
32require __DIR__."/conn_attr.inc";
33
34$attr_array = array('MODULE','ACTION','CLIENT_INFO','CLIENT_IDENTIFIER');
35
36echo"**Test  Negative cases************\n";
37
38echo "\nInvalid Connection resource 1\n";
39$nc1=NULL;
40// Invalid connection handle.
41try {
42    oci_set_action($nc1,$nc1);
43} catch (TypeError $e) {
44    var_dump($e->getMessage());
45}
46
47// Variable instead of a connection resource.
48echo "\nInvalid Connection resource 2\n";
49$str1= 'not a conn';
50try {
51    oci_set_client_info($str1,$str1);
52} catch (TypeError $e) {
53    var_dump($e->getMessage());
54}
55
56// Setting an Invalid value.
57echo "\nInvalid Action value \n";
58$c1=oci_connect($testuser,$testpassword,$dbase);
59try {
60    oci_set_action($c1,$c1);
61} catch (TypeError $e) {
62    var_dump($e->getMessage());
63}
64
65// Setting values multiple times.
66echo "\nSet Values multiple times \n";
67var_dump(oci_set_action($c1,'ACTION1'));
68var_dump(oci_set_action($c1,'ACTION1'));
69var_dump(oci_set_action($c1,'ACTION2'));
70var_dump(oci_set_action($c1,'ACTION1'));
71get_attr($c1,'ACTION');
72
73// Testing with different types of values
74// NB.  This may diff in 11.1.0.6 due to a bug causing CLIENT_INFO of NULL to be ignored.
75echo "\nSetting to different values \n";
76$values_array = array(1000,NULL,'this is a very huge string with a length  > 64 !!!!!this is a very huge string with a length  > 64 !!!!!this is a very huge string with a length  > 64 !!!!!this is a very huge string with a length  > 64 !!!!!');
77
78foreach($values_array as $val ) {
79    oci_set_module_name($c1,$val);
80    oci_set_client_identifier($c1,$val);
81    oci_set_client_info($c1,$val);
82    $r = oci_set_action($c1,$val);
83    if ($r) {
84        echo "Values set successfully to $val\n";
85        foreach($attr_array as $attr) {
86            get_attr($c1,$attr);
87        }
88    }
89}
90
91clean_up($c);
92echo "Done\n";
93?>
94--EXPECTF--
95**Test  Negative cases************
96
97Invalid Connection resource 1
98string(%d) "oci_set_action(): Argument #1 ($connection) must be of type resource, null given"
99
100Invalid Connection resource 2
101string(%d) "oci_set_client_info(): Argument #1 ($connection) must be of type resource, string given"
102
103Invalid Action value
104string(%d) "oci_set_action(): Argument #2 ($action) must be of type string, resource given"
105
106Set Values multiple times
107bool(true)
108bool(true)
109bool(true)
110bool(true)
111The value of ACTION is ACTION1
112
113Setting to different values
114Values set successfully to 1000
115The value of MODULE is 1000
116The value of ACTION is 1000
117The value of CLIENT_INFO is 1000
118The value of CLIENT_IDENTIFIER is 1000
119Values set successfully to
120The value of MODULE is
121The value of ACTION is
122The value of CLIENT_INFO is
123The value of CLIENT_IDENTIFIER is
124
125Warning: oci_set_module_name(): ORA-24960: %s OCI_ATTR_MODULE %s on line %d
126
127Warning: oci_set_client_identifier(): ORA-24960: %s OCI_ATTR_CLIENT_IDENTIFIER %s on line %d
128
129Warning: oci_set_client_info(): ORA-24960: %s OCI_ATTR_CLIENT_INFO %s on line %d
130
131Warning: oci_set_action(): ORA-24960: %s OCI_ATTR_ACTION %s on line %d
132Done
133