pdo_oci: Add client identifier and module attrs

Add tests for the new attributes, and check the setAttribute return
value.
This commit is contained in:
Cameron Porter 2019-01-25 11:44:10 -06:00 committed by Christopher Jones
parent fc940f0703
commit 38363f4820
8 changed files with 208 additions and 47 deletions

View File

@ -437,57 +437,102 @@ static int oci_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) /
zend_long lval = zval_get_long(val); zend_long lval = zval_get_long(val);
pdo_oci_db_handle *H = (pdo_oci_db_handle *)dbh->driver_data; pdo_oci_db_handle *H = (pdo_oci_db_handle *)dbh->driver_data;
if (attr == PDO_ATTR_AUTOCOMMIT) { switch (attr) {
if (dbh->in_txn) { case PDO_ATTR_AUTOCOMMIT:
/* Assume they want to commit whatever is outstanding */ {
H->last_err = OCITransCommit(H->svc, H->err, 0); if (dbh->in_txn) {
/* Assume they want to commit whatever is outstanding */
H->last_err = OCITransCommit(H->svc, H->err, 0);
if (H->last_err) { if (H->last_err) {
H->last_err = oci_drv_error("OCITransCommit"); H->last_err = oci_drv_error("OCITransCommit");
return 0; return 0;
}
dbh->in_txn = 0;
} }
dbh->in_txn = 0;
dbh->auto_commit = (unsigned int)lval? 1 : 0;
return 1;
} }
case PDO_ATTR_PREFETCH:
dbh->auto_commit = (unsigned int)lval? 1 : 0; {
return 1; H->prefetch = pdo_oci_sanitize_prefetch(lval);
} else if (attr == PDO_ATTR_PREFETCH) { return 1;
H->prefetch = pdo_oci_sanitize_prefetch(lval); }
return 1; case PDO_OCI_ATTR_ACTION:
} else if (attr == PDO_OCI_ATTR_ACTION) { {
#if (OCI_MAJOR_VERSION >= 10) #if (OCI_MAJOR_VERSION >= 10)
zend_string *action = zval_get_string(val); zend_string *action = zval_get_string(val);
H->last_err = OCIAttrSet(H->session, OCI_HTYPE_SESSION, H->last_err = OCIAttrSet(H->session, OCI_HTYPE_SESSION,
(dvoid *) ZSTR_VAL(action), (ub4) ZSTR_LEN(action), (dvoid *) ZSTR_VAL(action), (ub4) ZSTR_LEN(action),
OCI_ATTR_ACTION, H->err); OCI_ATTR_ACTION, H->err);
if (H->last_err) { if (H->last_err) {
oci_drv_error("OCIAttrSet: OCI_ATTR_ACTION"); oci_drv_error("OCIAttrSet: OCI_ATTR_ACTION");
return 0; return 0;
} }
return 1; return 1;
#else #else
oci_drv_error("Unsupported attribute type"); oci_drv_error("Unsupported attribute type");
return 0; return 0;
#endif #endif
} else if (attr == PDO_OCI_ATTR_CLIENT_INFO) { }
case PDO_OCI_ATTR_CLIENT_INFO:
{
#if (OCI_MAJOR_VERSION >= 10) #if (OCI_MAJOR_VERSION >= 10)
zend_string *client_info = zval_get_string(val); zend_string *client_info = zval_get_string(val);
H->last_err = OCIAttrSet(H->session, OCI_HTYPE_SESSION, H->last_err = OCIAttrSet(H->session, OCI_HTYPE_SESSION,
(dvoid *) ZSTR_VAL(client_info), (ub4) ZSTR_LEN(client_info), (dvoid *) ZSTR_VAL(client_info), (ub4) ZSTR_LEN(client_info),
OCI_ATTR_CLIENT_INFO, H->err); OCI_ATTR_CLIENT_INFO, H->err);
if (H->last_err) { if (H->last_err) {
oci_drv_error("OCIAttrSet: OCI_ATTR_CLIENT_INFO"); oci_drv_error("OCIAttrSet: OCI_ATTR_CLIENT_INFO");
return 0; return 0;
} }
return 1; return 1;
#else #else
oci_drv_error("Unsupported attribute type"); oci_drv_error("Unsupported attribute type");
return 0; return 0;
#endif #endif
} else { }
return 0; case PDO_OCI_ATTR_CLIENT_IDENTIFIER:
{
#if (OCI_MAJOR_VERSION >= 10)
zend_string *identifier = zval_get_string(val);
H->last_err = OCIAttrSet(H->session, OCI_HTYPE_SESSION,
(dvoid *) ZSTR_VAL(identifier), (ub4) ZSTR_LEN(identifier),
OCI_ATTR_CLIENT_IDENTIFIER, H->err);
if (H->last_err) {
oci_drv_error("OCIAttrSet: OCI_ATTR_CLIENT_IDENTIFIER");
return 0;
}
return 1;
#else
oci_drv_error("Unsupported attribute type");
return 0;
#endif
}
case PDO_OCI_ATTR_MODULE:
{
#if (OCI_MAJOR_VERSION >= 10)
zend_string *module = zval_get_string(val);
H->last_err = OCIAttrSet(H->session, OCI_HTYPE_SESSION,
(dvoid *) ZSTR_VAL(module), (ub4) ZSTR_LEN(module),
OCI_ATTR_MODULE, H->err);
if (H->last_err) {
oci_drv_error("OCIAttrSet: OCI_ATTR_MODULE");
return 0;
}
return 1;
#else
oci_drv_error("Unsupported attribute type");
return 0;
#endif
}
default:
return 0;
} }
} }

