home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / db02_src.zip / dberr.cc < prev    next >
C/C++ Source or Header  |  1993-11-05  |  5KB  |  214 lines

  1. /*************************************************************************
  2.  * Source Id :
  3.  *
  4.  * $Id: dberr.cc,v 1.14 1993/11/05 13:46:57 kevinl Exp $
  5.  *-------------------------------------------------------------------------
  6.  * Project Notes :
  7.  *
  8.  *  Diamond Base
  9.  *  ============
  10.  *      A solid database implementation, spurred on by the continuing
  11.  *  Metal (Lead) Base saga.
  12.  *
  13.  *  Project Team :
  14.  *        A. Davison
  15.  *        K. Lentin
  16.  *        D. Platt
  17.  *
  18.  *    Project Commenced : 05-02-1993
  19.  *
  20.  *-------------------------------------------------------------------------
  21.  *  Module Notes :
  22.  *
  23.  *    dbErr : A global error handler.
  24.  *
  25.  *  Original Author : Daz / Andy
  26.  *
  27.  *-------------------------------------------------------------------------
  28.  * Revision History:
  29.  *
  30.  * $Log: dberr.cc,v $
  31. // Revision 1.14  1993/11/05  13:46:57  kevinl
  32. // Protocol and fixes
  33. //
  34. // Revision 1.13  1993/11/03  13:48:27  kevinl
  35. // Fixed something little
  36. //
  37. // Revision 1.12  1993/11/03  10:45:26  kevinl
  38. // Needs string.h
  39. //
  40. // Revision 1.11  1993/08/05  11:52:08  darrenp
  41. // added db_refid error for MV.
  42. //
  43. // Revision 1.10  1993/07/05  05:36:19  darrenp
  44. // Added db_nomem and db_comms for the multi version.
  45. //
  46. // Revision 1.9  1993/06/23  05:21:22  kevinl
  47. // Mallocs are now in angular brackets
  48. //
  49. // Revision 1.8  1993/05/26  01:01:39  kevinl
  50. // MALLOC_H_MISSING
  51. //
  52. // Revision 1.7  1993/05/06  04:00:19  kevinl
  53. // SASC define for malloc.h
  54. //
  55. // Revision 1.6  1993/05/03  01:34:07  kevinl
  56. // 2 cases left out of switch
  57. //
  58. // Revision 1.5  1993/04/25  11:21:28  kevinl
  59. // Comments
  60. //
  61. // Revision 1.4  1993/03/30  14:37:48  kevinl
  62. // Modified error handling again. now we can get a string back (if we want)
  63. //
  64. // Revision 1.3  1993/03/29  23:26:47  kevinl
  65. // Support for diaRel's error handling
  66. //
  67. // Revision 1.2  1993/03/29  08:21:19  darrenp
  68. // Added malloc library support
  69. //
  70. // Revision 1.1  1993/03/28  10:39:20  kevinl
  71. // Initial revision
  72. //
  73.  **************************************************************************/
  74.  
  75. #include <iostream.h>
  76. #include <stdio.h>
  77. #include <string.h>
  78.  
  79. #ifndef MALLOC_H_MISSING
  80. #include <malloc.h>
  81. #endif
  82. #include <dberr.h>
  83.  
  84. // This is the status returned by the last dbErr call
  85. // extraErr can be optionally added and is cleared by subsequent calls
  86.  
  87. dbError dbErrorStatus = db_ok;
  88. char extraErr[50] = "";
  89.  
  90. //----------------------------------------
  91. // Register an error by remembering the
  92. // error code. Then return the error 
  93. // code.
  94.  
  95. dbError dbErr(dbError err, char* extra)
  96. {
  97.     if (extra)
  98.         strcpy(extraErr, extra);
  99.     else
  100.         extraErr[0] = 0;
  101.     dbErrorStatus = err;
  102.     return err;
  103. }
  104.  
  105. // Display a particular error message. temp is used to reinstate the
  106. // the last error code.
  107.  
  108. void dbErr(char* msg, dbError err)
  109. {
  110.     dbError temp = dbErrorStatus;
  111.     dbErrorStatus = err;
  112.     dbErr(msg);
  113.     dbErrorStatus = temp;
  114. }
  115.  
  116. //--------------------------------------------
  117. // Display the current error status, preceeded
  118. // by an optional error message.
  119.  
  120. void dbErr(char* msg)
  121. {
  122.     if (msg)
  123.         cerr << msg << " : " ;
  124.     else
  125.         cerr << "Error : " << endl;
  126.  
  127.     if (*extraErr)
  128.         cerr << extraErr << " : ";
  129.  
  130.     cerr << dbErrStr(dbErrorStatus) << endl;
  131. }
  132.  
  133. // Return the string representation of err
  134.  
  135. char* dbErrStr(dbError err)
  136. {
  137.     static char errStr[100];
  138.  
  139.     switch (err)
  140.     {
  141.         case db_ok : 
  142.             strcpy(errStr,"No error.");
  143.             break;
  144.         case db_alreadyregistered:
  145.             strcpy(errStr,"Relation already registered.");
  146.             break;
  147.         case db_unimp:
  148.             strcpy(errStr,"Not yet implemented.");
  149.             break;
  150.         case db_nfound:
  151.             strcpy(errStr,"Not Found.");
  152.             break;
  153.         case db_range:
  154.             strcpy(errStr,"Range Error.");
  155.             break;    
  156.         case db_toomany:
  157.             strcpy(errStr,"Too many.");
  158.             break;
  159.         case db_noquery:
  160.             strcpy(errStr,"No (such) query currently in progress.");
  161.             break;
  162.         case db_querylocked:
  163.             strcpy(errStr,"Query has a lock placed on it.");
  164.             break;
  165.         case db_reclocked:
  166.             strcpy(errStr,"Record is locked.");
  167.             break;
  168.         case db_dup:
  169.             strcpy(errStr,"Duplicate data found in database.");
  170.             break;
  171.         case db_badName:
  172.             strcpy(errStr,"Bad Name. - who knows?");
  173.             break;
  174.         case db_notopen:
  175.             strcpy(errStr,"Data file not open.");
  176.             break;
  177.         case db_err:
  178.             strcpy(errStr,"An unnamed error occured.");
  179.             break;
  180.         case db_alreadyopen:
  181.             strcpy(errStr,"Data file is already open.");
  182.             break;
  183.         case db_locked:
  184.             strcpy(errStr,"Data base is locked.");
  185.             break;
  186.         case db_unlocked:
  187.             strcpy(errStr,"Database unlocked.");
  188.             break;
  189.         case db_nobuckets:
  190.             strcpy(errStr,"Cannot create a bucket.");
  191.             break;
  192.         case db_eof:
  193.             strcpy(errStr,"End of file reached.");
  194.             break;
  195.         case db_nomem:
  196.             strcpy(errStr,"Out of memory. MV");
  197.             break;
  198.         case db_comm:
  199.             strcpy(errStr,"Comm. error. MV");
  200.             break;
  201.         case db_refid:
  202.             strcpy(errStr,"Bad reference id. MV");
  203.             break;
  204.         case db_protocol:
  205.             strcpy(errStr,"Old protocol. MV");
  206.             break;
  207.         default:
  208.             sprintf(errStr,"Danger, Will Robinson ! Unspecified error %d approaching !", err);
  209.             break;
  210.     }
  211.     return errStr;
  212. }
  213.  
  214.