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