home *** CD-ROM | disk | FTP | other *** search
/ Delphi Anthology / aDELPHI.iso / Runimage / Delphi50 / Source / Vcl / ib.pas < prev    next >
Pascal/Delphi Source File  |  1999-08-11  |  20KB  |  617 lines

  1. {********************************************************}
  2. {                                                        }
  3. {       Borland Delphi Visual Component Library          }
  4. {       InterBase Express core components                }
  5. {                                                        }
  6. {       Copyright (c) 1998-1999 Inprise Corporation      }
  7. {                                                        }
  8. {    InterBase Express is based in part on the product   }
  9. {    Free IB Components, written by Gregory H. Deatz for }
  10. {    Hoagland, Longo, Moran, Dunst & Doukas Company.     }
  11. {    Free IB Components is used under license.           }
  12. {                                                        }
  13. {********************************************************}
  14.  
  15. unit IB;
  16.  
  17. interface
  18.  
  19. uses
  20.   Windows, SysUtils, Classes, IBHeader, IBExternals, IBUtils, DB;
  21.  
  22. type
  23.     EIBError                  = class(EDatabaseError)
  24.   private
  25.     FSQLCode: Long;
  26.     FIBErrorCode: Long;
  27.   public
  28.     constructor Create(ASQLCode: Long; Msg: string); overload;
  29.     constructor Create(ASQLCode: Long; AIBErrorCode: Long; Msg: string); overload;
  30.     property SQLCode: Long read FSQLCode;
  31.     property IBErrorCode: Long read FIBErrorCode;
  32.   end;
  33.  
  34.   EIBInterBaseError         = class(EIBError);
  35.   EIBClientError            = class(EIBError);
  36.  
  37.   TIBDataBaseErrorMessage    = (ShowSQLCode,
  38.                                 ShowIBMessage,
  39.                                 ShowSQLMessage);
  40.   TIBDataBaseErrorMessages   = set of TIBDataBaseErrorMessage;
  41.   TIBClientError            = (
  42.     ibxeUnknownError,
  43.     ibxeInterBaseMissing,
  44.     ibxeInterBaseInstallMissing,
  45.     ibxeIB60feature,
  46.     ibxeNotSupported,
  47.     ibxeNotPermitted,
  48.     ibxeFileAccessError,
  49.     ibxeConnectionTimeout,
  50.     ibxeCannotSetDatabase,
  51.     ibxeCannotSetTransaction,
  52.     ibxeOperationCancelled,
  53.     ibxeDPBConstantNotSupported,
  54.     ibxeDPBConstantUnknown,
  55.     ibxeTPBConstantNotSupported,
  56.     ibxeTPBConstantUnknown,
  57.     ibxeDatabaseClosed,
  58.     ibxeDatabaseOpen,
  59.     ibxeDatabaseNameMissing,
  60.     ibxeNotInTransaction,
  61.     ibxeInTransaction,
  62.     ibxeTimeoutNegative,
  63.     ibxeNoDatabasesInTransaction,
  64.     ibxeUpdateWrongDB,
  65.     ibxeUpdateWrongTR,
  66.     ibxeDatabaseNotAssigned,
  67.     ibxeTransactionNotAssigned,
  68.     ibxeXSQLDAIndexOutOfRange,
  69.     ibxeXSQLDANameDoesNotExist,
  70.     ibxeEOF,
  71.     ibxeBOF,
  72.     ibxeInvalidStatementHandle,
  73.     ibxeSQLOpen,
  74.     ibxeSQLClosed,
  75.     ibxeDatasetOpen,
  76.     ibxeDatasetClosed,
  77.     ibxeUnknownSQLDataType,
  78.     ibxeInvalidColumnIndex,
  79.     ibxeInvalidParamColumnIndex,
  80.     ibxeInvalidDataConversion,
  81.     ibxeColumnIsNotNullable,
  82.     ibxeBlobCannotBeRead,
  83.     ibxeBlobCannotBeWritten,
  84.     ibxeEmptyQuery,
  85.     ibxeCannotOpenNonSQLSelect,
  86.     ibxeNoFieldAccess,
  87.     ibxeFieldReadOnly,
  88.     ibxeFieldNotFound,
  89.     ibxeNotEditing,
  90.     ibxeCannotInsert,
  91.     ibxeCannotPost,
  92.     ibxeCannotUpdate,
  93.     ibxeCannotDelete,
  94.     ibxeCannotRefresh,
  95.     ibxeBufferNotSet,
  96.     ibxeCircularReference,
  97.     ibxeSQLParseError,
  98.     ibxeUserAbort,
  99.     ibxeDataSetUniDirectional,
  100.     ibxeCannotCreateSharedResource,
  101.     ibxeWindowsAPIError,
  102.     ibxeColumnListsDontMatch,
  103.     ibxeColumnTypesDontMatch,
  104.     ibxeCantEndSharedTransaction,
  105.     ibxeFieldUnsupportedType,
  106.     ibxeCircularDataLink,
  107.     ibxeEmptySQLStatement,
  108.     ibxeIsASelectStatement,
  109.     ibxeRequiredParamNotSet,
  110.     ibxeNoStoredProcName,
  111.     ibxeIsAExecuteProcedure,
  112.     ibxeUpdateFailed,
  113.     ibxeNotCachedUpdates,
  114.     ibxeNotLiveRequest,
  115.     ibxeNoProvider,
  116.     ibxeNoRecordsAffected,
  117.     ibxeNoTableName,
  118.     ibxeCannotCreatePrimaryIndex,
  119.     ibxeCannotDropSystemIndex,
  120.     ibxeTableNameMismatch,
  121.     ibxeIndexFieldMissing,
  122.     ibxeInvalidCancellation,
  123.     ibxeInvalidEvent,
  124.     ibxeMaximumEvents,
  125.     ibxeNoEventsRegistered,
  126.     ibxeInvalidQueueing,
  127.     ibxeInvalidRegistration,
  128.     ibxeInvalidBatchMove,
  129.     ibxeSQLDialectInvalid,
  130.     ibxeSPBConstantNotSupported,
  131.     ibxeSPBConstantUnknown,
  132.     ibxeServiceActive,
  133.     ibxeServiceInActive,
  134.     ibxeServerNameMissing,
  135.     ibxeQueryParamsError,
  136.     ibxeStartParamsError,
  137.     ibxeOutputParsingError,
  138.     ibxeUseSpecificProcedures,
  139.     ibxeSQLMonitorAlreadyPresent
  140.     );
  141.  
  142.   TStatusVector              = array[0..19] of ISC_STATUS;
  143.   PStatusVector              = ^TStatusVector;
  144.  
  145.   { TIBTLGlobals }
  146.  
  147.   { A single structure will be used to maintain all thread-local "globals" }
  148.   TIBTLGlobals              = record
  149.     FStatusVector: TStatusVector;
  150.   end;
  151.   PIBTLGlobals              = ^TIBTLGlobals;
  152.  
  153. resourcestring
  154. { generic strings used in code }
  155.   SIBDatabaseEditor = 'Da&tabase Editor...';
  156.   SIBTransactionEditor = '&Transaction Editor...';
  157.   SDatabaseFilter = 'Database Files (*.gdb)|*.gdb|All files (*.*)|*.*';
  158.   SDisconnectDatabase = 'Database is currently connected. Disconnect and continue?';
  159.   SCommitTransaction = 'Transaction is currently Active. Rollback and continue?';
  160.   SExecute = 'E&xecute';
  161.   SNoDataSet = 'No dataset association';
  162.   SSQLGenSelect = 'Must select at least one key field and one update field';
  163.   SSQLNotGenerated = 'Update SQL statements not generated, exit anyway?';
  164.   SIBUpdateSQLEditor = '&UpdateSQL Editor...';
  165.   SSQLDataSetOpen = 'Unable to determine field names for %s';
  166.  
  167. { strings used in error messages}
  168.   SUnknownError = 'Unknown error';
  169.   SInterBaseMissing = 'InterBase library gds32.dll not found in the path. Please install InterBase to use this functionality';
  170.   SInterBaseInstallMissing = 'InterBase Install DLL ibinstall.dll not found in the path. Please install InterBase 6 to use this functionality';
  171.   SIB60feature = '%s is an InterBase6 function. Please upgrade to InterBase6 to use this functonality';
  172.   SNotSupported = 'Unsupported feature';
  173.   SNotPermitted = 'Not permitted';
  174.   SFileAccessError = 'Temporary file access error';
  175.   SConnectionTimeout = 'Database connection timed out';
  176.   SCannotSetDatabase = 'Cannot set database';
  177.   SCannotSetTransaction = 'Cannot set transaction';
  178.   SOperationCancelled = 'Operation cancelled at user''s request';
  179.   SDPBConstantNotSupported = 'DPB Constant (isc_dpb_%s) is unsupported';
  180.   SDPBConstantUnknown = 'DPB Constant (%d) is unknown';
  181.   STPBConstantNotSupported = 'TPB Constant (isc_tpb_%s) is unsupported';
  182.   STPBConstantUnknown = 'TPB Constant (%d) is unknown';
  183.   SDatabaseClosed = 'Cannot perform operation -- DB is not open';
  184.   SDatabaseOpen = 'Cannot perform operation -- DB is currently open';
  185.   SDatabaseNameMissing = 'Database name is missing';
  186.   SNotInTransaction = 'Transaction is not active';
  187.   SInTransaction = 'Transaction is active';
  188.   STimeoutNegative = 'Timeout values cannot be negative';
  189.   SNoDatabasesInTransaction = 'No databases are listed in transaction component';
  190.   SUpdateWrongDB = 'Updating wrong database';
  191.   SUpdateWrongTR = 'Updating wrong transaction. Unique transaction expected in set';
  192.   SDatabaseNotAssigned = 'Database not assigned';
  193.   STransactionNotAssigned = 'Transaction not assigned';
  194.   SXSQLDAIndexOutOfRange = 'XSQLDA index out of range';
  195.   SXSQLDANameDoesNotExist = 'XSQLDA name does not exist (%s)';
  196.   SEOF = 'End of file';
  197.   SBOF = 'Beginning of file';
  198.   SInvalidStatementHandle = 'Invalid statement handle';
  199.   SSQLOpen = 'IBSQL Open';
  200.   SSQLClosed = 'IBSQL Closed';
  201.   SDatasetOpen = 'Dataset open';
  202.   SDatasetClosed = 'Dataset closed';
  203.   SUnknownSQLDataType = 'Unknown SQL Data type (%d)';
  204.   SInvalidColumnIndex = 'Invalid column index (index exceeds permitted range)';
  205.   SInvalidParamColumnIndex = 'Invalid parameter index (index exceeds permitted range)';
  206.   SInvalidDataConversion = 'Invalid data conversion';
  207.   SColumnIsNotNullable = 'Column cannot be set to null (%s)';
  208.   SBlobCannotBeRead = 'Blob stream cannot be read';
  209.   SBlobCannotBeWritten = 'Blob stream cannot be written';
  210.   SEmptyQuery = 'Empty query';
  211.   SCannotOpenNonSQLSelect = 'Cannot "open" a non-select statement. Use ExecQuery';
  212.   SNoFieldAccess = 'No access to field "%s"';
  213.   SFieldReadOnly = 'Field "%s" is read-only';
  214.   SFieldNotFound = 'Field "%s" not found';
  215.   SNotEditing = 'Not editing';
  216.   SCannotInsert = 'Cannot insert into dataset. (No insert query)';
  217.   SCannotPost = 'Cannot post. (No update/insert query)';
  218.   SCannotUpdate = 'Cannot update. (No update query)';
  219.   SCannotDelete = 'Cannot delete from dataset. (No delete query)';
  220.   SCannotRefresh = 'Cannot refresh row. (No refresh query)';
  221.   SBufferNotSet = 'Buffer not set';
  222.   SCircularReference = 'Circular references not permitted';
  223.   SSQLParseError = 'SQL Parse Error:' + CRLF + CRLF + '%s';
  224.   SUserAbort = 'User abort';
  225.   SDataSetUniDirectional = 'Data set is uni-directional';
  226.   SCannotCreateSharedResource = 'Cannot create shared resource. (Windows error %d)';
  227.   SWindowsAPIError = 'Windows API error. (Windows error %d [$%.8x])';
  228.   SColumnListsDontMatch = 'Column lists do not match';
  229.   SColumnTypesDontMatch = 'Column types don''t match. (From index: %d; To index: %d)';
  230.   SCantEndSharedTransaction = 'Can''t end a shared transaction unless it is forced and equal ' +
  231.                              'to the transaction''s TimeoutAction';
  232.   SFieldUnsupportedType = 'Unsupported Field Type';
  233.   SCircularDataLink = 'Circular DataLink Reference';
  234.   SEmptySQLStatement = 'Empty SQL Statement';
  235.   SIsASelectStatement = 'use Open for a Select Statement';
  236.   SRequiredParamNotSet = 'Required Param value not set';
  237.   SNoStoredProcName = 'No Stored Procedure Name assigned';
  238.   SIsAExecuteProcedure = 'use ExecProc for Procedure; use TQuery for Select procedures';
  239.   SUpdateFailed = 'Update Failed';
  240.   SNotCachedUpdates = 'CachedUpdates not enabled';
  241.   SNotLiveRequest = 'Request is not live - cannot modify';
  242.   SNoProvider = 'No Provider';
  243.   SNoRecordsAffected = 'No Records Affected';
  244.   SNoTableName = 'No Table Name assigned';
  245.   SCannotCreatePrimaryIndex = 'Cannot Create Primary Index; are created automatically';
  246.   SCannotDropSystemIndex = 'Cannot Drop System Index';
  247.   STableNameMismatch = 'Table Name Mismatch';
  248.   SIndexFieldMissing = 'Index Field Missing';
  249.   SInvalidCancellation = 'Cannot Cancel events while processing';
  250.   SInvalidEvent = 'Invalid Event';
  251.   SMaximumEvents = 'Exceded Maximum Event limits';
  252.   SNoEventsRegistered = 'No Events Registered';
  253.   SInvalidQueueing = 'Invalid Queueing';
  254.   SInvalidRegistration = 'Invalid Registration';
  255.   SInvalidBatchMove = 'Invalid Batch Move';
  256.   SSQLDialectInvalid = 'SQL Dialect Invalid';
  257.   SSPBConstantNotSupported = 'SPB Constant Not supported';
  258.   SSPBConstantUnknown = 'SPB Constant Unknown';
  259.   SServiceActive = 'Cannot perform operation -- service is not attached';
  260.   SServiceInActive = 'Cannot perform operation -- service is attached';
  261.   SServerNameMissing = 'Server Name Missing';
  262.   SQueryParamsError = 'Query Parameters missing or incorrect';
  263.   SStartParamsError = 'start Parameters missing or incorrect';
  264.   SOutputParsingError = 'Unexpected Output buffer value';
  265.   SUseSpecificProcedures = 'Generic ServiceStart not applicable: Use Specific Procedures to set configuration params';
  266.   SSQLMonitorAlreadyPresent = 'SQL Monitor Instance is already present';
  267.  
  268. const
  269.   IBPalette1 = 'InterBase'; {do not localize}
  270.   IBPalette2 = 'InterBase Admin'; {do not localize}
  271.  
  272.   IBLocalBufferLength = 512;
  273.   IBBigLocalBufferLength = IBLocalBufferLength * 2;
  274.   IBHugeLocalBufferLength = IBBigLocalBufferLength * 20;
  275.  
  276.   IBErrorMessages: array[TIBClientError] of string = (
  277.     SUnknownError,
  278.     SInterBaseMissing,
  279.     SInterBaseInstallMissing,
  280.     SIB60feature,
  281.     SNotSupported,
  282.     SNotPermitted,
  283.     SFileAccessError,
  284.     SConnectionTimeout,
  285.     SCannotSetDatabase,
  286.     SCannotSetTransaction,
  287.     SOperationCancelled,
  288.     SDPBConstantNotSupported,
  289.     SDPBConstantUnknown,
  290.     STPBConstantNotSupported,
  291.     STPBConstantUnknown,
  292.     SDatabaseClosed,
  293.     SDatabaseOpen,
  294.     SDatabaseNameMissing,
  295.     SNotInTransaction,
  296.     SInTransaction,
  297.     STimeoutNegative,
  298.     SNoDatabasesInTransaction,
  299.     SUpdateWrongDB,
  300.     SUpdateWrongTR,
  301.     SDatabaseNotAssigned,
  302.     STransactionNotAssigned,
  303.     SXSQLDAIndexOutOfRange,
  304.     SXSQLDANameDoesNotExist,
  305.     SEOF,
  306.     SBOF,
  307.     SInvalidStatementHandle,
  308.     SSQLOpen,
  309.     SSQLClosed,
  310.     SDatasetOpen,
  311.     SDatasetClosed,
  312.     SUnknownSQLDataType,
  313.     SInvalidColumnIndex,
  314.     SInvalidParamColumnIndex,
  315.     SInvalidDataConversion,
  316.     SColumnIsNotNullable,
  317.     SBlobCannotBeRead,
  318.     SBlobCannotBeWritten,
  319.     SEmptyQuery,
  320.     SCannotOpenNonSQLSelect,
  321.     SNoFieldAccess,
  322.     SFieldReadOnly,
  323.     SFieldNotFound,
  324.     SNotEditing,
  325.     SCannotInsert,
  326.     SCannotPost,
  327.     SCannotUpdate,
  328.     SCannotDelete,
  329.     SCannotRefresh,
  330.     SBufferNotSet,
  331.     SCircularReference,
  332.     SSQLParseError,
  333.     SUserAbort,
  334.     SDataSetUniDirectional,
  335.     SCannotCreateSharedResource,
  336.     SWindowsAPIError,
  337.     SColumnListsDontMatch,
  338.     SColumnTypesDontMatch,
  339.     SCantEndSharedTransaction,
  340.     SFieldUnsupportedType,
  341.     SCircularDataLink,
  342.     SEmptySQLStatement,
  343.     SIsASelectStatement,
  344.     SRequiredParamNotSet,
  345.     SNoStoredProcName,
  346.     SIsAExecuteProcedure,
  347.     SUpdateFailed,
  348.     SNotCachedUpdates,
  349.     SNotLiveRequest,
  350.     SNoProvider,
  351.     SNoRecordsAffected,
  352.     SNoTableName,
  353.     SCannotCreatePrimaryIndex,
  354.     SCannotDropSystemIndex,
  355.     STableNameMismatch,
  356.     SIndexFieldMissing,
  357.     SInvalidCancellation,
  358.     SInvalidEvent,
  359.     SMaximumEvents,
  360.     SNoEventsRegistered,
  361.     SInvalidQueueing,
  362.     SInvalidRegistration,
  363.     SInvalidBatchMove,
  364.     SSQLDialectInvalid,
  365.     SSPBConstantNotSupported,
  366.     SSPBConstantUnknown,
  367.     SServiceActive,
  368.     SServiceInActive,
  369.     SServerNameMissing,
  370.     SQueryParamsError,
  371.     SStartParamsError,
  372.     SOutputParsingError,
  373.     SUseSpecificProcedures,
  374.     SSQLMonitorAlreadyPresent
  375.   );
  376.  
  377. var
  378.   IBCS: TRTLCriticalSection;
  379.   hIBTLGlobals: DWord;
  380.  
  381. procedure IBAlloc(var P; OldSize, NewSize: Integer);
  382.  
  383. procedure IBError(ErrMess: TIBClientError; const Args: array of const);
  384. procedure IBDataBaseError;
  385.  
  386. procedure InitializeIBTLGlobals;
  387. procedure FreeIBTLGlobals;
  388.  
  389. function StatusVector: PISC_STATUS;
  390. function StatusVectorArray: PStatusVector;
  391. function CheckStatusVector(ErrorCodes: array of ISC_STATUS): Boolean;
  392. function StatusVectorAsText: string;
  393.  
  394. procedure SetIBDataBaseErrorMessages(Value: TIBDataBaseErrorMessages);
  395. function GetIBDataBaseErrorMessages: TIBDataBaseErrorMessages;
  396.  
  397. implementation
  398.  
  399. uses
  400.   IBIntf;
  401.  
  402. var
  403.   IBDataBaseErrorMessages: TIBDataBaseErrorMessages;
  404.  
  405.  
  406. procedure IBAlloc(var P; OldSize, NewSize: Integer);
  407. var
  408.   i: Integer;
  409. begin
  410.   ReallocMem(Pointer(P), NewSize);
  411.   for i := OldSize to NewSize - 1 do PChar(P)[i] := #0;
  412. end;
  413.  
  414. procedure IBError(ErrMess: TIBClientError; const Args: array of const);
  415. begin
  416.   raise EIBClientError.Create(Ord(ErrMess),
  417.                               Format(IBErrorMessages[ErrMess], Args));
  418. end;
  419.  
  420. procedure IBDataBaseError;
  421. var
  422.   sqlcode: Long;
  423.   IBErrorCode: Long;
  424.   local_buffer: array[0..IBHugeLocalBufferLength - 1] of char;
  425.   usr_msg: string;
  426.   status_vector: PISC_STATUS;
  427.   IBDataBaseErrorMessages: TIBDataBaseErrorMessages;
  428. begin
  429.   usr_msg := '';
  430.  
  431.   { Get a local reference to the status vector.
  432.     Get a local copy of the IBDataBaseErrorMessages options.
  433.     Get the SQL error code }
  434.   status_vector := StatusVector;
  435.   IBErrorCode := StatusVectorArray[1];
  436.   IBDataBaseErrorMessages := GetIBDataBaseErrorMessages;
  437.   sqlcode := isc_sqlcode(status_vector);
  438.  
  439.   if (ShowSQLCode in IBDataBaseErrorMessages) then
  440.     usr_msg := usr_msg + 'SQLCODE: ' + IntToStr(sqlcode); {do not localize}
  441.   Exclude(IBDataBaseErrorMessages, ShowSQLMessage);
  442.   if (ShowSQLMessage in IBDataBaseErrorMessages) then
  443.   begin
  444.     isc_sql_interprete(sqlcode, local_buffer, IBLocalBufferLength);
  445.     if (ShowSQLCode in IBDataBaseErrorMessages) then
  446.       usr_msg := usr_msg + CRLF;
  447.     usr_msg := usr_msg + string(local_buffer);
  448.   end;
  449.  
  450.   if (ShowIBMessage in IBDataBaseErrorMessages) then
  451.   begin
  452.     if (ShowSQLCode in IBDataBaseErrorMessages) or
  453.        (ShowSQLMessage in IBDataBaseErrorMessages) then
  454.       usr_msg := usr_msg + CRLF;
  455.     while (isc_interprete(local_buffer, @status_vector) > 0) do
  456.     begin
  457.       if (usr_msg <> '') and (usr_msg[Length(usr_msg)] <> LF) then
  458.         usr_msg := usr_msg + CRLF;
  459.       usr_msg := usr_msg + string(local_buffer);
  460.     end;
  461.   end;
  462.   if (usr_msg <> '') and (usr_msg[Length(usr_msg)] = '.') then
  463.     Delete(usr_msg, Length(usr_msg), 1);
  464.   raise EIBInterBaseError.Create(sqlcode, IBErrorCode, usr_msg);
  465. end;
  466.  
  467. procedure InitializeIBTLGlobals;
  468. var
  469.   TLGlobals: PIBTLGlobals;
  470. begin
  471.   TLGlobals := nil;
  472.   if TlsGetValue(hIBTLGlobals) <> nil then exit;
  473.   IBAlloc(TLGlobals, 0, SizeOf(TIBTLGlobals));
  474.   TlsSetValue(hIBTLGlobals, Pointer(TLGlobals));
  475. end;
  476.  
  477. procedure FreeIBTLGlobals;
  478. var
  479.   TLGlobals: PIBTLGlobals;
  480. begin
  481.   TLGlobals := PIBTLGlobals(TlsGetValue(hIBTLGlobals));
  482.   if TLGlobals <> nil then
  483.   begin
  484.     IBAlloc(TLGlobals, 0, 0);
  485.     TlsSetValue(hIBTLGlobals, nil);
  486.   end;
  487. end;
  488.  
  489. { Return the status vector for the current thread }
  490. function StatusVector: PISC_STATUS;
  491. var
  492.   TLGlobals: PIBTLGlobals;
  493. begin
  494.   TLGlobals := PIBTLGlobals(TlsGetValue(hIBTLGlobals));
  495.   if TLGlobals = nil then
  496.   begin
  497.     InitializeIBTLGlobals;
  498.     TLGlobals := PIBTLGlobals(TlsGetValue(hIBTLGlobals));
  499.   end;
  500.   result := @(TLGlobals^.FStatusVector);
  501. end;
  502.  
  503. function StatusVectorArray: PStatusVector;
  504. var
  505.   TLGlobals: PIBTLGlobals;
  506. begin
  507.   TLGlobals := PIBTLGlobals(TlsGetValue(hIBTLGlobals));
  508.   if TLGlobals = nil then
  509.   begin
  510.     InitializeIBTLGlobals;
  511.     TLGlobals := PIBTLGlobals(TlsGetValue(hIBTLGlobals));
  512.   end;
  513.   result := @(TLGlobals^.FStatusVector);
  514. end;
  515.  
  516. function CheckStatusVector(ErrorCodes: array of ISC_STATUS): Boolean;
  517. var
  518.   p: PISC_STATUS;
  519.   i: Integer;
  520.   procedure NextP(i: Integer);
  521.   begin
  522.     p := PISC_STATUS(PChar(p) + (i * SizeOf(ISC_STATUS)));
  523.   end;
  524. begin
  525.   p := StatusVector;
  526.   result := False;
  527.   while (p^ <> 0) and (not result) do
  528.     case p^ of
  529.       3: NextP(3);
  530.       1, 4:
  531.       begin
  532.         NextP(1);
  533.         i := 0;
  534.         while (i <= High(ErrorCodes)) and (not result) do
  535.         begin
  536.           result := p^ = ErrorCodes[i];
  537.           Inc(i);
  538.         end;
  539.         NextP(1);
  540.       end;
  541.       else
  542.         NextP(2);
  543.     end;
  544. end;
  545.  
  546. function StatusVectorAsText: string;
  547. var
  548.   p: PISC_STATUS;
  549.   function NextP(i: Integer): PISC_STATUS;
  550.   begin
  551.     p := PISC_STATUS(PChar(p) + (i * SizeOf(ISC_STATUS)));
  552.     result := p;
  553.   end;
  554. begin
  555.   p := StatusVector;
  556.   result := '';
  557.   while (p^ <> 0) do
  558.     if (p^ = 3) then
  559.     begin
  560.       result := result + Format('%d %d %d', [p^, NextP(1)^, NextP(1)^]) + CRLF;
  561.       NextP(1);
  562.     end
  563.     else begin
  564.       result := result + Format('%d %d', [p^, NextP(1)^]) + CRLF;
  565.       NextP(1);
  566.     end;
  567. end;
  568.  
  569.  
  570. { EIBError }
  571. constructor EIBError.Create(ASQLCode: Long; Msg: string);
  572. begin
  573.   inherited Create(Msg);
  574.   FSQLCode := ASQLCode;
  575. end;
  576.  
  577. constructor EIBError.Create(ASQLCode: Long; AIBErrorCode: Long; Msg: string);
  578. begin
  579.      inherited Create(Msg);
  580.      FSQLCode :=  ASQLCode;
  581.      FIBErrorCode := AIBErrorCode;
  582. end;
  583.  
  584. procedure SetIBDataBaseErrorMessages(Value: TIBDataBaseErrorMessages);
  585. begin
  586.   EnterCriticalSection(IBCS);
  587.   try
  588.     IBDataBaseErrorMessages := Value;
  589.   finally
  590.     LeaveCriticalSection(IBCS);
  591.   end;
  592. end;
  593.  
  594. function GetIBDataBaseErrorMessages: TIBDataBaseErrorMessages;
  595. begin
  596.   EnterCriticalSection(IBCS);
  597.   try
  598.     result := IBDataBaseErrorMessages;
  599.   finally
  600.     LeaveCriticalSection(IBCS);
  601.   end;
  602. end;
  603.  
  604. initialization
  605.   IsMultiThread := True;
  606.   InitializeCriticalSection(IBCS);
  607.   hIBTLGlobals := TlsAlloc;
  608.   IBDataBaseErrorMessages := [ShowSQLMessage, ShowIBMessage];
  609.  
  610. finalization
  611.  
  612.   FreeIBTLGlobals;
  613.   TlsFree(hIBTLGlobals);
  614.   DeleteCriticalSection(IBCS);
  615.  
  616. end.
  617.