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