View File

@ -94,6 +94,8 @@ 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_ACTION", (zend_long)PDO_OCI_ATTR_ACTION);
REGISTER_PDO_CLASS_CONST_LONG("OCI_ATTR_CLIENT_INFO", (zend_long)PDO_OCI_ATTR_CLIENT_INFO); 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);
php_pdo_register_driver(&pdo_oci_driver); php_pdo_register_driver(&pdo_oci_driver);

View File

@ -105,4 +105,6 @@ extern struct pdo_stmt_methods oci_stmt_methods;
enum { enum {
PDO_OCI_ATTR_ACTION = PDO_ATTR_DRIVER_SPECIFIC, PDO_OCI_ATTR_ACTION = PDO_ATTR_DRIVER_SPECIFIC,
PDO_OCI_ATTR_CLIENT_INFO, PDO_OCI_ATTR_CLIENT_INFO,
PDO_OCI_ATTR_CLIENT_IDENTIFIER,
PDO_OCI_ATTR_MODULE
}; };

View File

@ -11,7 +11,7 @@ PDOTest::skip();
require(dirname(__FILE__) . '/../../pdo/tests/pdo_test.inc'); require(dirname(__FILE__) . '/../../pdo/tests/pdo_test.inc');
$query = 'select action from v$session where sid = (select distinct sid from v$mystat)'; $query = 'select action from v$session where sid = sys_context(\'USERENV\', \'SID\')';
$dbh = PDOTest::factory(); $dbh = PDOTest::factory();
@ -20,21 +20,21 @@ $row = $stmt->fetch();
echo 'ACTION NOT SET: '; echo 'ACTION NOT SET: ';
var_dump($row['action']); var_dump($row['action']);
$dbh->setAttribute(PDO::OCI_ATTR_ACTION, "some action"); var_dump($dbh->setAttribute(PDO::OCI_ATTR_ACTION, "some action"));
$stmt = $dbh->query($query); $stmt = $dbh->query($query);
$row = $stmt->fetch(); $row = $stmt->fetch();
echo 'ACTION SET: '; echo 'ACTION SET: ';
var_dump($row['action']); var_dump($row['action']);
$dbh->setAttribute(PDO::OCI_ATTR_ACTION, "something else!"); var_dump($dbh->setAttribute(PDO::OCI_ATTR_ACTION, "something else!"));
$stmt = $dbh->query($query); $stmt = $dbh->query($query);
$row = $stmt->fetch(); $row = $stmt->fetch();
echo 'ACTION RESET: '; echo 'ACTION RESET: ';
var_dump($row['action']); var_dump($row['action']);
$dbh->setAttribute(PDO::OCI_ATTR_ACTION, null); var_dump($dbh->setAttribute(PDO::OCI_ATTR_ACTION, null));
$stmt = $dbh->query($query); $stmt = $dbh->query($query);
$row = $stmt->fetch(); $row = $stmt->fetch();
@ -46,7 +46,10 @@ echo "Done\n";
?> ?>
--EXPECT-- --EXPECT--
ACTION NOT SET: NULL ACTION NOT SET: NULL
bool(true)
ACTION SET: string(11) "some action" ACTION SET: string(11) "some action"
bool(true)
ACTION RESET: string(15) "something else!" ACTION RESET: string(15) "something else!"
bool(true)
ACTION NULLED: NULL ACTION NULLED: NULL
Done Done

View File

