com php-src: pdo_oci: Add support for setting and getting the oracle OCI 18c call timeout va lue.: NEWS ext/pdo/tests/bug_69356.phpt
ext/pdo_oci/oci_driver.c ext/pdo_oci/pdo_oci.c ext/pdo_oci/php_pdo_oci_int.h ext/pdo_oci/test s/pdo_oci_attr_call_timeout.phpt ext/pdo_oci/test
s/pdo_oci_class_constants.phpt ext/pdo_oci/tests/pd o_oci_debugdumpparams.phpt

From: Date: Fri, 01 Nov 2019 09:36:55 +0000
Subject: com php-src: pdo_oci: Add support for setting and getting the oracle OCI 18c call timeout va lue.: NEWS ext/pdo/tests/bug_69356.phpt
ext/pdo_oci/oci_driver.c ext/pdo_oci/pdo_oci.c ext/pdo_oci/php_pdo_oci_int.h ext/pdo_oci/test s/pdo_oci_attr_call_timeout.phpt ext/pdo_oci/test
s/pdo_oci_class_constants.phpt ext/pdo_oci/tests/pd o_oci_debugdumpparams.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-109154@lists.php.net to get a copy of this message
Commit: 07964fc2b56c149407000f3aa968a7ac2f36d1fd Author: Cameron Porter <porterca@us.ibm.com> Fri, 25 Oct 2019 08:32:12 +0200 Committer: Christoph M. Becker <cmbecker69@gmx.de> Fri, 1 Nov 2019 10:36:55 +0100 Parents: 61ebce1f06ea8e5c3726bbcc1f623a2ce7e05b7c Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=07964fc2b56c149407000f3aa968a7ac2f36d1fd Log: pdo_oci: Add support for setting and getting the oracle OCI 18c call timeout value. Changed paths: M NEWS M ext/pdo/tests/bug_69356.phpt M ext/pdo_oci/oci_driver.c M ext/pdo_oci/pdo_oci.c M ext/pdo_oci/php_pdo_oci_int.h A ext/pdo_oci/tests/pdo_oci_attr_call_timeout.phpt M ext/pdo_oci/tests/pdo_oci_class_constants.phpt A ext/pdo_oci/tests/pdo_oci_debugdumpparams.phpt

