Skip to content

Commit

Permalink
pdo_oci: Register new attr constants and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
camporter authored and cjbj committed Feb 11, 2019
1 parent a095472 commit fc940f0
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ext/pdo_oci/pdo_oci.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ static MUTEX_T pdo_oci_env_mutex;
*/
PHP_MINIT_FUNCTION(pdo_oci)
{
REGISTER_PDO_CLASS_CONST_LONG("OCI_ATTR_ACTION", (zend_long)PDO_OCI_ATTR_ACTION);
REGISTER_PDO_CLASS_CONST_LONG("OCI_ATTR_CLIENT_INFO", (zend_long)PDO_OCI_ATTR_CLIENT_INFO);

php_pdo_register_driver(&pdo_oci_driver);

// Defer OCI init to PHP_RINIT_FUNCTION because with php-fpm,
Expand Down
52 changes: 52 additions & 0 deletions ext/pdo_oci/tests/pdo_oci_attr_action.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
--TEST--
PDO_OCI: Attribute: Setting session action
--SKIPIF--
<?php
if (!extension_loaded('pdo') || !extension_loaded('pdo_oci')) die('skip not loaded');
require(dirname(__FILE__).'/../../pdo/tests/pdo_test.inc');
PDOTest::skip();
?>
--FILE--
<?php

require(dirname(__FILE__) . '/../../pdo/tests/pdo_test.inc');

$query = 'select action from v$session where sid = (select distinct sid from v$mystat)';

$dbh = PDOTest::factory();

$stmt = $dbh->query($query);
$row = $stmt->fetch();
echo 'ACTION NOT SET: ';
var_dump($row['action']);

$dbh->setAttribute(PDO::OCI_ATTR_ACTION, "some action");

$stmt = $dbh->query($query);
$row = $stmt->fetch();
echo 'ACTION SET: ';
var_dump($row['action']);

$dbh->setAttribute(PDO::OCI_ATTR_ACTION, "something else!");

$stmt = $dbh->query($query);
$row = $stmt->fetch();
echo 'ACTION RESET: ';
var_dump($row['action']);

$dbh->setAttribute(PDO::OCI_ATTR_ACTION, null);

$stmt = $dbh->query($query);
$row = $stmt->fetch();
echo 'ACTION NULLED: ';
var_dump($row['action']);

echo "Done\n";

?>
--EXPECT--
ACTION NOT SET: NULL
ACTION SET: string(11) "some action"
ACTION RESET: string(15) "something else!"
ACTION NULLED: NULL
Done
52 changes: 52 additions & 0 deletions ext/pdo_oci/tests/pdo_oci_attr_client_info.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
--TEST--
PDO_OCI: Attribute: Setting session client info
--SKIPIF--
<?php
if (!extension_loaded('pdo') || !extension_loaded('pdo_oci')) die('skip not loaded');
require(dirname(__FILE__).'/../../pdo/tests/pdo_test.inc');
PDOTest::skip();
?>
--FILE--
<?php

require(dirname(__FILE__) . '/../../pdo/tests/pdo_test.inc');

$query = 'select client_info from v$session where sid = (select distinct sid from v$mystat)';

$dbh = PDOTest::factory();

$stmt = $dbh->query($query);
$row = $stmt->fetch();
echo 'CLIENT_INFO NOT SET: ';
var_dump($row['client_info']);

$dbh->setAttribute(PDO::OCI_ATTR_CLIENT_INFO, "some client info");

$stmt = $dbh->query($query);
$row = $stmt->fetch();
echo 'CLIENT_INFO SET: ';
var_dump($row['client_info']);

$dbh->setAttribute(PDO::OCI_ATTR_CLIENT_INFO, "something else!");

$stmt = $dbh->query($query);
$row = $stmt->fetch();
echo 'CLIENT_INFO RESET: ';
var_dump($row['client_info']);

$dbh->setAttribute(PDO::OCI_ATTR_CLIENT_INFO, null);

$stmt = $dbh->query($query);
$row = $stmt->fetch();
echo 'CLIENT_INFO NULLED: ';
var_dump($row['client_info']);

echo "Done\n";

?>
--EXPECT--
CLIENT_INFO NOT SET: NULL
CLIENT_INFO SET: string(16) "some client info"
CLIENT_INFO RESET: string(15) "something else!"
CLIENT_INFO NULLED: NULL
Done
62 changes: 62 additions & 0 deletions ext/pdo_oci/tests/pdo_oci_class_constants.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
--TEST--
PDO OCI specific class constants
--SKIPIF--
<?php
if (!extension_loaded('pdo') || !extension_loaded('pdo_oci')) die('skip not loaded');
require(dirname(__FILE__).'/../../pdo/tests/pdo_test.inc');
PDOTest::skip();
?>
--FILE--
<?php

require(dirname(__FILE__) . '/../../pdo/tests/pdo_test.inc');

$expected = [
'OCI_ATTR_CLIENT_INFO' => true,
'OCI_ATTR_ACTION' => true,
];

$ref = new ReflectionClass('PDO');
$constants = $ref->getConstants();
$values = [];

foreach ($constants as $name => $value) {
if (substr($name, 0, 8) == 'OCI_ATTR') {
if (!isset($values[$value])) {
$values[$value] = [$name];
} else {
$values[$value][] = $name;
}

if (isset($expected[$name])) {
unset($expected[$name]);
unset($constants[$name]);
}

} else {
unset($constants[$name]);
}
}

if (!empty($constants)) {
printf("[001] Dumping list of unexpected constants\n");
var_dump($constants);
}

if (!empty($expected)) {
printf("[002] Dumping list of missing constants\n");
var_dump($expected);
}

if (!empty($values)) {
foreach ($values as $value => $constants) {
if (count($constants) > 1) {
printf("[003] Several constants share the same value '%s'\n", $value);
var_dump($constants);
}
}
}

print "done!";
--EXPECT--
done!

0 comments on commit fc940f0

Please sign in to comment.