From:             pdan-php at esync dot org
Operating system: Linux
PHP version:      4.3.9
PHP Bug Type:     ODBC related
Bug description:  odbc_next_result bugs

Description:
------------
odbc_next_result does not set the corresponding internal php_odbc
structures if SQLMoreResults returns SQL_SUCCESS

The following patch against 4.3.9 fixes the issue, at least from a 'user's
perspective:

--- ext/odbc/php_odbc.c.orig    2004-10-13 21:44:05.000000000 +0300
+++ ext/odbc/php_odbc.c 2004-10-13 21:44:28.000000000 +0300
@@ -2422,10 +2422,12 @@

    result->fetched = 0;
    rc = SQLMoreResults(result->stmt);
+    /*
    if (rc == SQL_SUCCESS) {
        RETURN_TRUE;
    }
-   else if (rc == SQL_SUCCESS_WITH_INFO) {
+   else */
+    if (rc == SQL_SUCCESS_WITH_INFO || rc == SQL_SUCCESS) {
        rc = SQLFreeStmt(result->stmt, SQL_UNBIND);
        SQLNumParams(result->stmt, &(result->numparams));
        SQLNumResultCols(result->stmt, &(result->numcols));


Reproduce code:
---------------
$con = odbc_connect($dsn, $user, $password);
if (!is_resource($con)) die("failed to connect");

$query = 'SELECT 1 AS A; SELECT 2 AS B, 3 AS C, 4 AS D; SELECT 5 AS E, 6
AS F;';

$qres = odbc_exec($con, $query);

if ($qres===false) die ("failed to execute");

do{
    while(odbc_fetch_row($qres)){
        for($f = 1; $f<=odbc_num_fields($qres); $f++){
            $val = odbc_result($qres, $f);
            echo('Field name: ' . odbc_field_name($qres, $f) . ', value='
. $val . ' (size=' . strlen($val) . ')' . "\n");
        }
    }
} while(odbc_next_result($qres));


Expected result:
----------------
Field name: A, value=1 (size=1)
Field name: B, value=2 (size=1)
Field name: C, value=3 (size=1)
Field name: D, value=4 (size=1)
Field name: E, value=5 (size=1)
Field name: F, value=6 (size=1)

(reproduce code as run on 4.3.9 with my odbc fix)

Actual result:
--------------
black php-4.3.9 # gdb sapi/cli/php
GNU gdb 6.0
Copyright 2003 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you
are
welcome to change it and/or distribute copies of it under certain
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for
details.
This GDB was configured as "i686-pc-linux-gnu"...Using host libthread_db
library "/lib/libthread_db.so.1".

(gdb) set args b.php
(gdb) run
Starting program: /var/tmp/portage/php-4.3.9/work/php-4.3.9/sapi/cli/php
b.php
warning: Unable to find dynamic linker breakpoint function.
GDB will be unable to debug shared library initializers
and track explicitly loaded dynamic code.
Field name: A, value=1 (size=1)

Program received signal SIGSEGV, Segmentation fault.
0x08112a8d in zif_odbc_result ()
(gdb) backtrace
#0  0x08112a8d in zif_odbc_result ()
#1  0x081fb77c in execute ()
#2  0x081ef6a5 in zend_execute_scripts ()
#3  0x081c8c05 in php_execute_script ()
#4  0x0820a18b in main ()

Even if the crash is in odbc_result, the real reason is in
odbc_next_result.

-- 
Edit bug report at http://bugs.php.net/?id=30430&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=30430&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=30430&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=30430&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=30430&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=30430&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=30430&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=30430&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=30430&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=30430&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=30430&r=notwrong
Not enough info:             http://bugs.php.net/fix.php?id=30430&r=notenoughinfo
Submitted twice:             http://bugs.php.net/fix.php?id=30430&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=30430&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=30430&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=30430&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=30430&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=30430&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=30430&r=float
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=30430&r=mysqlcfg

Reply via email to