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