mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-15 23:49:22 +02:00
fcl-db: reverts rev.29118, because there are 3rd party libraries (like ZEOS), which define own EDatabaseError descendants, where they define members FErrorCode and/or ErrorCode.
This patch also fixes bugs #27078 and #26684, what was intention of rev.29118 git-svn-id: trunk@29163 -
This commit is contained in:
parent
3670828f3b
commit
eaadd51b42
@ -2355,7 +2355,7 @@ var r : Integer;
|
|||||||
FailedCount : integer;
|
FailedCount : integer;
|
||||||
Response : TResolverResponse;
|
Response : TResolverResponse;
|
||||||
StoreCurrRec : TBufBookmark;
|
StoreCurrRec : TBufBookmark;
|
||||||
AUpdateErr : EUpdateError;
|
AUpdateError : EUpdateError;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
CheckBrowseMode;
|
CheckBrowseMode;
|
||||||
@ -2382,18 +2382,23 @@ begin
|
|||||||
on E: EDatabaseError do
|
on E: EDatabaseError do
|
||||||
begin
|
begin
|
||||||
Inc(FailedCount);
|
Inc(FailedCount);
|
||||||
if FailedCount > word(MaxErrors) then Response := rrAbort
|
if FailedCount > word(MaxErrors) then
|
||||||
else Response := rrSkip;
|
Response := rrAbort
|
||||||
|
else
|
||||||
|
Response := rrSkip;
|
||||||
if assigned(FOnUpdateError) then
|
if assigned(FOnUpdateError) then
|
||||||
begin
|
begin
|
||||||
AUpdateErr := PSGetUpdateException(Exception(AcquireExceptionObject), nil);
|
AUpdateError := PSGetUpdateException(Exception(AcquireExceptionObject), nil);
|
||||||
FOnUpdateError(Self,Self,AUpdateErr,FUpdateBuffer[r].UpdateKind,Response);
|
FOnUpdateError(Self, Self, AUpdateError, FUpdateBuffer[r].UpdateKind, Response);
|
||||||
AUpdateErr.Free;
|
AUpdateError.Free;
|
||||||
if Response in [rrApply, rrIgnore] then dec(FailedCount);
|
if Response in [rrApply, rrIgnore] then dec(FailedCount);
|
||||||
if Response = rrApply then dec(r);
|
if Response = rrApply then dec(r);
|
||||||
end
|
end
|
||||||
else if Response = rrAbort then
|
else if Response = rrAbort then
|
||||||
Raise EUpdateError.Create(SOnUpdateError,E.Message,E.ErrorCode,0,Exception(AcquireExceptionObject));
|
begin
|
||||||
|
AUpdateError := PSGetUpdateException(Exception(AcquireExceptionObject), nil);
|
||||||
|
raise AUpdateError;
|
||||||
|
end;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
raise;
|
raise;
|
||||||
|
@ -78,18 +78,12 @@ type
|
|||||||
|
|
||||||
{ Exception classes }
|
{ Exception classes }
|
||||||
|
|
||||||
{ EDatabaseError }
|
EDatabaseError = class(Exception);
|
||||||
|
|
||||||
EDatabaseError = class(Exception)
|
|
||||||
Protected
|
|
||||||
FErrorCode: integer;
|
|
||||||
Public
|
|
||||||
Property ErrorCode: integer Read FErrorCode;
|
|
||||||
end;
|
|
||||||
|
|
||||||
EUpdateError = class(EDatabaseError)
|
EUpdateError = class(EDatabaseError)
|
||||||
private
|
private
|
||||||
FContext : String;
|
FContext : String;
|
||||||
|
FErrorCode : integer;
|
||||||
FOriginalException : Exception;
|
FOriginalException : Exception;
|
||||||
FPreviousError : Integer;
|
FPreviousError : Integer;
|
||||||
public
|
public
|
||||||
@ -97,6 +91,7 @@ type
|
|||||||
ErrCode, PrevError : integer; E: Exception);
|
ErrCode, PrevError : integer; E: Exception);
|
||||||
Destructor Destroy; override;
|
Destructor Destroy; override;
|
||||||
property Context : String read FContext;
|
property Context : String read FContext;
|
||||||
|
property ErrorCode : integer read FErrorcode;
|
||||||
property OriginalException : Exception read FOriginalException;
|
property OriginalException : Exception read FOriginalException;
|
||||||
property PreviousError : Integer read FPreviousError;
|
property PreviousError : Integer read FPreviousError;
|
||||||
end;
|
end;
|
||||||
|
@ -27,8 +27,8 @@ type
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
EIBDatabaseError = class(ESQLDatabaseError)
|
EIBDatabaseError = class(ESQLDatabaseError)
|
||||||
public
|
public
|
||||||
property GDSErrorCode: integer read FErrorCode Write FErrorCode;
|
property GDSErrorCode: integer read ErrorCode; deprecated 'Please use ErrorCode instead of GDSErrorCode'; // Nov 2014
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TIBCursor }
|
{ TIBCursor }
|
||||||
@ -152,20 +152,26 @@ const
|
|||||||
|
|
||||||
procedure TIBConnection.CheckError(ProcName : string; Status : PISC_STATUS);
|
procedure TIBConnection.CheckError(ProcName : string; Status : PISC_STATUS);
|
||||||
var
|
var
|
||||||
buf : array [0..1023] of char;
|
|
||||||
Msg : string;
|
|
||||||
E : EIBDatabaseError;
|
|
||||||
Err : longint;
|
Err : longint;
|
||||||
|
Msg : string;
|
||||||
|
Buf : array [0..1023] of char;
|
||||||
|
E : EIBDatabaseError;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
if ((Status[0] = 1) and (Status[1] <> 0)) then
|
if ((Status[0] = 1) and (Status[1] <> 0)) then
|
||||||
begin
|
begin
|
||||||
Err := Status[1];
|
Err := Status[1];
|
||||||
msg := '';
|
Msg := '';
|
||||||
while isc_interprete(Buf, @Status) > 0 do
|
while isc_interprete(Buf, @Status) > 0 do
|
||||||
Msg := Msg + LineEnding +' -' + StrPas(Buf);
|
Msg := Msg + LineEnding + ' -' + StrPas(Buf);
|
||||||
E := EIBDatabaseError.CreateFmt('%s : %s : %s',[self.Name,ProcName,Msg]);
|
E := EIBDatabaseError.CreateFmt('%s : %s', [ProcName,Msg], Self, Err, '');
|
||||||
E.GDSErrorCode := Err;
|
{$IFDEF LinkDynamically}
|
||||||
|
if assigned(fb_sqlstate) then // >= Firebird 2.5
|
||||||
|
begin
|
||||||
|
fb_sqlstate(Buf, Status);
|
||||||
|
E.SQLState := StrPas(Buf);
|
||||||
|
end;
|
||||||
|
{$ENDIF}
|
||||||
Raise E;
|
Raise E;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
@ -140,7 +140,7 @@ type
|
|||||||
|
|
||||||
EMSSQLDatabaseError = class(ESQLDatabaseError)
|
EMSSQLDatabaseError = class(ESQLDatabaseError)
|
||||||
public
|
public
|
||||||
property DBErrorCode: integer read FErrorCode; deprecated 'Please use ErrorCode instead of DBErrorCode'; // Feb 2014
|
property DBErrorCode: integer read ErrorCode; deprecated 'Please use ErrorCode instead of DBErrorCode'; // Feb 2014
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TMSSQLConnectionDef }
|
{ TMSSQLConnectionDef }
|
||||||
@ -298,13 +298,13 @@ var E: EMSSQLDatabaseError;
|
|||||||
begin
|
begin
|
||||||
if (Ret=FAIL) or (DBErrorStr<>'') then
|
if (Ret=FAIL) or (DBErrorStr<>'') then
|
||||||
begin
|
begin
|
||||||
|
// try clear all pending results to allow ROLLBACK and prevent error 10038 "Results pending"
|
||||||
|
if assigned(FDBProc) then dbcancel(FDBProc);
|
||||||
if DBErrorStr = '' then
|
if DBErrorStr = '' then
|
||||||
case DBErrorNo of
|
case DBErrorNo of
|
||||||
SYBEFCON: DBErrorStr:='SQL Server connection failed!';
|
SYBEFCON: DBErrorStr:='SQL Server connection failed!';
|
||||||
end;
|
end;
|
||||||
E:=EMSSQLDatabaseError.CreateFmt('Error %d : %s'+LineEnding+'%s', [DBErrorNo, DBErrorStr, DBMsgStr], Self, DBErrorNo, '');
|
E:=EMSSQLDatabaseError.CreateFmt('Error %d : %s'+LineEnding+'%s', [DBErrorNo, DBErrorStr, DBMsgStr], Self, DBErrorNo, '');
|
||||||
// try clear all pending results to allow ROLLBACK and prevent error 10038 "Results pending"
|
|
||||||
if assigned(FDBProc) then dbcancel(FDBProc);
|
|
||||||
DBErrorStr:='';
|
DBErrorStr:='';
|
||||||
DBMsgStr:='';
|
DBMsgStr:='';
|
||||||
raise E;
|
raise E;
|
||||||
|
@ -31,7 +31,7 @@ const
|
|||||||
type
|
type
|
||||||
EOraDatabaseError = class(ESQLDatabaseError)
|
EOraDatabaseError = class(ESQLDatabaseError)
|
||||||
public
|
public
|
||||||
property ORAErrorCode: integer read FErrorCode; deprecated 'Please use ErrorCode instead of ORAErrorCode'; // June 2014
|
property ORAErrorCode: integer read ErrorCode; deprecated 'Please use ErrorCode instead of ORAErrorCode'; // June 2014
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TOracleTrans = Class(TSQLHandle)
|
TOracleTrans = Class(TSQLHandle)
|
||||||
@ -332,13 +332,13 @@ end;
|
|||||||
|
|
||||||
procedure TOracleConnection.HandleError;
|
procedure TOracleConnection.HandleError;
|
||||||
|
|
||||||
var
|
var errcode : sb4;
|
||||||
errcode : sb4;
|
buf : array[0..1023] of char;
|
||||||
buf : array[0..1023] of char;
|
E : EOraDatabaseError;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
OCIErrorGet(FOciError,1,nil,errcode,@buf[0],1024,OCI_HTYPE_ERROR);
|
OCIErrorGet(FOciError,1,nil,errcode,@buf[0],1024,OCI_HTYPE_ERROR);
|
||||||
Raise EOraDatabaseError.Create(pchar(buf),Self,ErrCode,'');;
|
|
||||||
|
raise EOraDatabaseError.CreateFmt('%s', [pchar(buf)], Self, errcode, '')
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TOracleConnection.GetParameters(cursor: TSQLCursor; ATransaction : TSQLTransaction; AParams: TParams);
|
procedure TOracleConnection.GetParameters(cursor: TSQLCursor; ATransaction : TSQLTransaction; AParams: TParams);
|
||||||
|
@ -70,13 +70,11 @@ type
|
|||||||
{ ESQLDatabaseError}
|
{ ESQLDatabaseError}
|
||||||
|
|
||||||
ESQLDatabaseError = class(EDatabaseError)
|
ESQLDatabaseError = class(EDatabaseError)
|
||||||
Private
|
|
||||||
Function GetNamePrefix (comp : TComponent; Fmt: String) :String;
|
|
||||||
public
|
public
|
||||||
|
ErrorCode: integer;
|
||||||
SQLState : string;
|
SQLState : string;
|
||||||
constructor CreateFmt(const Fmt: string; const Args: array of const;
|
constructor CreateFmt(const Fmt: string; const Args: array of const;
|
||||||
Comp : TComponent; AErrorCode: integer; ASQLState: string); overload;
|
Comp : TComponent; AErrorCode: integer; ASQLState: string); overload;
|
||||||
constructor Create(AMessage: string; Comp : TComponent; AErrorCode: integer; ASQLState: string); overload;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TSQLDBFieldDef }
|
{ TSQLDBFieldDef }
|
||||||
@ -747,36 +745,20 @@ end;
|
|||||||
|
|
||||||
{ ESQLDatabaseError }
|
{ ESQLDatabaseError }
|
||||||
|
|
||||||
Function ESQLDatabaseError.GetNamePrefix(comp: TComponent; Fmt: String): String;
|
|
||||||
|
|
||||||
const
|
|
||||||
CompNameFmt='%s : %s';
|
|
||||||
|
|
||||||
begin
|
|
||||||
if not assigned(Comp) then
|
|
||||||
Result := Fmt
|
|
||||||
else if Comp.Name = '' then
|
|
||||||
Result := Format(CompNameFmt, [Comp.ClassName,Fmt])
|
|
||||||
else
|
|
||||||
Result := Format(CompNameFmt, [Comp.Name,Fmt]);
|
|
||||||
end;
|
|
||||||
|
|
||||||
constructor ESQLDatabaseError.CreateFmt(const Fmt: string; const Args: array of const;
|
constructor ESQLDatabaseError.CreateFmt(const Fmt: string; const Args: array of const;
|
||||||
Comp: TComponent; AErrorCode: integer; ASQLState: string);
|
Comp: TComponent; AErrorCode: integer; ASQLState: string);
|
||||||
|
const CompNameFmt='%s : %s';
|
||||||
var Msg: string;
|
var Msg: string;
|
||||||
begin
|
begin
|
||||||
Msg:=GetNamePrefix(Comp,Fmt);
|
if not assigned(Comp) then
|
||||||
inherited CreateFmt(Msg, Args);
|
Msg := Fmt
|
||||||
FErrorCode := AErrorCode;
|
else if Comp.Name = '' then
|
||||||
SQLState := ASQLState;
|
Msg := Format(CompNameFmt, [Comp.ClassName,Fmt])
|
||||||
end;
|
else
|
||||||
|
Msg := Format(CompNameFmt, [Comp.Name,Fmt]);
|
||||||
|
|
||||||
constructor ESQLDatabaseError.Create(AMessage: string; Comp: TComponent;
|
inherited CreateFmt(Msg, Args);
|
||||||
AErrorCode: integer; ASQLState: string);
|
ErrorCode := AErrorCode;
|
||||||
begin
|
|
||||||
AMessage:=GetNamePrefix(Comp,AMessage);
|
|
||||||
inherited Create(AMessage);
|
|
||||||
FErrorCode := AErrorCode;
|
|
||||||
SQLState := ASQLState;
|
SQLState := ASQLState;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user