浏览代码

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

git-svn-id: trunk@29118 -
michael 10 年之前
父节点
当前提交
2134e3aaac

+ 1 - 1
packages/fcl-db/src/base/bufdataset.pas

@@ -2393,7 +2393,7 @@ begin
               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,0,0,Exception(AcquireExceptionObject));
+              Raise EUpdateError.Create(SOnUpdateError,E.Message,E.ErrorCode,0,Exception(AcquireExceptionObject));
             end
             end
           else
           else
             raise;
             raise;

+ 9 - 3
packages/fcl-db/src/base/db.pas

@@ -78,11 +78,18 @@ type
 
 
 { Exception classes }
 { Exception classes }
 
 
-  EDatabaseError = class(Exception);
+  { EDatabaseError }
+
+  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
@@ -90,7 +97,6 @@ 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;

+ 3 - 3
packages/fcl-db/src/sqldb/interbase/ibconnection.pp

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

+ 1 - 1
packages/fcl-db/src/sqldb/mssql/mssqlconn.pp

@@ -140,7 +140,7 @@ type
 
 
   EMSSQLDatabaseError = class(ESQLDatabaseError)
   EMSSQLDatabaseError = class(ESQLDatabaseError)
     public
     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;
   end;
 
 
   { TMSSQLConnectionDef }
   { TMSSQLConnectionDef }

+ 6 - 12
packages/fcl-db/src/sqldb/oracle/oracleconnection.pp

@@ -31,7 +31,7 @@ const
 type
 type
   EOraDatabaseError = class(ESQLDatabaseError)
   EOraDatabaseError = class(ESQLDatabaseError)
     public
     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;
   end;
 
 
   TOracleTrans = Class(TSQLHandle)
   TOracleTrans = Class(TSQLHandle)
@@ -332,19 +332,13 @@ end;
 
 
 procedure TOracleConnection.HandleError;
 procedure TOracleConnection.HandleError;
 
 
-var errcode : sb4;
-    buf     : array[0..1023] of char;
-    E       : EOraDatabaseError;
+var
+  errcode : sb4;
+  buf     : array[0..1023] of char;
+
 begin
 begin
   OCIErrorGet(FOciError,1,nil,errcode,@buf[0],1024,OCI_HTYPE_ERROR);
   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;
 end;
 
 
 procedure TOracleConnection.GetParameters(cursor: TSQLCursor; ATransaction : TSQLTransaction; AParams: TParams);
 procedure TOracleConnection.GetParameters(cursor: TSQLCursor; ATransaction : TSQLTransaction; AParams: TParams);

+ 27 - 9
packages/fcl-db/src/sqldb/sqldb.pp

@@ -80,11 +80,13 @@ 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 }
@@ -741,20 +743,36 @@ end;
 
 
 { ESQLDatabaseError }
 { 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
 begin
   if not assigned(Comp) then
   if not assigned(Comp) then
-    Msg := Fmt
+    Result := Fmt
   else if Comp.Name = '' then
   else if Comp.Name = '' then
-    Msg := Format(CompNameFmt, [Comp.ClassName,Fmt])
+    Result := Format(CompNameFmt, [Comp.ClassName,Fmt])
   else
   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);
   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;
   SQLState  := ASQLState;
 end;
 end;