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