home *** CD-ROM | disk | FTP | other *** search
/ Borland Programmer's Resource / Borland_Programmers_Resource_CD_1995.iso / code / kdbf / pxmsg.cpp < prev   
Encoding:
C/C++ Source or Header  |  1995-05-19  |  3.7 KB  |  124 lines

  1. // PXMSG.CPP  Returns error strings from error codes.
  2. //
  3. // For Windows, compile with -DWINDOWS so that error codes are converted
  4. // to the ANSI character set.
  5. //
  6. // Note to translators: When translating these error messages, use ASCII,
  7. // not ANSI, character set, even for Windows. For example, specify "déjà"
  8. // for "already".
  9.  
  10. // DBF - (C) Copyright 1994 by Borland International
  11.  
  12. #include "kdbf.h"
  13. #pragma hdrstop
  14.  
  15. #ifdef __DLL__
  16.    #define EXPORT _export
  17. #else
  18.    #define EXPORT
  19. #endif
  20.  
  21. typedef struct
  22. {
  23.    int code;
  24.    char far *msg;
  25. } Message;
  26.  
  27. Message KnownMessages[] = {
  28.  
  29.     // DBF Error Messages
  30.    {PXERR_INVENGINETYPE,   "Invalid Engine Type for this library"},
  31.    {PXERR_ENGINEOPEN,      "Engine is already open"},
  32.    {PXERR_ENGINENOTOPEN,   "Engine is not open"},
  33.    {PXERR_DBALREADYOPEN,   "Database is already open"},
  34.    {PXERR_DBNOTOPEN,       "Database is not open"},
  35.    {PXERR_CURSORALREADYOPEN,"Cursor is already open"},
  36.    {PXERR_CURSORNOTOPEN,    "Cursor is not open"},
  37.    {PXERR_INVFIELDTYPE,     "Field type value supplied is invalid"}, 
  38.    {PXERR_RECALREADYATT,    "Record is already attched to a Cursor"},
  39.    {PXERR_RECNOTATT,        "Record is not attached to a Cursor"},
  40.    {PXERR_INVCURRRECORD,    "Cursor is not positioned on a valid record"}, 
  41.    {PXERR_TABLESDIFFER,     "Tables corresponding to Cursors are different"},
  42.    {PXERR_INVKEYCOUNT,      "Invalid number of key values for current index"},  
  43.    {PXERR_NOKEYMAP,         "Key map for compound key has not been specified"},  
  44.    {PXERR_NOCLEARNULL,      "clearNull is not allowed on Generic Records"},
  45.    {PXERR_DATACONV,         "Data conversion of a field's value failed"},   
  46.    {PXERR_BLOBNOTOPEN,      "Blob field is not open"},
  47.  
  48.    // KDBF Error messages
  49.    {PXERR_STATEMENTOPEN,    "Statement is open"},
  50.    {PXERR_STATEMENTNOTOPEN, "Statement is not open" }
  51.    };
  52.  
  53. #define KnownMsgSize ( sizeof(KnownMessages) / sizeof(KnownMessages[0]) )
  54.  
  55.  
  56. // internal error >200
  57. //
  58. char far *interror = "Internal error no: ";
  59. char far *undef    = "Undefined errorcode";
  60.  
  61.  
  62. static char errMsg[DBIMAXMSGLEN * 5];   // Area in which a message is stored.
  63.  
  64. //
  65. // Returns the error message text for a given error code.
  66. //
  67.  
  68. char far * pascal far EXPORT PXOopErrMsg(Retcode errCode)
  69. {
  70.     int i;
  71.     char far *pOemStr = NULL;
  72.     DBIErrInfo ErrInfo;
  73.  
  74.     // Get DBF Error
  75.     for (i = 0; i < KnownMsgSize; i++ )
  76.     {
  77.         if(KnownMessages[i].code == errCode)
  78.         {
  79.             pOemStr = KnownMessages[i].msg;
  80.             break;
  81.         }
  82.     }
  83.  
  84.     // If not an old error message
  85.     if (!pOemStr)
  86.     {
  87.         if ((errCode != DBIERR_CANTFINDODAPI) &&
  88.             (errCode != DBIERR_NOTINITIALIZED))
  89.         {
  90.             DbiGetErrorInfo(TRUE, &ErrInfo);
  91.  
  92.             // Check if last error is not the error for which information
  93.             // is desired - DbiGetErrInfo only return information on
  94.             // the last Error....
  95.             if (ErrInfo.iError == errCode)
  96.             {
  97.                 sprintf(errMsg, "%s\r\n%s\r\n%s\r\n%s\r\n%s",
  98.                         ErrInfo.szErrCode,
  99.                         ErrInfo.szContext1, ErrInfo.szContext2,
  100.                         ErrInfo.szContext3, ErrInfo.szContext4);
  101.             }
  102.             else
  103.             {
  104.                 DbiGetErrorString(errCode, errMsg);
  105.             }
  106.         }
  107.         else
  108.         {
  109.             if (errCode != DBIERR_NOTINITIALIZED)
  110.             {
  111.                 strcpy(errMsg, "BDE Not Initialized");
  112.             }
  113.             else
  114.             {
  115.                 strcpy(errMsg, "Can't find BDE DLLs");
  116.             }
  117.         }
  118.         pOemStr = errMsg;
  119.     }
  120.  
  121.     return pOemStr;
  122. }
  123.  
  124.