Bug #76732 [Opn->Ver]: Unable to fetch text and varchar(max) when procedure returns more result sets

From: Date: Mon, 05 Oct 2020 12:30:51 +0000
Subject: Bug #76732 [Opn->Ver]: Unable to fetch text and varchar(max) when procedure returns more result sets
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-229398@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76732&edit=1 ID: 76732 Updated by: cmb@php.net Reported by: honza dot hink at gmail dot com Summary: Unable to fetch text and varchar(max) when procedure returns more result sets -Status: Open +Status: Verified Type: Bug Package: ODBC related Operating System: Windows 10 PHP Version: 7.2.8 Block user comment: N Private report: N New Comment: I can confirm this issue with ODBC 17 Driver for SQL Server. Other drivers are likely affected as well. The problem is that the odbc extension mixes SQLBindCol() and SQLGetData() even for drivers which do not support SQL_GD_ANY_COLUMN, whereas PDO_ODBC gets that right[1]. [1] <https://github.com/php/php-src/blob/php-7.3.23/ext/pdo_odbc/odbc_stmt.c#L620-L622> Previous Comments: ------------------------------------------------------------------------ [2019-08-24 08:04:19] honza dot hink at gmail dot com This case is bewhiskered, nobody concerns. Build a headstone. ------------------------------------------------------------------------ [2018-08-12 13:22:08] honza dot hink at gmail dot com Description: ------------ odbc_fetch_array() reports error: SQL error: [Microsoft][SQL Server Native Client 11.0]Invalid Descriptor Index, SQL state S1002 in SQLGetData in ... It is related to Bug #73725, that has been partially solved, but it remains by this circumstances: This error occurs on reading result with two conditions at the same time. First condition: - SQL syntax contains more than one command (select or execute) OR - SQL command contains anything extra, f.e. "set nocount on execute ..." OR - SQL command contains any comment, f.e. "/* any comment */ select ..." OR - SQL command calls a procedure that returns more than one result Second condition: - one of sql results contains column type text or not empty varchar(max) If one condition is not true, then it works OK. There are differences between drivers "SQL Server" and "SQL Server Native Client". One doesn't like text type if it is not the last column, another driver doesn't like not empty varchar(max). My example contains both features, so it gives an error regardless used driver. Test script: --------------- <?php header("Content-Type: text/html; charset=utf-8"); $con=odbc_connect("Local64bit","any_user","his_pwd"); $res1=odbc_do($con,"create procedure #p as select convert(text,'text 1') converted_to_text, 1 i, convert(varchar(max),'text 1') converted_to_varchar_max select convert(text,'text 2') converted_to_text, 1 i, convert(varchar(max),'text 2') converted_to_varchar_max "); $res2=odbc_do($con,"execute #p"); while($r=odbc_fetch_array($res2)) print_r($r); ?> Expected result: ---------------- Array ( [converted_to_text] => text 1 [i] => 1 [converted_to_varchar_max] => text 1 ) Actual result: -------------- <br /> <b>Warning</b>: odbc_fetch_array(): SQL error: [Microsoft][SQL Server Native Client 11.0]Invalid Descriptor Index, SQL state S1002 in SQLGetData in <b>F:\EclipseWorkspaces\Ramses\www\pokus.php</b> on line <b>9</b><br /> ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=76732&edit=1

« previous php.bugs (#229398) next »