@ -0,0 +1,55 @@
--TEST--
PDO_OCI: Attribute: Setting session client identifier
--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_identifier from v$session where sid = sys_context(\'USERENV\', \'SID\')';
$dbh = PDOTest::factory();
$stmt = $dbh->query($query);
$row = $stmt->fetch();
echo 'CLIENT_IDENTIFIER NOT SET: ';
var_dump($row['client_identifier']);
var_dump($dbh->setAttribute(PDO::OCI_ATTR_CLIENT_IDENTIFIER, "some client identifier"));
$stmt = $dbh->query($query);
$row = $stmt->fetch();
echo 'CLIENT_IDENTIFIER SET: ';
var_dump($row['client_identifier']);
var_dump($dbh->setAttribute(PDO::OCI_ATTR_CLIENT_IDENTIFIER, "something else!"));
$stmt = $dbh->query($query);
$row = $stmt->fetch();
echo 'CLIENT_IDENTIFIER RESET: ';
var_dump($row['client_identifier']);
var_dump($dbh->setAttribute(PDO::OCI_ATTR_CLIENT_IDENTIFIER, null));
$stmt = $dbh->query($query);
$row = $stmt->fetch();
echo 'CLIENT_IDENTIFIER NULLED: ';
var_dump($row['client_identifier']);
echo "Done\n";
?>
--EXPECT--
CLIENT_IDENTIFIER NOT SET: NULL
bool(true)
CLIENT_IDENTIFIER SET: string(22) "some client identifier"
bool(true)
CLIENT_IDENTIFIER RESET: string(15) "something else!"
bool(true)
CLIENT_IDENTIFIER NULLED: NULL
Done

View File

@ -11,7 +11,7 @@ PDOTest::skip();
require(dirname(__FILE__) . '/../../pdo/tests/pdo_test.inc'); require(dirname(__FILE__) . '/../../pdo/tests/pdo_test.inc');
$query = 'select client_info from v$session where sid = (select distinct sid from v$mystat)'; $query = 'select client_info from v$session where sid = sys_context(\'USERENV\', \'SID\')';
$dbh = PDOTest::factory(); $dbh = PDOTest::factory();
@ -20,21 +20,21 @@ $row = $stmt->fetch();
echo 'CLIENT_INFO NOT SET: '; echo 'CLIENT_INFO NOT SET: ';
var_dump($row['client_info']); var_dump($row['client_info']);
$dbh->setAttribute(PDO::OCI_ATTR_CLIENT_INFO, "some client info"); var_dump($dbh->setAttribute(PDO::OCI_ATTR_CLIENT_INFO, "some client info"));
$stmt = $dbh->query($query); $stmt = $dbh->query($query);
$row = $stmt->fetch(); $row = $stmt->fetch();
echo 'CLIENT_INFO SET: '; echo 'CLIENT_INFO SET: ';
var_dump($row['client_info']); var_dump($row['client_info']);
$dbh->setAttribute(PDO::OCI_ATTR_CLIENT_INFO, "something else!"); var_dump($dbh->setAttribute(PDO::OCI_ATTR_CLIENT_INFO, "something else!"));
$stmt = $dbh->query($query); $stmt = $dbh->query($query);
$row = $stmt->fetch(); $row = $stmt->fetch();
echo 'CLIENT_INFO RESET: '; echo 'CLIENT_INFO RESET: ';
var_dump($row['client_info']); var_dump($row['client_info']);
$dbh->setAttribute(PDO::OCI_ATTR_CLIENT_INFO, null); var_dump($dbh->setAttribute(PDO::OCI_ATTR_CLIENT_INFO, null));
$stmt = $dbh->query($query); $stmt = $dbh->query($query);
$row = $stmt->fetch(); $row = $stmt->fetch();
@ -46,7 +46,10 @@ echo "Done\n";
?> ?>
--EXPECT-- --EXPECT--
CLIENT_INFO NOT SET: NULL CLIENT_INFO NOT SET: NULL
bool(true)
CLIENT_INFO SET: string(16) "some client info" CLIENT_INFO SET: string(16) "some client info"
bool(true)
CLIENT_INFO RESET: string(15) "something else!" CLIENT_INFO RESET: string(15) "something else!"
bool(true)
CLIENT_INFO NULLED: NULL CLIENT_INFO NULLED: NULL
Done Done

View File

@ -0,0 +1,49 @@
--TEST--
PDO_OCI: Attribute: Setting session module
--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 module from v$session where sid = sys_context(\'USERENV\', \'SID\')';
$dbh = PDOTest::factory();
var_dump($dbh->setAttribute(PDO::OCI_ATTR_MODULE, "some module"));
$stmt = $dbh->query($query);
$row = $stmt->fetch();
echo 'MODULE SET: ';
var_dump($row['module']);
var_dump($dbh->setAttribute(PDO::OCI_ATTR_MODULE, "something else!"));
$stmt = $dbh->query($query);
$row = $stmt->fetch();
echo 'MODULE RESET: ';
var_dump($row['module']);
var_dump($dbh->setAttribute(PDO::OCI_ATTR_MODULE, null));
$stmt = $dbh->query($query);
$row = $stmt->fetch();
echo 'MODULE NULLED: ';
var_dump($row['module']);
echo "Done\n";
?>
--EXPECT--
bool(true)
MODULE SET: string(11) "some module"
bool(true)
MODULE RESET: string(15) "something else!"
bool(true)
MODULE NULLED: NULL
Done

View File

@ -12,8 +12,10 @@ PDOTest::skip();
require(dirname(__FILE__) . '/../../pdo/tests/pdo_test.inc'); require(dirname(__FILE__) . '/../../pdo/tests/pdo_test.inc');
$expected = [ $expected = [
'OCI_ATTR_CLIENT_INFO' => true, 'OCI_ATTR_CLIENT_INFO' => true,
'OCI_ATTR_ACTION' => true, 'OCI_ATTR_ACTION' => true,
'OCI_ATTR_CLIENT_IDENTIFIER' => true,
'OCI_ATTR_MODULE' => true,
]; ];
$ref = new ReflectionClass('PDO'); $ref = new ReflectionClass('PDO');