]>
git.saurik.com Git - wxWidgets.git/blob - src/iodbc/herr.c
6 * Error stack management functions
8 * The iODBC driver manager.
10 * Copyright (C) 1995 by Ke Jin <kejin@empress.com>
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Library General Public
14 * License as published by the Free Software Foundation; either
15 * version 2 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Library General Public License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with this library; if not, write to the Free
24 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
44 _iodbcdm_popsqlerr (HERR herr
)
46 sqlerr_t
*list
= (sqlerr_t
*) herr
;
49 if (herr
== SQL_NULL_HERR
)
63 _iodbcdm_freesqlerrlist (HERR herrlist
)
67 for (list
= herrlist
; list
!= 0;)
69 list
= _iodbcdm_popsqlerr (list
);
81 sqlerr_t
*perr
= (sqlerr_t
*) herr
;
84 if (herr
!= SQL_NULL_HERR
)
90 /* over wirte the top entry to prevent error stack blow out */
98 ebuf
= (sqlerr_t
*) MEM_ALLOC (sizeof (sqlerr_t
));
108 ebuf
->next
= (sqlerr_t
*) herr
;
115 _iodbcdm_getsqlstate (
119 sqlerr_t
*perr
= (sqlerr_t
*) herr
;
122 if (herr
== SQL_NULL_HERR
|| tab
== NULL
)
124 return (char FAR
*) NULL
;
128 ptr
->code
!= en_sqlstat_total
;
131 if (ptr
->code
== perr
->code
)
133 return (char FAR
*) (ptr
->stat
);
137 return (char FAR
*) NULL
;
142 _iodbcdm_getsqlerrmsg (
146 sqlerr_t
*perr
= (sqlerr_t
*) herr
;
149 if (herr
== SQL_NULL_HERR
)
154 if (perr
->msg
== NULL
&& errtab
== NULL
)
159 if (perr
->msg
!= NULL
)
164 for (ptr
= (sqlerrmsg_t
*) errtab
;
165 ptr
->code
!= en_sqlstat_total
;
168 if (ptr
->code
== perr
->code
)
170 return (char FAR
*) ptr
->msg
;
174 return (char FAR
*) NULL
;
183 UCHAR FAR
* szSqlstate
,
184 SDWORD FAR
* pfNativeError
,
185 UCHAR FAR
* szErrorMsg
,
187 SWORD FAR
* pcbErrorMsg
)
189 GENV_t FAR
*genv
= (GENV_t FAR
*) henv
;
190 DBC_t FAR
*pdbc
= (DBC_t FAR
*) hdbc
;
191 STMT_t FAR
*pstmt
= (STMT_t FAR
*) hstmt
;
194 HENV dhenv
= SQL_NULL_HENV
;
195 HDBC dhdbc
= SQL_NULL_HDBC
;
196 HSTMT dhstmt
= SQL_NULL_HSTMT
;
198 HERR herr
= SQL_NULL_HERR
;
199 HPROC hproc
= SQL_NULL_HPROC
;
201 char FAR
*errmsg
= NULL
;
202 char FAR
*ststr
= NULL
;
205 RETCODE retcode
= SQL_SUCCESS
;
207 if (hstmt
!= SQL_NULL_HSTMT
) /* retrive stmt err */
212 if (thdbc
== SQL_NULL_HDBC
)
214 return SQL_INVALID_HANDLE
;
216 hproc
= _iodbcdm_getproc (thdbc
, en_Error
);
217 dhstmt
= pstmt
->dhstmt
;
220 else if (hdbc
!= SQL_NULL_HDBC
) /* retrive dbc err */
224 if (thdbc
== SQL_NULL_HDBC
)
226 return SQL_INVALID_HANDLE
;
228 hproc
= _iodbcdm_getproc (thdbc
, en_Error
);
232 if (herr
== SQL_NULL_HERR
233 && pdbc
->henv
== SQL_NULL_HENV
)
235 return SQL_NO_DATA_FOUND
;
238 else if (henv
!= SQL_NULL_HENV
) /* retrive env err */
242 /* Drivers shouldn't push error message
243 * on envoriment handle */
245 if (herr
== SQL_NULL_HERR
)
247 return SQL_NO_DATA_FOUND
;
254 return SQL_INVALID_HANDLE
;
257 if (szErrorMsg
!= NULL
)
259 if (cbErrorMsgMax
< 0
260 || cbErrorMsgMax
> SQL_MAX_MESSAGE_LENGTH
- 1)
263 /* SQLError() doesn't post error for itself */
267 if (herr
== SQL_NULL_HERR
) /* no err on drv mng */
270 if (hproc
== SQL_NULL_HPROC
)
272 PUSHSQLERR (herr
, en_IM001
);
277 CALL_DRIVER (thdbc
, retcode
, hproc
, en_Error
,
278 (dhenv
, dhdbc
, dhstmt
, szSqlstate
, pfNativeError
, szErrorMsg
,
279 cbErrorMsgMax
, pcbErrorMsg
))
284 if (szSqlstate
!= NULL
)
288 /* get sql state string */
289 ststr
= (char FAR
*) _iodbcdm_getsqlstate (herr
,
290 (void FAR
*) sqlerrmsg_tab
);
298 len
= (int) STRLEN (ststr
);
301 STRNCPY (szSqlstate
, ststr
, len
);
303 /* buffer size of szSqlstate is not checked. Applications
304 * suppose provide enough ( not less than 6 bytes ) buffer
309 if (pfNativeError
!= NULL
)
311 /* native error code is specific to data source */
312 *pfNativeError
= (SDWORD
) 0L;
315 if (szErrorMsg
== NULL
|| cbErrorMsgMax
== 0)
317 if (pcbErrorMsg
!= NULL
)
319 *pcbErrorMsg
= (SWORD
) 0;
325 char msgbuf
[256] = {'\0'};
327 /* get sql state message */
328 errmsg
= _iodbcdm_getsqlerrmsg (herr
, (void FAR
*) sqlerrmsg_tab
);
332 errmsg
= (char FAR
*) "";
335 sprintf (msgbuf
, "%s%s", sqlerrhd
, errmsg
);
337 len
= STRLEN (msgbuf
);
339 if (len
< cbErrorMsgMax
- 1)
341 retcode
= SQL_SUCCESS
;
345 len
= cbErrorMsgMax
- 1;
346 retcode
= SQL_SUCCESS_WITH_INFO
;
347 /* and not posts error for itself */
350 STRNCPY ((char *) szErrorMsg
, msgbuf
, len
);
353 if (pcbErrorMsg
!= NULL
)
355 *pcbErrorMsg
= (SWORD
) len
;
359 switch (handle
) /* free this err */
362 genv
->herr
= _iodbcdm_popsqlerr (genv
->herr
);
366 pdbc
->herr
= _iodbcdm_popsqlerr (pdbc
->herr
);
370 pstmt
->herr
= _iodbcdm_popsqlerr (pstmt
->herr
);