home *** CD-ROM | disk | FTP | other *** search
- /*---------------------------------------------------------------------------
- *
- * Copyright (c) 1995 Cadre Technologies Inc.
- *
- * This software is furnished under a license and may be used only in
- * accordance with the terms of such license and with the inclusion of
- * the above copyright notice. This software or any other copies thereof
- * may not be provided or otherwise made available to any other person.
- * No title to and ownership of the software is hereby transferred.
- *
- * The information in this software is subject to change without notice
- * and should not be construed as a commitment by Cadre Technologies Inc.
- *
- *---------------------------------------------------------------------------
- *
- * File : @(#)SqlPrint.cp 1.1
- * Original date : 28 November 1995
- * Description : General error handling function
- * taken from examples in SYBASE Open Client Embedded
- * SQL/C Programmer's Guide
- * uses RogueWave class library
- *
- *---------------------------------------------------------------------------
- */
- static const char SccsId[]="@(#)SqlPrint.cp 1.1\t06 Feb 1996 Copyright 1995 Cadre Technologies Inc.";
-
- #ifndef SQLPRINT_HXX
- #include "SqlPrint.hxx"
- #endif
-
- #include <stdlib.h>
- #include <stdio.h>
-
- EXEC SQL WHENEVER SQLERROR CONTINUE;
- EXEC SQL WHENEVER SQLWARNING CONTINUE;
- EXEC SQL WHENEVER NOT FOUND CONTINUE;
-
- // Code taken from "Open Client Embedded SQL/C Programmer's Guide",
- // Ch. 8 "Handling Errors", Sect. "Using get diagnostics".
- //
- void sqlprint()
- {
- EXEC SQL BEGIN DECLARE SECTION;
- int nrMesg;
- int condCnt;
- EXEC SQL INCLUDE SQLCA;
- EXEC SQL END DECLARE SECTION;
-
- EXEC SQL GET DIAGNOSTICS :nrMesg = NUMBER;
-
- for (condCnt = 1; condCnt <= nrMesg; ++condCnt) {
- EXEC SQL GET DIAGNOSTICS EXCEPTION :condCnt :sqlca = SQLCA_INFO;
-
- // ignore CS_STATUS_RESULT returned after every stored procedure call
- //
- if (sqlca.sqlcode == -25009)
- return;
-
- // ignore "Command has been aborted." msg if not first msg
- //
- if (sqlca.sqlcode == -3621 && condCnt != 1)
- return;
-
- if (sqlca.sqlcode < 0) {
- // sqlerror
- printf("SYBASE ERROR [%d] (#%d): %s\n", sqlca.sqlcode, condCnt, sqlca.sqlerrm.sqlerrmc);
- } else if (sqlca.sqlcode == 100) {
- // not found
- printf("SYBASE MESSAGE [%d] (#%d): No rows returned from last statement.\n", sqlca.sqlcode, condCnt);
- } else if (sqlca.sqlcode == 0) {
- // sqlwarning
- if (sqlca.sqlwarn[1] == 'W')
- printf("SYBASE WARNING [%d] (#%d): %s\n", sqlca.sqlcode, condCnt, sqlca.sqlerrm.sqlerrmc);
- else if (sqlca.sqlwarn[3] == 'W')
- printf("SYBASE WARNING [%d] (#%d): %s\n", sqlca.sqlcode, condCnt, sqlca.sqlerrm.sqlerrmc);
- }
- }
- }
-
-