tony2001 Mon Oct 9 09:34:55 2006 UTC
Added files: (Branch: PHP_5_2)
/php-src/ext/oci8/tests pecl_bug8816.phpt
Modified files:
/php-src/ext/oci8 oci8_statement.c
Log:
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
http://cvs.php.net/viewvc.cgi/php-src/ext/oci8/oci8_statement.c?r1=1.7.2.14.2.10&r2=1.7.2.14.2.11&diff_format=u
Index: php-src/ext/oci8/oci8_statement.c
diff -u php-src/ext/oci8/oci8_statement.c:1.7.2.14.2.10
php-src/ext/oci8/oci8_statement.c:1.7.2.14.2.11
--- php-src/ext/oci8/oci8_statement.c:1.7.2.14.2.10 Tue Sep 12 11:42:44 2006
+++ php-src/ext/oci8/oci8_statement.c Mon Oct 9 09:34:55 2006
@@ -25,7 +25,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: oci8_statement.c,v 1.7.2.14.2.10 2006/09/12 11:42:44 tony2001 Exp $ */
+/* $Id: oci8_statement.c,v 1.7.2.14.2.11 2006/10/09 09:34:55 tony2001 Exp $ */
#ifdef HAVE_CONFIG_H
@@ -155,6 +155,11 @@
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 @@
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);
- }
-
- column->cb_retlen = 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;
- 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
- )
- );
+ /* 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
+ )
+ );
+ }
}
}
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;
+ }
}
}
}
http://cvs.php.net/viewvc.cgi/php-src/ext/oci8/tests/pecl_bug8816.phpt?view=markup&rev=1.1
Index: php-src/ext/oci8/tests/pecl_bug8816.phpt
+++ php-src/ext/oci8/tests/pecl_bug8816.phpt
--TEST--
PECL Bug #8816 (issue in php_oci_statement_fetch with more than one piecewise
column)
--SKIPIF--
<?php if (!extension_loaded('oci8')) die("skip no oci8 extension"); ?>
--FILE--
<?php
require dirname(__FILE__)."/connect.inc";
$create_1 = "CREATE TABLE t1 (id INTEGER, l1 LONG)";
$create_2 = "CREATE TABLE t2 (id INTEGER, l2 LONG)";
$drop_1 = "DROP TABLE t1";
$drop_2 = "DROP TABLE t2";
$s1 = oci_parse($c, $drop_1);
$s2 = oci_parse($c, $drop_2);
@oci_execute($s1);
@oci_execute($s2);
$s1 = oci_parse($c, $create_1);
$s2 = oci_parse($c, $create_2);
oci_execute($s1);
oci_execute($s2);
$values = array("1234567890111111111", "122222222222222",
"985456745674567654567654567654", "123456789", "987654321");
$i = 0;
foreach ($values as $val) {
$i++;
$insert = "INSERT INTO t1 VALUES($i, ".$val.")";
$s = oci_parse($c, $insert);
oci_execute($s);
}
foreach ($values as $val) {
$insert = "INSERT INTO t2 VALUES($i, ".$val.")";
$s = oci_parse($c, $insert);
oci_execute($s);
$i--;
}
$query ="
SELECT
t1.l1, t2.l2
FROM
t1, t2
WHERE
t1.id = t2.id
ORDER BY t1.id ASC
";
$sth = oci_parse($c, $query);
oci_execute($sth);
while ( $row = oci_fetch_assoc($sth) ) {
var_dump($row);
}
$s1 = oci_parse($c, $drop_1);
$s2 = oci_parse($c, $drop_2);
@oci_execute($s1);
@oci_execute($s2);
echo "Done\n";
?>
--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
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php