Skip to content

Commit 7cea78b

Browse files
sharadrajundossche
andauthored
Fix for Input Output Bind issue (Issue #20) (#31)
Fix for Input Output Bind issue Co-authored-by: Niels Dossche <7771979+ndossche@users.noreply.github.com>
1 parent df964b4 commit 7cea78b

3 files changed

Lines changed: 38 additions & 2 deletions

File tree

CREDITS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ Oracle (OCI) driver for PDO
22
Wez Furlong
33
Michael Voříšek
44
Ashutosh Agrawal
5+
Niels Dossche

oci_statement.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ static sb4 oci_bind_output_cb(dvoid *ctx, OCIBind *bindp, ub4 iter, ub4 index, d
278278

279279
zval_ptr_dtor(parameter);
280280

281-
Z_STR_P(parameter) = zend_string_alloc(param->max_value_len, 1);
281+
ZVAL_NEW_STR(parameter, zend_string_alloc(param->max_value_len, false));
282282
P->used_for_output = 1;
283283

284284
P->actual_len = (ub4) Z_STRLEN_P(parameter);
@@ -397,7 +397,8 @@ static int oci_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *pa
397397
zval_ptr_dtor_str(parameter);
398398
ZVAL_UNDEF(parameter);
399399
} else if (Z_TYPE_P(parameter) == IS_STRING) {
400-
Z_STR_P(parameter) = zend_string_init(Z_STRVAL_P(parameter), P->actual_len, 1);
400+
ZVAL_STR(parameter, zend_string_truncate(Z_STR_P(parameter), P->actual_len, false));
401+
Z_STRVAL_P(parameter)[Z_STRLEN_P(parameter)] = '\0';
401402
}
402403
} else if (PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_LOB && P->thing) {
403404
php_stream *stm;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
PDO_OCI: Test input/output parameter binding
3+
--EXTENSIONS--
4+
pdo
5+
pdo_oci
6+
--SKIPIF--
7+
<?php
8+
require(getenv('PDO_TEST_DIR').'/pdo_test.inc');
9+
PDOTest::skip();
10+
?>
11+
--FILE--
12+
<?php
13+
14+
require_once(getenv('PDO_TEST_DIR').'/pdo_test.inc');
15+
16+
$dbh = PDOTest::factory();
17+
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
18+
$dbh->setAttribute(PDO::ATTR_AUTOCOMMIT, false);
19+
20+
$sql = <<<SQL
21+
begin
22+
:p := :p + 100;
23+
end;
24+
SQL;
25+
26+
$stmt = $dbh->prepare($sql);
27+
$p = -1;
28+
$stmt->bindParam(':p', $p, PDO::PARAM_INT | PDO::PARAM_INPUT_OUTPUT, 10);
29+
$stmt->execute();
30+
var_dump($p);
31+
32+
?>
33+
--EXPECT--
34+
string(2) "99"

0 commit comments

Comments
 (0)