int logPushMsg( HLOG hLog, char *pszModule, char *pszFunctionName, int nLine, int nSeverity, int nCode, char *pszMessage ) { HLOGMSG hMsg; FILE *hFile; if ( !hLog ) return LOG_ERROR; if ( !hLog->hMessages ) return LOG_ERROR; if ( !hLog->bOn ) return LOG_SUCCESS; if ( !pszModule ) return LOG_ERROR; if ( !pszFunctionName ) return LOG_ERROR; if ( !pszMessage ) return LOG_ERROR; /* check for, and handle, max msg */ if ( hLog->nMaxMsgs && hLog->hMessages->nItems >= hLog->nMaxMsgs ) logPopMsg( hLog ); hMsg = malloc( sizeof(LOGMSG) ); if (!hMsg) goto error_abort0; hMsg->pszModuleName = (char *)strdup( pszModule ); if (!hMsg->pszModuleName) goto error_abort1; hMsg->pszFunctionName = (char *)strdup( pszFunctionName ); if (!hMsg->pszFunctionName) goto error_abort2; hMsg->pszMessage = (char *)strdup( pszMessage ); if (!hMsg->pszMessage) goto error_abort3; hMsg->nLine = nLine; hMsg->nSeverity = nSeverity; hMsg->nCode = nCode; /* append to list */ lstAppend( hLog->hMessages, hMsg ); /* append to file */ if ( hLog->pszLogFile ) { hFile = uo_fopen( hLog->pszLogFile, "a" ); if ( !hFile ) return LOG_ERROR; uo_fprintf( hFile, "[%s][%s][%s][%d]%s\n", hLog->pszProgramName, pszModule, pszFunctionName, nLine, pszMessage ); uo_fclose( hFile ); } return LOG_SUCCESS; error_abort3: free(hMsg->pszFunctionName); error_abort2: free(hMsg->pszModuleName); error_abort1: free(hMsg); error_abort0: return LOG_ERROR; }
/*! * \brief Get oldest error for the given handle. * * This is deprecated - use SQLGetDiagRec instead. This is mapped * to SQLGetDiagRec. The main difference between this and * SQLGetDiagRec is that this call will delete the error message to * allow multiple calls here to work their way through all of the * errors even with the lack of an ability to pass a specific message * number to be returned. * * \param hDrvEnv * \param hDrvDbc * \param hDrvStmt * \param szSqlState * \param pfNativeError * \param szErrorMsg * \param nErrorMsgMax * \param pcbErrorMsg * * \return SQLRETURN * * \sa SQLGetDiagRec */ SQLRETURN SQLError( SQLHENV hDrvEnv, SQLHDBC hDrvDbc, SQLHSTMT hDrvStmt, SQLCHAR *szSqlState, SQLINTEGER *pfNativeError, SQLCHAR *szErrorMsg, SQLSMALLINT nErrorMsgMax, SQLSMALLINT *pcbErrorMsg ) { SQLSMALLINT nHandleType; SQLHANDLE hHandle; SQLRETURN nReturn; HLOG hLog; /* map call to SQLGetDiagRec */ if ( hDrvEnv ) { nHandleType = SQL_HANDLE_ENV; hHandle = hDrvEnv; hLog = ((HDRVENV)hDrvEnv)->hLog; } else if ( hDrvDbc ) { nHandleType = SQL_HANDLE_DBC; hHandle = hDrvDbc; hLog = ((HDRVDBC)hDrvDbc)->hLog; } else if ( hDrvStmt ) { nHandleType = SQL_HANDLE_STMT; hHandle = hDrvStmt; hLog = ((HDRVSTMT)hDrvStmt)->hLog; } else return SQL_INVALID_HANDLE; nReturn = SQLGetDiagRec_( nHandleType, hHandle, 1, szSqlState, pfNativeError, szErrorMsg, nErrorMsgMax, pcbErrorMsg ); /* unlike SQLGetDiagRec - we delete the message returned */ if ( SQL_SUCCEEDED( nReturn ) ) logPopMsg( hLog ); return nReturn; }
int logvPushMsgf( HLOG hLog, char *pszModule, char *pszFunctionName, int nLine, int nSeverity, int nCode, char *pszMessageFormat, va_list args ) { HLOGMSG hMsg=NULL; FILE *hFile; int mlen=0; if ( !hLog ) return LOG_ERROR; if ( !hLog->hMessages ) return LOG_ERROR; if ( !hLog->bOn ) return LOG_SUCCESS; if ( !pszModule ) return LOG_ERROR; if ( !pszFunctionName ) return LOG_ERROR; if ( !pszMessageFormat ) return LOG_ERROR; /* check for, and handle, max msg */ if ( hLog->nMaxMsgs && hLog->hMessages->nItems == hLog->nMaxMsgs ) logPopMsg( hLog ); hMsg = malloc( sizeof(LOGMSG) ); if (!hMsg) goto error_abort0; hMsg->pszModuleName = (char *)strdup( pszModule ); if (!hMsg->pszModuleName) goto error_abort1; hMsg->pszFunctionName = (char *)strdup( pszFunctionName ); if (!hMsg->pszFunctionName) goto error_abort2; #if defined( HAVE_VSNPRINTF ) mlen=vsnprintf(NULL,0,pszMessageFormat,args); #else mlen=uodbc_vsnprintf(NULL,0,pszMessageFormat,args); #endif mlen++; hMsg->pszMessage = malloc(mlen); if (!hMsg->pszMessage) goto error_abort3; #if defined( HAVE_VSNPRINTF ) vsnprintf(hMsg->pszMessage,mlen,pszMessageFormat,args); #else uodbc_vsnprintf(hMsg->pszMessage,mlen,pszMessageFormat,args); #endif hMsg->nLine = nLine; hMsg->nSeverity = nSeverity; hMsg->nCode = nCode; /* append to list */ lstAppend( hLog->hMessages, hMsg ); /* append to file */ if ( hLog->pszLogFile ) { hFile = uo_fopen( hLog->pszLogFile, "a" ); if ( !hFile ) return LOG_ERROR; if (hMsg) { uo_fprintf( hFile, "[%s][%s][%s][%d]%s\n", hLog->pszProgramName, pszModule, pszFunctionName, nLine, hMsg->pszMessage ); } else { uo_fprintf( hFile, "[%s][%s][%s][%d]", hLog->pszProgramName, pszModule, pszFunctionName, nLine ); uo_vfprintf( hFile, pszMessageFormat, args ); uo_fprintf( hFile, "\n" ); } uo_fclose( hFile ); } return LOG_SUCCESS; error_abort3: free(hMsg->pszFunctionName); error_abort2: free(hMsg->pszModuleName); error_abort1: free(hMsg); error_abort0: return LOG_ERROR; }