php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46195 odbc_prepare use SQLNumResultCols
Submitted: 2008-09-29 12:09 UTC Modified: 2017-10-24 06:56 UTC
Votes:3
Avg. Score:4.3 ± 0.9
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: marcus dot kunze at syntela dot de Assigned:
Status: Open Package: ODBC related
PHP Version: 5.2.6 OS: Windows
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: marcus dot kunze at syntela dot de
New email:
PHP Version: OS:

 

 [2008-09-29 12:09 UTC] marcus dot kunze at syntela dot de
Description:
------------
odbc_prepare use SQLNumResultCols to get the count and description of den result column. The problem is a resultset the is depends on the paremeter or a multiple resultset with differens column.
SQLNumResultCols return only the correct result after SQLExecute is call! In odbc_execute is the same code, the code in odbc_prepare is needless.
Testet Solution on Windows, SQL Server 2005
php_odbc.c[908]
   result->numcols = 0;
/*
   SQLNumResultCols(result->stmt, &(result->numcols));
   if (result->numcols > 0) {
	if (!odbc_bindcols(result TSRMLS_CC)) {
		efree(result);
		RETURN_FALSE;
	}
   } else {
	result->values = NULL;
   }
*/	
   zend_list_addref(conn->id);


Reproduce code:
---------------
$connstr = "Driver={SQL Server};SERVER=localhost;DATABASE=master";
$sql = "select 1 as col1 \n".
       "select 2 as col2, 3 as col3 \n".
       "select 4 as col4, 5 as col5, 6 as col6";

$conn = odbc_connect($connstr, $username, $password);
$result = odbc_prepare($conn, $sql );
odbc_execute( $result );
do {
	odbc_result_all( $result );
} while ( odbc_next_result( $result ) );


Expected result:
----------------
col1
1

col2	col3
2	3

col4	col5	col6
4	5	6

Actual result:
--------------
col4	col5	col6
1	?x??x4[?	?x?x4[?

col2	col3
2	3

col4	col5	col6
4	5	6

Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-11-07 12:03 UTC] iodbc@php.net
Strictly speaking from an ODBC API point of view, you can call 
SQLNumResultCols directly after SQLPrepare, but not all 
drivers/databases evaluate the SQL statement at prepare time and therefor can only return this information after SQLExecute.

I am working on a patch that will resolve calling SQLNumResultCols and 
more importantly the odbc_bindcols call multiple times, without the 
possibility of breaking backward compatibility on existing apps.
 [2008-11-07 12:41 UTC] marcus dot kunze at syntela dot de
Hallo,
if the result depends on parameter from Execute, SQLNumResultCols can not return die correct result.

Sample:

create procedure test ( @param int )
as
   if @param = 1  select 1 as col1
   else if @param = 2  select 2 as col2
   else if @param = 3  select 3 as col3
   else  select 'other' as other


odbc_prepare('exec test(?)');

bevor not execute with the paramter vor ?, SQLNumResultCols can not have the name vor the column.
 [2017-10-24 06:56 UTC] kalle@php.net
-Status: Assigned +Status: Open -Assigned To: iodbc +Assigned To:
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sun Sep 22 03:01:26 2019 UTC