//////////////////////////////////////////////////
//  NexusDB Data Access Components
//  Copyright © 2009-2013 Devart. All right reserved.
//////////////////////////////////////////////////

{$IFNDEF CLR}

{$I NexusDac.inc}
unit NexusErrorUni;
{$ENDIF}

interface

{$IFNDEF DUMMY}
uses
  SysUtils, Classes, {$IFNDEF LITE}DBAccess,{$ENDIF} CRTypes;

type
  ENexusError = class({$IFDEF LITE}Exception{$ELSE}EDAError{EDatabaseError}{$ENDIF})
  private
  {$IFDEF LITE}
    FErrorCode: integer;
  {$ENDIF}

  public
    constructor Create(ErrorCode: integer; ErrorMsg: string);
    destructor Destroy; override;

  {$IFNDEF LITE}
    function IsFatalError: boolean; override;
    function IsKeyViolation: boolean; override;
  {$ENDIF}

  {$IFDEF LITE}
    property ErrorCode: integer read FErrorCode;
  {$ENDIF}
  end;
{$ENDIF} // DUMMY

implementation

{$IFNDEF DUMMY}

{$IFNDEF LITE}
uses
  nxllBde;
{$ENDIF}

{ ENexusError }

constructor ENexusError.Create(ErrorCode: integer; ErrorMsg: string);
begin
{$IFDEF CLR}
  inherited Create({$IFNDEF LITE}ErrorCode, {$ENDIF}ErrorMsg);
{$ELSE}
  inherited
  Message := ErrorMsg;
{$ENDIF}
  FErrorCode := ErrorCode;
end;

destructor ENexusError.Destroy;
begin
  inherited;
end;

{$IFNDEF LITE}
function ENexusError.IsFatalError: boolean;
begin
  Result := FErrorCode = DBIERR_SERVERCOMMLOST;
end;

function ENexusError.IsKeyViolation: boolean;
begin
  Result := FErrorCode = DBIERR_KEYVIOL;
end;
{$ENDIF}

{$ENDIF} // DUMMY

end.
