xref: /PHP-8.2/ext/oci8/tests/db_op_2.phpt (revision 72f47c0c)
1--TEST--
2oci_set_db_operation: test DBOP for end-to-end tracing
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 (strcasecmp($user, "system") && strcasecmp($user, "sys")) {
10    die("skip needs to be run as a DBA user");
11}
12preg_match('/.*Release ([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)*/', oci_server_version($c), $matches);
13if (!(isset($matches[0]) && $matches[1] >= 12)) {
14    die("skip expected output only valid when using Oracle Database 12c or greater");
15}
16preg_match('/^[[:digit:]]+/', oci_client_version(), $matches);
17if (!(isset($matches[0]) && $matches[0] >= 12)) {
18    die("skip works only with Oracle 12c or greater version of Oracle client libraries");
19}
20if (!function_exists('oci_set_db_operation'))
21{
22    die("skip function oci_set_db_operation() does not exist");
23}
24?>
25--FILE--
26<?php
27
28require(__DIR__.'/connect.inc');
29
30function dq($c, $q)
31{
32    $s = oci_parse($c, $q);
33    oci_execute($s);
34    var_dump(oci_fetch_assoc($s));
35}
36
37echo "Test 1\n";
38oci_set_db_operation($c, "db_op_2_a");
39dq($c, 'select /*+ MONITOR */ * from dual');
40
41oci_set_db_operation($c, "db_op_2_b");
42dq($c, 'select /*+ MONITOR */ * from dual');
43
44dq($c, 'select dbop_name from v$sql_monitor where dbop_name like \'db_op_2%\' order by dbop_exec_id desc');
45
46echo "Test 2\n";
47oci_set_db_operation($c, "");
48dq($c, 'select /*+ MONITOR */ \'dboptest\' from dual');
49
50dq($c, 'select sql_text, dbop_name from v$sql_monitor where sql_text like \'%dboptest%\' order by dbop_exec_id desc');
51
52?>
53--EXPECT--
54Test 1
55array(1) {
56  ["DUMMY"]=>
57  string(1) "X"
58}
59array(1) {
60  ["DUMMY"]=>
61  string(1) "X"
62}
63array(1) {
64  ["DBOP_NAME"]=>
65  string(9) "db_op_2_b"
66}
67Test 2
68array(1) {
69  ["'DBOPTEST'"]=>
70  string(8) "dboptest"
71}
72array(2) {
73  ["SQL_TEXT"]=>
74  string(42) "select /*+ MONITOR */ 'dboptest' from dual"
75  ["DBOP_NAME"]=>
76  NULL
77}
78