summaryrefslogtreecommitdiff
path: root/ext/pdo_oci/tests/pdo_oci_attr_call_timeout.phpt
blob: 31df15320ea6bb3ba5e958155e4d7fc3ee6a6360 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
--TEST--
PDO_OCI: Attribute: Setting and using call timeout
--SKIPIF--
<?php
if (getenv('SKIP_SLOW_TESTS')) die('skip slow tests excluded by request');
if (!extension_loaded('pdo') || !extension_loaded('pdo_oci')) die('skip not loaded');
require(__DIR__.'/../../pdo/tests/pdo_test.inc');
PDOTest::skip();
if (strcasecmp(getenv('PDOTEST_USER'), "system") && strcasecmp(getenv('PDOTEST_USER'), "sys")) {
    die("skip needs to be run as a user with access to DBMS_LOCK");
}

$dbh = PDOTest::factory();
preg_match('/^[[:digit:]]+/', $dbh->getAttribute(PDO::ATTR_CLIENT_VERSION), $matches);
if (!(isset($matches[0]) && $matches[0] >= 18)) {
    die("skip works only with Oracle 18c or greater version of Oracle client libraries");
}

?>
--FILE--
<?php

require(__DIR__ . '/../../pdo/tests/pdo_test.inc');

function mysleep($dbh, $t)
{
    $stmt = $dbh->prepare("begin dbms_lock.sleep(:t); end;");

    if (!$stmt) {
        $error = $dbh->errorInfo();
        echo "Prepare error was ", $error[2], "\n";
        return;
    }
    $stmt->bindParam(":t", $t, PDO::PARAM_INT);

    $r = $stmt->execute();
    if ($r) {
        echo "Execute succeeded\n";
    } else {
        $error = $dbh->errorInfo();
        echo "Execute error was ", $error[2], "\n";
    }
}

$dbh = PDOTest::factory();
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);

echo "Test 1\n";

$dbh->setAttribute(PDO::OCI_ATTR_CALL_TIMEOUT, 4000); // milliseconds

echo "call timeout:\n";
var_dump($dbh->getAttribute(PDO::OCI_ATTR_CALL_TIMEOUT));

$r = mysleep($dbh, 8); // seconds

?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
Test 1
call timeout:
int(4000)
Execute error was OCIStmtExecute: ORA-%r(03136|03156)%r: %s
 (%s:%d)
===DONE===