summaryrefslogtreecommitdiff
path: root/ext/pdo_oci
diff options
context:
space:
mode:
authorChristopher Jones <christopher.jones@oracle.com>2015-08-20 14:09:30 +1000
committerChristopher Jones <christopher.jones@oracle.com>2015-08-20 14:09:30 +1000
commitaf76506830f00ce732f79ee58f5b0ffcc8e2fc4e (patch)
tree4fc8eed64e3a05d11dcf181802a0c6ca16ff2183 /ext/pdo_oci
parentf8ee809e22c5df56a61faf1c69da04bcbd75b511 (diff)
downloadphp-git-af76506830f00ce732f79ee58f5b0ffcc8e2fc4e.tar.gz
Fixed bug #70308 (PDO::ATTR_PREFETCH is ignored)
Diffstat (limited to 'ext/pdo_oci')
-rw-r--r--ext/pdo_oci/oci_driver.c23
-rw-r--r--ext/pdo_oci/php_pdo_oci_int.h1
-rw-r--r--ext/pdo_oci/tests/checkliveness.phpt55
-rw-r--r--ext/pdo_oci/tests/pdo_oci_attr_prefetch_1.phpt49
4 files changed, 116 insertions, 12 deletions
diff --git a/ext/pdo_oci/oci_driver.c b/ext/pdo_oci/oci_driver.c
index 2551554476..6cd583493b 100644
--- a/ext/pdo_oci/oci_driver.c
+++ b/ext/pdo_oci/oci_driver.c
@@ -302,15 +302,13 @@ static int oci_handle_preparer(pdo_dbh_t *dbh, const char *sql, size_t sql_len,
}
- prefetch = pdo_oci_sanitize_prefetch((long) pdo_attr_lval(driver_options, PDO_ATTR_PREFETCH, PDO_OCI_PREFETCH_DEFAULT));
- if (prefetch) {
+ prefetch = H->prefetch; /* Note 0 is allowed so in future REF CURSORs can be used & then passed with no row loss*/
+ H->last_err = OCIAttrSet(S->stmt, OCI_HTYPE_STMT, &prefetch, 0,
+ OCI_ATTR_PREFETCH_ROWS, H->err);
+ if (!H->last_err) {
+ prefetch *= PDO_OCI_PREFETCH_ROWSIZE;
H->last_err = OCIAttrSet(S->stmt, OCI_HTYPE_STMT, &prefetch, 0,
- OCI_ATTR_PREFETCH_ROWS, H->err);
- if (!H->last_err) {
- prefetch *= PDO_OCI_PREFETCH_ROWSIZE;
- H->last_err = OCIAttrSet(S->stmt, OCI_HTYPE_STMT, &prefetch, 0,
- OCI_ATTR_PREFETCH_MEMORY, H->err);
- }
+ OCI_ATTR_PREFETCH_MEMORY, H->err);
}
stmt->driver_data = S;
@@ -460,6 +458,10 @@ static int oci_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) /
dbh->auto_commit = (unsigned int) (Z_LVAL_P(val)) ? 1 : 0;
return 1;
+ } else if (attr == PDO_ATTR_PREFETCH) {
+ convert_to_long(val);
+ H->prefetch = pdo_oci_sanitize_prefetch(Z_LVAL_P(val));
+ return 1;
} else {
return 0;
}
@@ -524,6 +526,9 @@ static int oci_handle_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *return
ZVAL_BOOL(return_value, dbh->auto_commit);
return TRUE;
+ case PDO_ATTR_PREFETCH:
+ ZVAL_LONG(return_value, H->prefetch);
+ return TRUE;
default:
return FALSE;
@@ -602,6 +607,8 @@ static int pdo_oci_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /* {{{ *
H = pecalloc(1, sizeof(*H), dbh->is_persistent);
dbh->driver_data = H;
+ H->prefetch = PDO_OCI_PREFETCH_DEFAULT;
+
/* allocate an environment */
#if HAVE_OCIENVNLSCREATE
if (vars[0].optval) {
diff --git a/ext/pdo_oci/php_pdo_oci_int.h b/ext/pdo_oci/php_pdo_oci_int.h
index 683146a05e..fd01f0f7a8 100644
--- a/ext/pdo_oci/php_pdo_oci_int.h
+++ b/ext/pdo_oci/php_pdo_oci_int.h
@@ -35,6 +35,7 @@ typedef struct {
OCIError *err;
OCISvcCtx *svc;
/* OCI9; 0 == use NLS_LANG */
+ ub4 prefetch;
ub2 charset;
sword last_err;
diff --git a/ext/pdo_oci/tests/checkliveness.phpt b/ext/pdo_oci/tests/checkliveness.phpt
new file mode 100644
index 0000000000..4bb070f40d
--- /dev/null
+++ b/ext/pdo_oci/tests/checkliveness.phpt
@@ -0,0 +1,55 @@
+--TEST--
+PDO OCI checkliveness (code coverage)
+--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 'ext/pdo/tests/pdo_test.inc';
+$db = PDOTest::test_factory('ext/pdo_oci/tests/common.phpt');
+
+$dsn = getenv('PDOTEST_DSN');
+$user = getenv('PDOTEST_USER');
+$pass = getenv('PDOTEST_PASS');
+$attr = getenv('PDOTEST_ATTR');
+
+try {
+ $db = new PDO($dsn, $user, $pass, array(PDO::ATTR_PERSISTENT => true));
+}
+catch (PDOException $e) {
+ echo 'Connection failed: ' . $e->getMessage();
+ exit;
+}
+
+// This triggers the call to check liveness
+try {
+ $db = new PDO($dsn, $user, $pass, array(PDO::ATTR_PERSISTENT => true));
+}
+catch (PDOException $e) {
+ echo 'Connection failed: ' . $e->getMessage();
+ exit;
+}
+
+$db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
+
+try {
+ $stmt = $db->prepare('SELECT * FROM dual');
+ $stmt->execute();
+ $row = $stmt->fetch();
+ var_dump($row);
+} catch (PDOException $e) {
+ print $e->getMessage();
+}
+
+$db = null;
+--EXPECTF--
+array(2) {
+ ["DUMMY"]=>
+ string(1) "X"
+ [0]=>
+ string(1) "X"
+}
diff --git a/ext/pdo_oci/tests/pdo_oci_attr_prefetch_1.phpt b/ext/pdo_oci/tests/pdo_oci_attr_prefetch_1.phpt
index 839fe83b02..0b42ecb660 100644
--- a/ext/pdo_oci/tests/pdo_oci_attr_prefetch_1.phpt
+++ b/ext/pdo_oci/tests/pdo_oci_attr_prefetch_1.phpt
@@ -13,12 +13,44 @@ require(dirname(__FILE__) . '/../../pdo/tests/pdo_test.inc');
$dbh = PDOTest::factory();
-echo "Test connect: (value is ignored & has no effect)\n";
+echo "Test connect\n";
putenv('PDOTEST_ATTR='.serialize(array(PDO::ATTR_PREFETCH=>101)));
$dbh = PDOTest::factory();
-echo "Test set: (value is ignored & has no effect)\n";
+echo $dbh->getAttribute(PDO::ATTR_PREFETCH), "\n";
+
+// Verify can fetch
+$s = $dbh->prepare("select dummy from dual" );
+$s->execute();
+while ($r = $s->fetch()) {
+ echo $r[0] . "\n";
+}
+
+echo "Test set 102\n";
$dbh->setAttribute(PDO::ATTR_PREFETCH, 102);
+echo $dbh->getAttribute(PDO::ATTR_PREFETCH), "\n";
+
+// Verify can fetch
+$s = $dbh->prepare("select dummy from dual" );
+$s->execute();
+while ($r = $s->fetch()) {
+ echo $r[0] . "\n";
+}
+
+echo "Test set -1: (Uses 0)\n";
+$dbh->setAttribute(PDO::ATTR_PREFETCH, -1);
+echo $dbh->getAttribute(PDO::ATTR_PREFETCH), "\n";
+
+// Verify can fetch
+$s = $dbh->prepare("select dummy from dual" );
+$s->execute();
+while ($r = $s->fetch()) {
+ echo $r[0] . "\n";
+}
+
+echo "Test set PHP_INT_MAX: (Uses default)\n";
+$dbh->setAttribute(PDO::ATTR_PREFETCH, PHP_INT_MAX);
+echo $dbh->getAttribute(PDO::ATTR_PREFETCH), "\n";
// Verify can fetch
$s = $dbh->prepare("select dummy from dual" );
@@ -31,7 +63,16 @@ echo "Done\n";
?>
--EXPECT--
-Test connect: (value is ignored & has no effect)
-Test set: (value is ignored & has no effect)
+Test connect
+101
+X
+Test set 102
+102
+X
+Test set -1: (Uses 0)
+0
+X
+Test set PHP_INT_MAX: (Uses default)
+100
X
Done