php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76732 Unable to fetch text and varchar(max) when procedure returns more result sets
Submitted: 2018-08-12 13:22 UTC Modified: 2020-10-05 12:48 UTC
Votes:19
Avg. Score:4.6 ± 0.7
Reproduced:19 of 19 (100.0%)
Same Version:5 (26.3%)
Same OS:13 (68.4%)
From: honza dot hink at gmail dot com Assigned:
Status: Verified Package: ODBC related
PHP Version: 7.3 OS: Windows 10
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: honza dot hink at gmail dot com
New email:
PHP Version: OS:

 

 [2018-08-12 13:22 UTC] 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 />


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-08-13 11:06 UTC] cmb@php.net
-Package: MSSQL related +Package: ODBC related
 [2019-08-24 08:04 UTC] honza dot hink at gmail dot com
This case is bewhiskered, nobody concerns. Build a headstone.
 [2020-10-05 12:30 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2020-10-05 12:30 UTC] cmb@php.net
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>
 [2020-10-05 12:48 UTC] cmb@php.net
-PHP Version: 7.2.8 +PHP Version: 7.3
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Tue Dec 01 21:01:23 2020 UTC