diff --git a/NEWS b/NEWS index f914d9d264f..102295dd7d1 100644 --- a/NEWS +++ b/NEWS @@ -51,6 +51,10 @@ PHP NEWS . Fixed bug #77849 (Disable cloning of PDO handle/connection objects). (camporter) +- PDO_OCI: + . Added support for setting and getting the oracle OCI 18c call timeout. + (camporter) + - phpdbg: . Fixed bug #76596 (phpdbg support for display_errors=stderr). (kabel) . Fixed bug #76801 (too many open files). (alekitto) diff --git a/ext/pdo/tests/bug_69356.phpt b/ext/pdo/tests/bug_69356.phpt index 4fca242a917..0885a8264fa 100644 --- a/ext/pdo/tests/bug_69356.phpt +++ b/ext/pdo/tests/bug_69356.phpt @@ -5,6 +5,7 @@ PDO Common: Bug #69356 (PDOStatement::debugDumpParams() truncates query) if (!extension_loaded('pdo')) die('skip'); $dir = getenv('REDIR_TEST_DIR'); if (false == $dir) die('skip no driver'); +if (!strncasecmp(getenv('PDOTEST_DSN'), 'oci', strlen('oci'))) die('skip query not supported'); require_once $dir . 'pdo_test.inc'; PDOTest::skip(); ?> diff --git a/ext/pdo_oci/oci_driver.c b/ext/pdo_oci/oci_driver.c index 58a63f58cb1..3d9267ba853 100644 --- a/ext/pdo_oci/oci_driver.c +++ b/ext/pdo_oci/oci_driver.c @@ -539,6 +539,24 @@ static int oci_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) / return 0; #endif } + case PDO_OCI_ATTR_CALL_TIMEOUT: + { +#if (OCI_MAJOR_VERSION >= 18) + ub4 timeout = (ub4) lval; + + H->last_err = OCIAttrSet(H->svc, OCI_HTYPE_SVCCTX, + (dvoid *) &timeout, (ub4) 0, + OCI_ATTR_CALL_TIMEOUT, H->err); + if (H->last_err) { + oci_drv_error("OCIAttrSet: OCI_ATTR_CALL_TIMEOUT"); + return 0; + } + return 1; +#else + oci_drv_error("Unsupported attribute type"); + return 0; +#endif + } default: return 0; } @@ -606,6 +624,26 @@ static int oci_handle_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *return case PDO_ATTR_PREFETCH: ZVAL_LONG(return_value, H->prefetch); return TRUE; + case PDO_OCI_ATTR_CALL_TIMEOUT: + { +#if (OCI_MAJOR_VERSION >= 18) + ub4 timeout; + + H->last_err = OCIAttrGet(H->svc, OCI_HTYPE_SVCCTX, + (dvoid *) &timeout, NULL, + OCI_ATTR_CALL_TIMEOUT, H->err); + if (H->last_err) { + oci_drv_error("OCIAttrGet: OCI_ATTR_CALL_TIMEOUT"); + return FALSE; + } + + ZVAL_LONG(return_value, (zend_long) timeout); + return TRUE; +#else + oci_drv_error("Unsupported attribute type"); + return FALSE; +#endif + } default: return FALSE; diff --git a/ext/pdo_oci/pdo_oci.c b/ext/pdo_oci/pdo_oci.c index e9be6cd0a6d..121378492a6 100644 --- a/ext/pdo_oci/pdo_oci.c +++ b/ext/pdo_oci/pdo_oci.c @@ -92,6 +92,7 @@ PHP_MINIT_FUNCTION(pdo_oci) REGISTER_PDO_CLASS_CONST_LONG("OCI_ATTR_CLIENT_INFO", (zend_long)PDO_OCI_ATTR_CLIENT_INFO); REGISTER_PDO_CLASS_CONST_LONG("OCI_ATTR_CLIENT_IDENTIFIER", (zend_long)PDO_OCI_ATTR_CLIENT_IDENTIFIER); REGISTER_PDO_CLASS_CONST_LONG("OCI_ATTR_MODULE", (zend_long)PDO_OCI_ATTR_MODULE); + REGISTER_PDO_CLASS_CONST_LONG("OCI_ATTR_CALL_TIMEOUT", (zend_long)PDO_OCI_ATTR_CALL_TIMEOUT); php_pdo_register_driver(&pdo_oci_driver); diff --git a/ext/pdo_oci/php_pdo_oci_int.h b/ext/pdo_oci/php_pdo_oci_int.h index ee56720e19e..488daf54e5d 100644 --- a/ext/pdo_oci/php_pdo_oci_int.h +++ b/ext/pdo_oci/php_pdo_oci_int.h @@ -102,5 +102,6 @@ enum { PDO_OCI_ATTR_ACTION = PDO_ATTR_DRIVER_SPECIFIC, PDO_OCI_ATTR_CLIENT_INFO, PDO_OCI_ATTR_CLIENT_IDENTIFIER, - PDO_OCI_ATTR_MODULE + PDO_OCI_ATTR_MODULE, + PDO_OCI_ATTR_CALL_TIMEOUT }; diff --git a/ext/pdo_oci/tests/pdo_oci_attr_call_timeout.phpt b/ext/pdo_oci/tests/pdo_oci_attr_call_timeout.phpt new file mode 100644 index 00000000000..31df15320ea --- /dev/null +++ b/ext/pdo_oci/tests/pdo_oci_attr_call_timeout.phpt @@ -0,0 +1,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=== diff --git a/ext/pdo_oci/tests/pdo_oci_class_constants.phpt b/ext/pdo_oci/tests/pdo_oci_class_constants.phpt index 265e84b9bae..0946b3f89b7 100644 --- a/ext/pdo_oci/tests/pdo_oci_class_constants.phpt +++ b/ext/pdo_oci/tests/pdo_oci_class_constants.phpt @@ -16,6 +16,7 @@ $expected = [ 'OCI_ATTR_ACTION' => true, 'OCI_ATTR_CLIENT_IDENTIFIER' => true, 'OCI_ATTR_MODULE' => true, + 'OCI_ATTR_CALL_TIMEOUT' => true, ]; $ref = new ReflectionClass('PDO'); diff --git a/ext/pdo_oci/tests/pdo_oci_debugdumpparams.phpt b/ext/pdo_oci/tests/pdo_oci_debugdumpparams.phpt new file mode 100644 index 00000000000..6f743c20d4c --- /dev/null +++ b/ext/pdo_oci/tests/pdo_oci_debugdumpparams.phpt @@ -0,0 +1,37 @@ +--TEST-- +PDO_OCI: Bug #69356 (PDOStatement::debugDumpParams() truncates query) +--SKIPIF-- +<?php +if (!extension_loaded('pdo') || !extension_loaded('pdo_oci')) die('skip not loaded'); +require(__DIR__.'/../../pdo/tests/pdo_test.inc'); +PDOTest::skip(); +?> +--FILE-- +<?php +require(__DIR__ . '/../../pdo/tests/pdo_test.inc'); + +$db = PDOTest::factory(); +$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); +$stmt = $db->query(" + SELECT ' + Dumps the informations contained by a prepared statement directly on the output. It will provide the SQL query in use, the number of parameters used (Params), the list of parameters, with their name, type (paramtype) as an integer, their key name or position, and the position in the query (if this is supported by the PDO driver, otherwise, it will be -1). + This is a debug function, which dump directly the data on the normal output. + Tip: + As with anything that outputs its result directly to the browser, the output-control functions can be used to capture the output of this function, and save it in a string (for example). + This will only dumps the parameters in the statement at the moment of the dump. Extra parameters are not stored in the statement, and not displayed. + ' FROM DUAL +"); +var_dump($stmt->debugDumpParams()); +?> +--EXPECT-- +SQL: [845] + SELECT ' + Dumps the informations contained by a prepared statement directly on the output. It will provide the SQL query in use, the number of parameters used (Params), the list of parameters, with their name, type (paramtype) as an integer, their key name or position, and the position in the query (if this is supported by the PDO driver, otherwise, it will be -1). + This is a debug function, which dump directly the data on the normal output. + Tip: + As with anything that outputs its result directly to the browser, the output-control functions can be used to capture the output of this function, and save it in a string (for example). + This will only dumps the parameters in the statement at the moment of the dump. Extra parameters are not stored in the statement, and not displayed. + ' FROM DUAL + +Params: 0 +NULL
« previous php.cvs (#109154) next »