php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #7507 Better ODBC error reporting/fetching
Submitted: 2000-10-28 05:23 UTC Modified: 2010-12-01 18:03 UTC
From: torben@php.net Assigned:
Status: Wont fix Package: ODBC related
PHP Version: 4.0 Latest CVS (28/10/2000) OS: Any
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2000-10-28 05:23 UTC] torben@php.net
Sent from one of my workmates:

We've had some problems using the PHP4 ODBC extension. The
return values of some ODBC functions don't seem to be 
handled properly. 
 
SQLPrepare() returns sometimes the return code 
SQL_SUCCESS_WITH_INFO when using DB2 (SQLError() giving the 
warning state 01589 "A statement contains redundant 
specifications."), but in php_odbc.c accept only 
SQL_SUCCESS as the return value of SQLPrepare(). 
 
Also when using DB2, SQLExecute() and SQLExecDirect() return 
SQL_NO_DATA_FOUND after a searched update or delete when no 
rows were found to update or delete. php_odbc.c only accepts 
return codes SQL_SUCCESS and SQL_SUCCESS_WITH_INFO. (I'm not 
sure if this is intentional, that is am I supposed to check 
with a where query beforehand whether the to be updated or 
deleted rows exist.) 
 
A patch to fix these two things is attached [below]. 
 
Is the return code handling the way it is because of keeping 
PHP4 ODBC module compatible with various different dbms's or 
is it just that no one has had the time to go through 
checking it for each CLI function call? 
 
Also: Is anyone about to add a way for the application to 
access the error/warning messages and sqlstates returned by 
the latest calls to SQLError(), like mysql_error() and 
mysql_errno() functions in the MySQL extension? Or is there 
some sort of design issue that prevents doing this? 

*** php_odbc.c.old  Fri Oct 27 15:47:32 2000 
--- php_odbc.c  Fri Oct 27 15:47:35 2000 
*************** 
*** 771,777 **** 
    } 
  #endif 
   
!   if ((rc = SQLPrepare(result->stmt, query, SQL_NTS)) != SQL_SUCCESS) { 
        odbc_sql_error(conn->henv, conn->hdbc, result->stmt, "SQLPrepare"); 
        SQLFreeStmt(result->stmt, SQL_DROP); 
        RETURN_FALSE; 
--- 771,778 ---- 
    } 
  #endif 
   
!   SQLPrepare(result->stmt, query, SQL_NTS); 
!   if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { 
        odbc_sql_error(conn->henv, conn->hdbc, result->stmt, "SQLPrepare"); 
        SQLFreeStmt(result->stmt, SQL_DROP); 
        RETURN_FALSE; 
*************** 
*** 930,936 **** 
            } 
        } 
    } else { 
!       if (rc != SQL_SUCCESS) { 
            odbc_sql_error(result->conn_ptr->henv, result->conn_ptr->hdbc, result->stmt, "SQLExecute"); 
            RETVAL_FALSE; 
        } 
--- 931,937 ---- 
            } 
        } 
    } else { 
!       if (rc != SQL_SUCCESS && rc != SQL_NO_DATA_FOUND) { 
            odbc_sql_error(result->conn_ptr->henv, result->conn_ptr->hdbc, result->stmt, "SQLExecute"); 
            RETVAL_FALSE; 
        } 
*************** 
*** 945,951 **** 
        efree(params); 
    } 
   
!   if (rc == SQL_SUCCESS) { 
        RETVAL_TRUE; 
    } 
   
   
--- 946,952 ---- 
        efree(params); 
    } 
   
!   if (rc == SQL_SUCCESS || rc == SQL_NO_DATA_FOUND) { 
        RETVAL_TRUE; 
    } 
   
*************** 
*** 1099,1105 **** 
  #endif 
   
    rc = SQLExecDirect(result->stmt, query, SQL_NTS); 
!   if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { 
        /* XXX FIXME we should really check out SQLSTATE with SQLError 
         * in case rc is SQL_SUCCESS_WITH_INFO here. 
         */ 
--- 1100,1106 ---- 
  #endif 
   
    rc = SQLExecDirect(result->stmt, query, SQL_NTS); 
!   if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO && rc != SQL_NO_DATA_FOUND) { 
        /* XXX FIXME we should really check out SQLSTATE with SQLError 
         * in case rc is SQL_SUCCESS_WITH_INFO here. 
         */ 
 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-01 15:48 UTC] jani@php.net
-Status: Open +Status: Wont fix -Package: Feature/Change Request +Package: *General Issues
 [2010-12-01 15:48 UTC] jani@php.net
Use PDO. :)
 [2010-12-01 15:48 UTC] jani@php.net
-Package: *General Issues +Package: ODBC related
 [2010-12-01 18:03 UTC] torben@php.net
Hehehe :)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 13:01:29 2024 UTC