1 /**********************************************************************
2  * SQLError (deprecated see SQLGetDiagRec)
3  *
4  **********************************************************************
5  *
6  * This code was created by Peter Harvey (mostly during Christmas 98/99).
7  * This code is LGPL. Please ensure that this message remains in future
8  * distributions and uses of this code (thats about all I get out of it).
9  * - Peter Harvey pharvey@codebydesign.com
10  *
11  **********************************************************************/
12 
13 #include <config.h>
14 #include "driver.h"
15 
SQLError(SQLHENV hDrvEnv,SQLHDBC hDrvDbc,SQLHSTMT hDrvStmt,SQLCHAR * szSqlState,SQLINTEGER * pfNativeError,SQLCHAR * szErrorMsg,SQLSMALLINT nErrorMsgMax,SQLSMALLINT * pcbErrorMsg)16 SQLRETURN SQLError( SQLHENV     hDrvEnv,
17 					SQLHDBC     hDrvDbc,
18 					SQLHSTMT    hDrvStmt,
19 					SQLCHAR   	*szSqlState,
20 					SQLINTEGER  *pfNativeError,
21 					SQLCHAR   	*szErrorMsg,
22 					SQLSMALLINT nErrorMsgMax,
23 					SQLSMALLINT	*pcbErrorMsg )
24 {
25 	HDRVENV		hEnv	= (HDRVENV)hDrvEnv;
26 	HDRVDBC		hDbc	= (HDRVDBC)hDrvDbc;
27     HDRVSTMT	hStmt	= (HDRVSTMT)hDrvStmt;
28 	char    *pszState       = NULL;			 /* pointer to status code   */
29 	char    *pszErrMsg      = NULL;			 /* pointer to error message */
30 	char	szMsgHdr[1024];
31 	int		nCode;
32 
33 	/* SANITY CHECKS */
34     if( hEnv == SQL_NULL_HENV && hDbc == SQL_NULL_HDBC && hStmt == SQL_NULL_HSTMT )
35         return SQL_INVALID_HANDLE;
36 
37 	/* DEFAULTS */
38 	szSqlState[0]	= '\0';
39 	*pfNativeError	= 0;
40 	szErrorMsg[0]	= '\0';
41 	*pcbErrorMsg	= 0;
42 
43 	/* STATEMENT */
44     if( hStmt != SQL_NULL_HENV )
45 	{
46 		if ( logPopMsg( hStmt->hLog ) != LOG_SUCCESS )
47 			return SQL_NO_DATA;
48 		strncpy( szErrorMsg, hStmt->szSqlMsg, nErrorMsgMax );
49 		*pcbErrorMsg = strlen( szErrorMsg );
50 		return SQL_SUCCESS;
51 	}
52 
53 	/* CONNECTION */
54     if( hDbc != SQL_NULL_HDBC )
55 	{
56 		if ( logPopMsg( hDbc->hLog ) != LOG_SUCCESS )
57 			return SQL_NO_DATA;
58 		strncpy( szErrorMsg, hDbc->szSqlMsg, nErrorMsgMax );
59 		*pcbErrorMsg = strlen( szErrorMsg );
60 		return SQL_SUCCESS;
61 	}
62 
63 	/* ENVIRONMENT */
64     if( hEnv != SQL_NULL_HSTMT )
65 	{
66 		if ( logPopMsg( hEnv->hLog ) != LOG_SUCCESS )
67 			return SQL_NO_DATA;
68 		strncpy( szErrorMsg, hEnv->szSqlMsg, nErrorMsgMax );
69 		*pcbErrorMsg = strlen( szErrorMsg );
70 		return SQL_SUCCESS;
71 	}
72 
73 	return SQL_NO_DATA;
74 }
75 
76 
77