1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
/**********************************************************************
* SQLGetDiagRec
*
**********************************************************************
*
* This code was created by Peter Harvey (mostly during Christmas 98/99).
* This code is LGPL. Please ensure that this message remains in future
* distributions and uses of this code (thats about all I get out of it).
* - Peter Harvey pharvey@codebydesign.com
*
**********************************************************************/
#include <config.h>
#include "driver.h"
SQLRETURN SQLGetDiagRec_( SQLSMALLINT nHandleType,
SQLHANDLE hHandle,
SQLSMALLINT nRecordNumber,
SQLCHAR * pszState,
SQLINTEGER * pnNativeError,
SQLCHAR * pszMessageText,
SQLSMALLINT nBufferLength,
SQLSMALLINT * pnStringLength
)
{
HLOG hLog = NULL;
HLOGMSG hMsg = NULL;
/* sanity checks */
if ( !hHandle )
return SQL_INVALID_HANDLE;
/* clear return values */
if ( pszState )
strcpy((char*) pszState, "-----" );
if ( pnNativeError )
*pnNativeError = 0;
if ( pszMessageText )
memset( pszMessageText, 0, nBufferLength );
if ( pnStringLength )
*pnStringLength = 0;
/* get hLog */
switch ( nHandleType )
{
case SQL_HANDLE_ENV:
hLog = ((HDRVENV)hHandle)->hLog;
break;
case SQL_HANDLE_DBC:
hLog = ((HDRVDBC)hHandle)->hLog;
break;
case SQL_HANDLE_STMT:
hLog = ((HDRVSTMT)hHandle)->hLog;
break;
case SQL_HANDLE_DESC:
default:
return SQL_ERROR;
}
/* get message */
if ( logPeekMsg( hLog, 1, &hMsg ) != LOG_SUCCESS )
return SQL_NO_DATA;
if ( pnNativeError )
*pnNativeError = hMsg->nCode;
if ( pszMessageText )
strncpy( (char*)pszMessageText, hMsg->pszMessage, nBufferLength-1 );
if ( pnStringLength )
*pnStringLength = strlen( (char*)hMsg->pszMessage );
return SQL_SUCCESS;
}
SQLRETURN SQLGetDiagRec( SQLSMALLINT nHandleType,
SQLHANDLE hHandle,
SQLSMALLINT nRecordNumber,
SQLCHAR * pszState,
SQLINTEGER * pnNativeError,
SQLCHAR * pszMessageText,
SQLSMALLINT nBufferLength,
SQLSMALLINT * pnStringLength
)
{
return SQLGetDiagRec_( nHandleType, hHandle, nRecordNumber, pszState, pnNativeError, pszMessageText, nBufferLength, pnStringLength );
}
|