I've found a nasty in SQLError.. I'm guessing it is a causualty of 
cut-n-paste.. Notice that the CLEAR_STMT_ERROR macro is being used to clear 
the error of "hstmt" when it's null.. Not only is the macro name wrong, but 
the argument as well.. In my case, hstmt was null, and it was dereferencing 
a null pointer.. My change is below (further down):

------------ BROKEN VERSION -------------------
SQLRETURN SQL_API SQLError(SQLHENV henv, SQLHDBC hdbc, SQLHSTMT hstmt,
                           SQLCHAR FAR    *szSqlState,
                           SQLINTEGER FAR *pfNativeError,
                           SQLCHAR FAR    *szErrorMsg,
                           SQLSMALLINT    cbErrorMsgMax,
                           SQLSMALLINT FAR *pcbErrorMsg)
{
  SQLRETURN error=SQL_INVALID_HANDLE;
  DBUG_ENTER("SQLError");

  if (hstmt){
    error = my_SQLGetDiagRec(SQL_HANDLE_STMT,hstmt,1,szSqlState,
                             pfNativeError, szErrorMsg,
                             cbErrorMsgMax,pcbErrorMsg);
    if(error == SQL_SUCCESS)
      CLEAR_STMT_ERROR(((STMT FAR*)hstmt));
  }
  else if (hdbc){
    error = my_SQLGetDiagRec(SQL_HANDLE_DBC,hdbc,1,szSqlState,
                             pfNativeError, szErrorMsg,
                             cbErrorMsgMax,pcbErrorMsg);
    if(error == SQL_SUCCESS)
      CLEAR_STMT_ERROR(((STMT FAR*)hstmt));
  }
  else if (henv){
    error = my_SQLGetDiagRec(SQL_HANDLE_ENV,henv,1,szSqlState,
                             pfNativeError, szErrorMsg,
                             cbErrorMsgMax,pcbErrorMsg);
    if(error == SQL_SUCCESS)
      CLEAR_STMT_ERROR(((STMT FAR*)hstmt));
  }
  DBUG_RETURN(error);
}

============== MENDED VERSION =====================


SQLRETURN SQL_API SQLError(SQLHENV henv, SQLHDBC hdbc, SQLHSTMT hstmt,
                           SQLCHAR FAR    *szSqlState,
                           SQLINTEGER FAR *pfNativeError,
                           SQLCHAR FAR    *szErrorMsg,
                           SQLSMALLINT    cbErrorMsgMax,
                           SQLSMALLINT FAR *pcbErrorMsg)
{
  SQLRETURN error=SQL_INVALID_HANDLE;
  DBUG_ENTER("SQLError");

  if (hstmt){
    error = my_SQLGetDiagRec(SQL_HANDLE_STMT,hstmt,1,szSqlState,
                             pfNativeError, szErrorMsg,
                             cbErrorMsgMax,pcbErrorMsg);
    if(error == SQL_SUCCESS)
      CLEAR_STMT_ERROR(((STMT FAR*)hstmt));
  }
  else if (hdbc){
    error = my_SQLGetDiagRec(SQL_HANDLE_DBC,hdbc,1,szSqlState,
                             pfNativeError, szErrorMsg,
                             cbErrorMsgMax,pcbErrorMsg);
    if(error == SQL_SUCCESS)
      CLEAR_DBC_ERROR(((STMT FAR*)hdbc));
  }
  else if (henv){
    error = my_SQLGetDiagRec(SQL_HANDLE_ENV,henv,1,szSqlState,
                             pfNativeError, szErrorMsg,
                             cbErrorMsgMax,pcbErrorMsg);
    if(error == SQL_SUCCESS)
      CLEAR_ENV_ERROR(((STMT FAR*)henv));
  }
  DBUG_RETURN(error);
}

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to