php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48122 odbc_cursor() returns empty name
Submitted: 2009-04-30 16:08 UTC Modified: 2013-02-18 00:33 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: theodoreb at goshen dot edu Assigned: kalle (profile)
Status: No Feedback Package: ODBC related
PHP Version: 5.2.9 OS: Gentoo Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2009-04-30 16:08 UTC] theodoreb at goshen dot edu
Description:
------------
odbc_cursor() returns empty string when the connection is created using odbc_connect() with SQL_CUR_USE_ODBC as the fourth parameter.

Using unixODBC-2.2.12 and freetds-0.82-r2 to connect to Microsoft SQL Server 2008.

Reproduce code:
---------------
$conn = odbc_connect("mssql", "login", "passwd",SQL_CUR_USE_ODBC);
$query = "SELECT *
            FROM tablename";
$cur = odbc_exec($conn,$query);
echo odbc_cursor($cur);


Expected result:
----------------
cursor name of $cur, something like SQL_CURa70b90

Actual result:
--------------
empty string ''

Patches

odbc-bug-48122 (last revision 2011-01-17 15:48 UTC by kalle@php.net)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-05-06 21:37 UTC] jani@php.net
Try this:

<?php
error_reporting(E_ALL);
$conn = odbc_connect("mssql", "login", "passwd",SQL_CUR_USE_ODBC);
var_dump($conn, odbc_errormsg($conn));
$query = "SELECT * FROM tablename";
$cur = odbc_exec($conn,$query);
var_dump(odbc_errormsg($conn));
echo odbc_cursor($cur);
var_dump(odbc_errormsg($conn));
?>

 [2009-05-06 22:13 UTC] theodoreb at goshen dot edu
Thanks for responding. 

I tried your code as follow:

error_reporting(E_ALL);
$conn = odbc_connect("mssql", "login", "passwd",SQL_CUR_USE_ODBC);
var_dump($conn, odbc_errormsg($conn));
$query = "SELECT * FROM tablename";
$cur = odbc_exec($conn,$query);
var_dump(odbc_errormsg($conn));
echo odbc_cursor($cur);
var_dump(odbc_errormsg($conn));

Here is the result:
resource(16) of type (odbc link) string(0) "" string(0) "" string(0) ""
 [2011-01-17 16:48 UTC] kalle@php.net
The following patch has been added/updated:

Patch Name: odbc-bug-48122
Revision:   1295279320
URL:        http://bugs.php.net/patch-display.php?bug=48122&patch=odbc-bug-48122&revision=1295279320
 [2011-01-17 16:50 UTC] kalle@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: kalle
 [2011-01-17 16:50 UTC] kalle@php.net
Could you try the attached patch?

According to the ODBC specification available at MSDN, then its possible for the SQLGetCursorName function to point to a NULL name where the length and return codes still are correct, so if thats the case it would fallback to the PHP cursor name which hopefully is the cause of this as I'm unable to reproduce it
 [2011-05-05 17:37 UTC] theodoreb at goshen dot edu
patch failed to apply with the following error:
patching file php_odbc.c
Hunk #1 FAILED at 1470.
Hunk #2 succeeded at 1205 (offset -274 lines).
1 out of 2 hunks FAILED -- saving rejects to file php_odbc.c.rej

and from the php_odbc.c.rej file:
***************
*** 1470,1477 ****
        if (max_len > 0) {
                cursorname = emalloc(max_len + 1);
                rc = SQLGetCursorName(result->stmt,cursorname,(SQLSMALLINT)max_len,&len);
-               if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
-                       char        state[6];     /* Not used */
                        SQLINTEGER  error;        /* Not used */
                        char        errormsg[SQL_MAX_MESSAGE_LENGTH];
                        SQLSMALLINT errormsgsize; /* Not used */
--- 1470,1477 ----
        if (max_len > 0) {
                cursorname = emalloc(max_len + 1);
                rc = SQLGetCursorName(result->stmt,cursorname,(SQLSMALLINT)max_len,&len);
+               if ((rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) || !cursorname) {
+                       char        state[6];
                        SQLINTEGER  error;        /* Not used */
                        char        errormsg[SQL_MAX_MESSAGE_LENGTH];
                        SQLSMALLINT errormsgsize; /* Not used */
 [2011-08-20 18:05 UTC] kalle@php.net
Does this apply to 5.3 too?
 [2013-02-18 00:33 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
 [2013-02-18 15:41 UTC] theodoreb at goshen dot edu
Yes, This apply to PHP 5.3.18 and also 5.4.8.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Mon Sep 28 13:01:23 2020 UTC