Skip to content

Commit fc940f0

Browse files
camportercjbj
authored andcommitted
pdo_oci: Register new attr constants and add tests
1 parent a095472 commit fc940f0

File tree

4 files changed

+169
-0
lines changed

4 files changed

+169
-0
lines changed

ext/pdo_oci/pdo_oci.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ static MUTEX_T pdo_oci_env_mutex;
9292
*/
9393
PHP_MINIT_FUNCTION(pdo_oci)
9494
{
95+
REGISTER_PDO_CLASS_CONST_LONG("OCI_ATTR_ACTION", (zend_long)PDO_OCI_ATTR_ACTION);
96+
REGISTER_PDO_CLASS_CONST_LONG("OCI_ATTR_CLIENT_INFO", (zend_long)PDO_OCI_ATTR_CLIENT_INFO);
97+
9598
php_pdo_register_driver(&pdo_oci_driver);
9699

97100
// Defer OCI init to PHP_RINIT_FUNCTION because with php-fpm,
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
--TEST--
2+
PDO_OCI: Attribute: Setting session action
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('pdo') || !extension_loaded('pdo_oci')) die('skip not loaded');
6+
require(dirname(__FILE__).'/../../pdo/tests/pdo_test.inc');
7+
PDOTest::skip();
8+
?>
9+
--FILE--
10+
<?php
11+
12+
require(dirname(__FILE__) . '/../../pdo/tests/pdo_test.inc');
13+
14+
$query = 'select action from v$session where sid = (select distinct sid from v$mystat)';
15+
16+
$dbh = PDOTest::factory();
17+
18+
$stmt = $dbh->query($query);
19+
$row = $stmt->fetch();
20+
echo 'ACTION NOT SET: ';
21+
var_dump($row['action']);
22+
23+
$dbh->setAttribute(PDO::OCI_ATTR_ACTION, "some action");
24+
25+
$stmt = $dbh->query($query);
26+
$row = $stmt->fetch();
27+
echo 'ACTION SET: ';
28+
var_dump($row['action']);
29+
30+
$dbh->setAttribute(PDO::OCI_ATTR_ACTION, "something else!");
31+
32+
$stmt = $dbh->query($query);
33+
$row = $stmt->fetch();
34+
echo 'ACTION RESET: ';
35+
var_dump($row['action']);
36+
37+
$dbh->setAttribute(PDO::OCI_ATTR_ACTION, null);
38+
39+
$stmt = $dbh->query($query);
40+
$row = $stmt->fetch();
41+
echo 'ACTION NULLED: ';
42+
var_dump($row['action']);
43+
44+
echo "Done\n";
45+
46+
?>
47+
--EXPECT--
48+
ACTION NOT SET: NULL
49+
ACTION SET: string(11) "some action"
50+
ACTION RESET: string(15) "something else!"
51+
ACTION NULLED: NULL
52+
Done
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
--TEST--
2+
PDO_OCI: Attribute: Setting session client info
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('pdo') || !extension_loaded('pdo_oci')) die('skip not loaded');
6+
require(dirname(__FILE__).'/../../pdo/tests/pdo_test.inc');
7+
PDOTest::skip();
8+
?>
9+
--FILE--
10+
<?php
11+
12+
require(dirname(__FILE__) . '/../../pdo/tests/pdo_test.inc');
13+
14+
$query = 'select client_info from v$session where sid = (select distinct sid from v$mystat)';
15+
16+
$dbh = PDOTest::factory();
17+
18+
$stmt = $dbh->query($query);
19+
$row = $stmt->fetch();
20+
echo 'CLIENT_INFO NOT SET: ';
21+
var_dump($row['client_info']);
22+
23+
$dbh->setAttribute(PDO::OCI_ATTR_CLIENT_INFO, "some client info");
24+
25+
$stmt = $dbh->query($query);
26+
$row = $stmt->fetch();
27+
echo 'CLIENT_INFO SET: ';
28+
var_dump($row['client_info']);
29+
30+
$dbh->setAttribute(PDO::OCI_ATTR_CLIENT_INFO, "something else!");
31+
32+
$stmt = $dbh->query($query);
33+
$row = $stmt->fetch();
34+
echo 'CLIENT_INFO RESET: ';
35+
var_dump($row['client_info']);
36+
37+
$dbh->setAttribute(PDO::OCI_ATTR_CLIENT_INFO, null);
38+
39+
$stmt = $dbh->query($query);
40+
$row = $stmt->fetch();
41+
echo 'CLIENT_INFO NULLED: ';
42+
var_dump($row['client_info']);
43+
44+
echo "Done\n";
45+
46+
?>
47+
--EXPECT--
48+
CLIENT_INFO NOT SET: NULL
49+
CLIENT_INFO SET: string(16) "some client info"
50+
CLIENT_INFO RESET: string(15) "something else!"
51+
CLIENT_INFO NULLED: NULL
52+
Done
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
--TEST--
2+
PDO OCI specific class constants
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('pdo') || !extension_loaded('pdo_oci')) die('skip not loaded');
6+
require(dirname(__FILE__).'/../../pdo/tests/pdo_test.inc');
7+
PDOTest::skip();
8+
?>
9+
--FILE--
10+
<?php
11+
12+
require(dirname(__FILE__) . '/../../pdo/tests/pdo_test.inc');
13+
14+
$expected = [
15+
'OCI_ATTR_CLIENT_INFO' => true,
16+
'OCI_ATTR_ACTION' => true,
17+
];
18+
19+
$ref = new ReflectionClass('PDO');
20+
$constants = $ref->getConstants();
21+
$values = [];
22+
23+
foreach ($constants as $name => $value) {
24+
if (substr($name, 0, 8) == 'OCI_ATTR') {
25+
if (!isset($values[$value])) {
26+
$values[$value] = [$name];
27+
} else {
28+
$values[$value][] = $name;
29+
}
30+
31+
if (isset($expected[$name])) {
32+
unset($expected[$name]);
33+
unset($constants[$name]);
34+
}
35+
36+
} else {
37+
unset($constants[$name]);
38+
}
39+
}
40+
41+
if (!empty($constants)) {
42+
printf("[001] Dumping list of unexpected constants\n");
43+
var_dump($constants);
44+
}
45+
46+
if (!empty($expected)) {
47+
printf("[002] Dumping list of missing constants\n");
48+
var_dump($expected);
49+
}
50+
51+
if (!empty($values)) {
52+
foreach ($values as $value => $constants) {
53+
if (count($constants) > 1) {
54+
printf("[003] Several constants share the same value '%s'\n", $value);
55+
var_dump($constants);
56+
}
57+
}
58+
}
59+
60+
print "done!";
61+
--EXPECT--
62+
done!

0 commit comments

Comments
 (0)