From 3a48a290a053094ff29a3dd74fac5cd646a2db60 Mon Sep 17 00:00:00 2001 From: Antony Dovgal Date: Mon, 9 Oct 2006 09:34:55 +0000 Subject: [PATCH] MFH: fix PECL bug #8816 (issue in php_oci_statement_fetch with more than one piecewise column) patch by jeff at badtz-maru dot com --- ext/oci8/oci8_statement.c | 78 ++++++++++++++++--------- ext/oci8/tests/pecl_bug8816.phpt | 98 ++++++++++++++++++++++++++++++++ 2 files changed, 150 insertions(+), 26 deletions(-) create mode 100644 ext/oci8/tests/pecl_bug8816.phpt diff --git a/ext/oci8/oci8_statement.c b/ext/oci8/oci8_statement.c index fabfaa8a3b..75a2cf3066 100644 --- a/ext/oci8/oci8_statement.c +++ b/ext/oci8/oci8_statement.c @@ -155,6 +155,11 @@ int php_oci_statement_set_prefetch(php_oci_statement *statement, ub4 size TSRMLS int php_oci_statement_fetch(php_oci_statement *statement, ub4 nrows TSRMLS_DC) { int i; + void *handlepp; + ub4 typep, iterp, idxp; + ub1 in_outp, piecep; + zend_bool piecewisecols = 0; + php_oci_out_column *column; PHP_OCI_CALL_RETURN(statement->errcode, OCIStmtFetch, (statement->stmt, statement->err, nrows, OCI_FETCH_NEXT, OCI_DEFAULT)); @@ -186,42 +191,63 @@ int php_oci_statement_fetch(php_oci_statement *statement, ub4 nrows TSRMLS_DC) column = php_oci_statement_get_column(statement, i + 1, NULL, 0 TSRMLS_CC); if (column->piecewise) { column->retlen4 = 0; + piecewisecols = 1; } } while (statement->errcode == OCI_NEED_DATA) { - for (i = 0; i < statement->ncolumns; i++) { - column = php_oci_statement_get_column(statement, i + 1, NULL, 0 TSRMLS_CC); - if (column->piecewise) { - if (!column->data) { - column->data = (text *) emalloc(PHP_OCI_PIECE_SIZE); - } else { - column->data = erealloc(column->data, column->retlen4 + PHP_OCI_PIECE_SIZE); + if (piecewisecols) { + PHP_OCI_CALL_RETURN(statement->errcode, + OCIStmtGetPieceInfo, + ( + statement->stmt, + statement->err, + &handlepp, + &typep, + &in_outp, + &iterp, + &idxp, + &piecep + ) + ); + + /* scan through our columns for a piecewise column with a matching handle */ + for (i = 0; i < statement->ncolumns; i++) { + column = php_oci_statement_get_column(statement, i + 1, NULL, 0 TSRMLS_CC); + if (column->piecewise && handlepp == column->oci_define) { + if (!column->data) { + column->data = (text *) ecalloc(1, PHP_OCI_PIECE_SIZE + 1); + } else { + column->data = erealloc(column->data, column->retlen4 + PHP_OCI_PIECE_SIZE + 1); + memset(column->data + column->retlen4, 0, PHP_OCI_PIECE_SIZE + 1); + } + column->cb_retlen = PHP_OCI_PIECE_SIZE; + + /* and instruct fetch to fetch waiting piece into our buffer */ + PHP_OCI_CALL(OCIStmtSetPieceInfo, + ( + (void *) column->oci_define, + OCI_HTYPE_DEFINE, + statement->err, + ((char*)column->data) + column->retlen4, + &(column->cb_retlen), + piecep, + &column->indicator, + &column->retcode + ) + ); } - - column->cb_retlen = PHP_OCI_PIECE_SIZE; - - PHP_OCI_CALL(OCIStmtSetPieceInfo, - ( - (void *) column->oci_define, - OCI_HTYPE_DEFINE, - statement->err, - ((char*)column->data) + column->retlen4, - &(column->cb_retlen), - OCI_NEXT_PIECE, - &column->indicator, - &column->retcode - ) - ); } } PHP_OCI_CALL_RETURN(statement->errcode, OCIStmtFetch, (statement->stmt, statement->err, nrows, OCI_FETCH_NEXT, OCI_DEFAULT)); - for (i = 0; i < statement->ncolumns; i++) { - column = php_oci_statement_get_column(statement, i + 1, NULL, 0 TSRMLS_CC); - if (column && column->piecewise) { - column->retlen4 += column->cb_retlen; + if (piecewisecols) { + for (i = 0; i < statement->ncolumns; i++) { + column = php_oci_statement_get_column(statement, i + 1, NULL, 0 TSRMLS_CC); + if (column && column->piecewise && handlepp == column->oci_define) { + column->retlen4 += column->cb_retlen; + } } } } diff --git a/ext/oci8/tests/pecl_bug8816.phpt b/ext/oci8/tests/pecl_bug8816.phpt new file mode 100644 index 0000000000..c369711fcf --- /dev/null +++ b/ext/oci8/tests/pecl_bug8816.phpt @@ -0,0 +1,98 @@ +--TEST-- +PECL Bug #8816 (issue in php_oci_statement_fetch with more than one piecewise column) +--SKIPIF-- + +--FILE-- + +--EXPECT-- +array(2) { + ["L1"]=> + string(19) "1234567890111111111" + ["L2"]=> + string(9) "987654321" +} +array(2) { + ["L1"]=> + string(15) "122222222222222" + ["L2"]=> + string(9) "123456789" +} +array(2) { + ["L1"]=> + string(30) "985456745674567654567654567654" + ["L2"]=> + string(30) "985456745674567654567654567654" +} +array(2) { + ["L1"]=> + string(9) "123456789" + ["L2"]=> + string(15) "122222222222222" +} +array(2) { + ["L1"]=> + string(9) "987654321" + ["L2"]=> + string(19) "1234567890111111111" +} +Done -- 2.40.0