* Promoted errorcode to the EDatabaseError level, unified all error codes

git-svn-id: trunk@29118 -
This commit is contained in:
michael 2014-11-23 12:46:53 +00:00
parent 8808308843
commit 2134e3aaac
6 changed files with 47 additions and 29 deletions

View File

@ -2393,7 +2393,7 @@ begin
if Response = rrApply then dec(r);
end
else if Response = rrAbort then
Raise EUpdateError.Create(SOnUpdateError,E.Message,0,0,Exception(AcquireExceptionObject));
Raise EUpdateError.Create(SOnUpdateError,E.Message,E.ErrorCode,0,Exception(AcquireExceptionObject));
end
else
raise;

View File

@ -78,11 +78,18 @@ type
{ Exception classes }
EDatabaseError = class(Exception);
{ EDatabaseError }
EDatabaseError = class(Exception)
Protected
FErrorCode: integer;
Public
Property ErrorCode: integer Read FErrorCode;
end;
EUpdateError = class(EDatabaseError)
private
FContext : String;
FErrorCode : integer;
FOriginalException : Exception;
FPreviousError : Integer;
public
@ -90,7 +97,6 @@ type
ErrCode, PrevError : integer; E: Exception);
Destructor Destroy; override;
property Context : String read FContext;
property ErrorCode : integer read FErrorcode;
property OriginalException : Exception read FOriginalException;
property PreviousError : Integer read FPreviousError;
end;

View File

@ -26,9 +26,9 @@ type
ServerVersionString : string; //Complete version string, including name, platform
end;
EIBDatabaseError = class(EDatabaseError)
public
GDSErrorCode : Longint;
EIBDatabaseError = class(ESQLDatabaseError)
public
property GDSErrorCode: integer read FErrorCode Write FErrorCode;
end;
{ TIBCursor }

View File

@ -140,7 +140,7 @@ type
EMSSQLDatabaseError = class(ESQLDatabaseError)
public
property DBErrorCode: integer read ErrorCode; deprecated 'Please use ErrorCode instead of DBErrorCode'; // Feb 2014
property DBErrorCode: integer read FErrorCode; deprecated 'Please use ErrorCode instead of DBErrorCode'; // Feb 2014
end;
{ TMSSQLConnectionDef }

View File

@ -31,7 +31,7 @@ const
type
EOraDatabaseError = class(ESQLDatabaseError)
public
property ORAErrorCode: integer read ErrorCode; deprecated 'Please use ErrorCode instead of ORAErrorCode'; // June 2014
property ORAErrorCode: integer read FErrorCode; deprecated 'Please use ErrorCode instead of ORAErrorCode'; // June 2014
end;
TOracleTrans = Class(TSQLHandle)
@ -332,19 +332,13 @@ end;
procedure TOracleConnection.HandleError;
var errcode : sb4;
buf : array[0..1023] of char;
E : EOraDatabaseError;
var
errcode : sb4;
buf : array[0..1023] of char;
begin
OCIErrorGet(FOciError,1,nil,errcode,@buf[0],1024,OCI_HTYPE_ERROR);
if (Self.Name <> '') then
E := EOraDatabaseError.CreateFmt('%s : %s',[Self.Name,pchar(buf)])
else
E := EOraDatabaseError.Create(pchar(buf));
E.ErrorCode := errcode;
Raise E;
Raise EOraDatabaseError.Create(pchar(buf),Self,ErrCode,'');;
end;
procedure TOracleConnection.GetParameters(cursor: TSQLCursor; ATransaction : TSQLTransaction; AParams: TParams);

View File

@ -80,11 +80,13 @@ type
{ ESQLDatabaseError}
ESQLDatabaseError = class(EDatabaseError)
Private
Function GetNamePrefix (comp : TComponent; Fmt: String) :String;
public
ErrorCode: integer;
SQLState : string;
constructor CreateFmt(const Fmt: string; const Args: array of const;
Comp : TComponent; AErrorCode: integer; ASQLState: string); overload;
constructor Create(AMessage: string; Comp : TComponent; AErrorCode: integer; ASQLState: string); overload;
end;
{ TSQLDBFieldDef }
@ -741,20 +743,36 @@ end;
{ ESQLDatabaseError }
constructor ESQLDatabaseError.CreateFmt(const Fmt: string; const Args: array of const;
Comp: TComponent; AErrorCode: integer; ASQLState: string);
const CompNameFmt='%s : %s';
var Msg: string;
Function ESQLDatabaseError.GetNamePrefix(comp: TComponent; Fmt: String): String;
const
CompNameFmt='%s : %s';
begin
if not assigned(Comp) then
Msg := Fmt
Result := Fmt
else if Comp.Name = '' then
Msg := Format(CompNameFmt, [Comp.ClassName,Fmt])
Result := Format(CompNameFmt, [Comp.ClassName,Fmt])
else
Msg := Format(CompNameFmt, [Comp.Name,Fmt]);
Result := Format(CompNameFmt, [Comp.Name,Fmt]);
end;
constructor ESQLDatabaseError.CreateFmt(const Fmt: string; const Args: array of const;
Comp: TComponent; AErrorCode: integer; ASQLState: string);
var Msg: string;
begin
Msg:=GetNamePrefix(Comp,Fmt);
inherited CreateFmt(Msg, Args);
ErrorCode := AErrorCode;
FErrorCode := AErrorCode;
SQLState := ASQLState;
end;
constructor ESQLDatabaseError.Create(AMessage: string; Comp: TComponent;
AErrorCode: integer; ASQLState: string);
begin
AMessage:=GetNamePrefix(Comp,AMessage);
inherited Create(AMessage);
FErrorCode := AErrorCode;
SQLState := ASQLState;
end;