home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a063 / 6.img / SAMPLE / APTFORMS / MSGHNDLR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-24  |  1.4 KB  |  71 lines

  1. #include <sybfront.h>
  2. #include <sybdb.h>
  3. #include <sybfrs.h>
  4.  
  5. #if MSDOS
  6. #    include    "aforms.h"
  7. #endif /* MSDOS */
  8.  
  9. /*
  10. **  MSG_HANDLER
  11. **  Catch SQL Server error or information messages.
  12. */
  13. int msg_handler(dbproc, msgno, msgstate, severity, msgtext, 
  14.                 srvname, procname, line)
  15.  
  16. DBPROCESS       *dbproc;
  17. DBINT           msgno;
  18. int             msgstate;
  19. int             severity;
  20. char            *msgtext;
  21. char            *srvname;
  22. char            *procname;
  23. DBUSMALLINT     line;
  24.  
  25. {
  26.     int             i;
  27.     char  tmpbuf[256];
  28.     char  msgbuf[256];
  29.  
  30.     /* Null out mesage buffers to avoid spurious garbage */
  31.     for (i = 0; i< 256; i++)
  32.     {
  33.         tmpbuf[i] ='\0';
  34.         msgbuf[i] ='\0';
  35.     }
  36.     /* For informational messages, be brief. */
  37.     if (severity == 0)
  38.     {
  39.         fsmessage(msgtext);
  40.         return(0);
  41.     }
  42.  
  43.     sprintf (tmpbuf, "Msg %ld, Level %d, State %d\n", 
  44.             msgno, severity, msgstate);
  45.     strcat(msgbuf, tmpbuf);
  46.     
  47. #if DBLIB40
  48.     if (strlen(srvname) > 0)
  49.     {
  50.         sprintf (tmpbuf, "Server '%s', ", srvname);
  51.         strcat(msgbuf, tmpbuf);
  52.     }
  53.     if (strlen(procname) > 0)
  54.     {
  55.         sprintf (tmpbuf, "Procedure '%s', ", procname);
  56.         strcat(msgbuf, tmpbuf);
  57.     }
  58.     if (line > 0)
  59.     {
  60.         sprintf (tmpbuf, "Line %d", line);
  61.         strcat(msgbuf, tmpbuf);
  62.     }
  63. #endif    /* DBLIB40 */
  64.  
  65.     sprintf(tmpbuf, "\n\t%s\n", msgtext);
  66.     strcat(msgbuf, tmpbuf);
  67.  
  68.     fsmessage(msgbuf);
  69.     return(0);
  70. }
  71.