Browse Source

* Revert rev r33905, started from too old version

git-svn-id: trunk@33912 -
michael 9 years ago
parent
commit
ef7c327c7a
1 changed files with 60 additions and 80 deletions
  1. 60 80
      packages/fcl-db/src/sqldb/interbase/fbadmin.pp

+ 60 - 80
packages/fcl-db/src/sqldb/interbase/fbadmin.pp

@@ -1,4 +1,4 @@
-unit fbadmin;
+unit FBAdmin;
 
 
 { Interbase/Firebird Administration using the service manager
 { Interbase/Firebird Administration using the service manager
 
 
@@ -47,14 +47,17 @@ uses
 
 
 type
 type
   TIBBackupOption=(IBBkpVerbose,IBBkpIgnoreChecksums,IBBkpIgnoreLimbo,IBBkpMetadataOnly,
   TIBBackupOption=(IBBkpVerbose,IBBkpIgnoreChecksums,IBBkpIgnoreLimbo,IBBkpMetadataOnly,
-     IBBkpNoGarbageCollect,IBBkpOldDescriptions,IBBkpNonTransportable,IBBkpConvert,IBBkpWait);
+     IBBkpNoGarbageCollect,IBBkpOldDescriptions,IBBkpNonTransportable,IBBkpConvert);
   TIBBackupOptions= set of TIBBackupOption;
   TIBBackupOptions= set of TIBBackupOption;
   TIBRestoreOption=(IBResVerbose,IBResDeactivateIdx,IBResNoShadow,IBResNoValidity,
   TIBRestoreOption=(IBResVerbose,IBResDeactivateIdx,IBResNoShadow,IBResNoValidity,
-     IBResOneAtaTime,IBResReplace,IBResCreate,IBResUseAllSpace,IBResAMReadOnly,
-     IBResAMReadWrite, IBResWait);
+     IBResOneAtaTime,IBResReplace,IBResCreate,IBResUseAllSpace,IBResAMReadOnly,IBResAMReadWrite,
+     IBFixFssData, IBFixFssMeta);
   TIBRestoreOptions= set of TIBRestoreOption;
   TIBRestoreOptions= set of TIBRestoreOption;
   TServiceProtocol=(IBSPLOCAL,IBSPTCPIP,IBSPNETBEUI,IBSPNAMEDPIPE);
   TServiceProtocol=(IBSPLOCAL,IBSPTCPIP,IBSPNETBEUI,IBSPNAMEDPIPE);
   TIBOnOutput= procedure(Sender: TObject; msg: string; IBAdminAction: string) of object;
   TIBOnOutput= procedure(Sender: TObject; msg: string; IBAdminAction: string) of object;
+  TIBStatOption = (IBDataPages, IBDbLog, IBHeaderPages, IBIndexPages, IBSystemRelations,
+    IBRecordVersions, IBStatTables);
+  TIBStatOptions = set of TIBStatOption;
 
 
   { TFBAdmin }
   { TFBAdmin }
 
 
@@ -62,6 +65,7 @@ type
   private
   private
     FErrorCode: longint;
     FErrorCode: longint;
     FErrorMsg: string;
     FErrorMsg: string;
+    FFixFssDataCharSet: String;
     FHost: string;
     FHost: string;
     FOnOutput: TIBOnOutput;
     FOnOutput: TIBOnOutput;
     FOutput: TStringList;
     FOutput: TStringList;
@@ -78,7 +82,6 @@ type
     FSvcHandle: isc_svc_handle;
     FSvcHandle: isc_svc_handle;
     FUseExceptions: boolean;
     FUseExceptions: boolean;
     FUser: string;
     FUser: string;
-    FWaitInterval: Integer;
     function CheckConnected(ProcName: string):boolean;
     function CheckConnected(ProcName: string):boolean;
     procedure CheckError(ProcName : string; Status : PISC_STATUS);
     procedure CheckError(ProcName : string; Status : PISC_STATUS);
     function GetDBInfo:boolean;
     function GetDBInfo:boolean;
@@ -91,6 +94,7 @@ type
     function IBSPBParamSerialize(isccode:byte;value:longint):string;
     function IBSPBParamSerialize(isccode:byte;value:longint):string;
     function MakeBackupOptions(options:TIBBackupOptions):longint;
     function MakeBackupOptions(options:TIBBackupOptions):longint;
     function MakeRestoreOptions(options:TIBRestoreOptions):longint;
     function MakeRestoreOptions(options:TIBRestoreOptions):longint;
+
   public
   public
     constructor Create(AOwner: TComponent); override;
     constructor Create(AOwner: TComponent); override;
     destructor Destroy; override;
     destructor Destroy; override;
@@ -136,12 +140,8 @@ type
     function GetUsers(Users:TStrings):boolean;
     function GetUsers(Users:TStrings):boolean;
     //Get database server log file
     //Get database server log file
     function GetDatabaseLog:boolean;
     function GetDatabaseLog:boolean;
-    // For Backup, Restore this will check if the service call is still running.
-    function ServiceRunning: Boolean;
-    // Wait till the service stops running, or until aTimeout (in milliseconds) is reached.
-    // Return true if the service stopped, false if timeout reached.
-    // WaitInterval is the interval (in milliseconds) between ServiceRunning calls.
-    function WaitForServiceCompletion(aTimeOut: Integer): Boolean;
+    //Get database statistics
+    function GetDatabaseStats(Database:string;Options:TIBStatOptions;TableNames:String = ''): boolean;
     //Database server version
     //Database server version
     property ServerVersion:string read FServerVersion;
     property ServerVersion:string read FServerVersion;
     //Implementation string of the database server
     //Implementation string of the database server
@@ -154,6 +154,8 @@ type
     property ServerMsgDir:string read FServerMsgDir;
     property ServerMsgDir:string read FServerMsgDir;
     //Path to the security database in use by the server
     //Path to the security database in use by the server
     property ServerSecDBDir:string read FServerSecDBDir;
     property ServerSecDBDir:string read FServerSecDBDir;
+    // FixFxxData/FixFxxMetaData code page
+    property FixFssDataCharSet: String read FFixFssDataCharSet write FFixFssDataCharSet;
   published
   published
     //User name to connect to service manager
     //User name to connect to service manager
     property User: string read FUser write FUser;
     property User: string read FUser write FUser;
@@ -181,15 +183,11 @@ type
     //Event handler for Service output messages
     //Event handler for Service output messages
     //Used in Backup and Restore operations and GetLog
     //Used in Backup and Restore operations and GetLog
     property OnOutput: TIBOnOutput read FOnOutput write FOnOutput;
     property OnOutput: TIBOnOutput read FOnOutput write FOnOutput;
-    // Interval (in milliseconds) to sleep while waiting for the service operation to end.
-    Property WaitInterval : Integer Read FWaitInterval Write FWaitInterval;
   end;
   end;
 
 
 
 
 implementation
 implementation
 
 
-uses dateutils;
-
 resourcestring
 resourcestring
   SErrNotConnected = '%s : %s : Not connected.';
   SErrNotConnected = '%s : %s : Not connected.';
   SErrError = '%s : %s : %s';
   SErrError = '%s : %s : %s';
@@ -209,17 +207,11 @@ end;
 
 
 procedure TFBAdmin.IBRaiseError(GDSErrorCode: Longint; const msg: string;
 procedure TFBAdmin.IBRaiseError(GDSErrorCode: Longint; const msg: string;
   const args: array of const);
   const args: array of const);
-var
-  E:EIBDatabaseError;
 begin
 begin
-  FErrorMsg:=format(msg,args);
+  FErrorMsg:=Format(msg,args);
   FErrorCode:=GDSErrorCode;
   FErrorCode:=GDSErrorCode;
   if FUseExceptions then
   if FUseExceptions then
-    begin
-    E := EIBDatabaseError.Create(FErrorMsg);
-    E.GDSErrorCode := GDSErrorCode;
-    Raise E;
-    end;
+    raise EIBDatabaseError.CreateFmt(msg,args,nil,GDSErrorCode,'');
 end;
 end;
 
 
 function TFBAdmin.IBSPBParamSerialize(isccode: byte; value: string): string;
 function TFBAdmin.IBSPBParamSerialize(isccode: byte; value: string): string;
@@ -385,7 +377,7 @@ begin
   inherited Create(AOwner);
   inherited Create(AOwner);
   FPort:= 3050;
   FPort:= 3050;
   FOutput:=TStringList.Create;
   FOutput:=TStringList.Create;
-  WaitInterval:=100;
+  FFixFssDataCharSet:= '';
 end;
 end;
 
 
 destructor TFBAdmin.Destroy;
 destructor TFBAdmin.Destroy;
@@ -398,7 +390,6 @@ end;
 
 
 function TFBAdmin.Connect: boolean;
 function TFBAdmin.Connect: boolean;
 var
 var
-  E:EIBDatabaseError;
   Service:string;
   Service:string;
   spb:string;
   spb:string;
 begin
 begin
@@ -407,11 +398,7 @@ begin
   result:=InitialiseIBase60<>0;
   result:=InitialiseIBase60<>0;
   {$EndIf}
   {$EndIf}
   if FSvcHandle<>FB_API_NULLHANDLE then
   if FSvcHandle<>FB_API_NULLHANDLE then
-    begin
-    E := EIBDatabaseError.CreateFmt(SErrConnected,[self.Name]);
-    E.GDSErrorCode := 0;
-    Raise E;
-    end;
+    raise EIBDatabaseError.CreateFmt(SErrConnected,[Self.Name],nil,0,'');
   Service:='service_mgr';
   Service:='service_mgr';
   case FProtocol of
   case FProtocol of
     IBSPTCPIP:if FPort=3050 then
     IBSPTCPIP:if FPort=3050 then
@@ -467,9 +454,7 @@ begin
     exit;
     exit;
     end;
     end;
   if IBBkpVerbose in Options then
   if IBBkpVerbose in Options then
-    result:=GetOutput('Backup')
-  else if (IBBkpWait in Options) then
-    WaitForServiceCompletion(0);
+    result:=GetOutput('Backup');
 end;
 end;
 
 
 function TFBAdmin.BackupMultiFile(Database: string; Filenames: TStrings;
 function TFBAdmin.BackupMultiFile(Database: string; Filenames: TStrings;
@@ -498,52 +483,9 @@ begin
     exit;
     exit;
     end;
     end;
   if IBBkpVerbose in Options then
   if IBBkpVerbose in Options then
-    result:=GetOutput('BackupMultiFile')
-  else if (IBBkpWait in Options) then
-    WaitForServiceCompletion(0);
+    result:=GetOutput('BackupMultiFile');
 end;
 end;
 
 
-Function TFBAdmin.ServiceRunning : Boolean;
-
-const
-  BUFFERSIZE=1000;
-
-var
-  res:integer;
-  buffer: string;
-  spb:string;
-
-begin
-  FOutput.Clear;
-  spb:=chr(isc_info_svc_running);
-  setlength(buffer,BUFFERSIZE);
-  result:=isc_service_query(@FStatus[0], @FSvcHandle, nil, 0, nil, length(spb),
-          @spb[1],BUFFERSIZE,@buffer[1])=0;
-  if Not Result then
-    CheckError('ServiceRunning',FSTatus);
-  if (Buffer[1]=Char(isc_info_svc_running)) then
-    begin
-    res:=isc_vax_integer(@Buffer[2],4);
-    Result:=res=1;
-    end
-  else
-    IBRaiseError(0,'%s: Service status detection returned wrong result',[self.Name]);
-end;
-
-Function TFBAdmin.WaitForServiceCompletion(aTimeOut : Integer) : Boolean;
-
-Var
-  N : TDateTime;
-
-begin
-  N:=Now;
-  Repeat
-    Sleep(WaitInterval);
-    Result:=not ServiceRunning;
-  until Result or ((aTimeOut<>0) and (MilliSecondsBetween(Now,N)>aTimeOut*WaitInterval));
-end;
-
-
 function TFBAdmin.Restore(Database, Filename: string;
 function TFBAdmin.Restore(Database, Filename: string;
   Options: TIBRestoreOptions; RoleName: string): boolean;
   Options: TIBRestoreOptions; RoleName: string): boolean;
 var
 var
@@ -569,6 +511,10 @@ begin
     else
     else
       spb:=spb+chr(isc_spb_res_access_mode)+chr(isc_spb_res_am_readwrite);
       spb:=spb+chr(isc_spb_res_access_mode)+chr(isc_spb_res_am_readwrite);
     end;
     end;
+  if (IBFixFssData in Options) and (FixFssDataCharSet > ' ') then
+    spb:=spb+IBSPBParamSerialize(isc_spb_res_fix_fss_data, FixFssDataCharSet);
+  if (IBFixFssMeta in Options) and (FixFssDataCharSet > ' ') then
+    spb:=spb+IBSPBParamSerialize(isc_spb_res_fix_fss_metadata, FixFssDataCharSet);
   spb:=spb+IBSPBParamSerialize(isc_spb_options,MakeRestoreOptions(Options));
   spb:=spb+IBSPBParamSerialize(isc_spb_options,MakeRestoreOptions(Options));
   result:=isc_service_start(@FStatus[0], @FSvcHandle, nil, length(spb),
   result:=isc_service_start(@FStatus[0], @FSvcHandle, nil, length(spb),
     @spb[1])=0;
     @spb[1])=0;
@@ -578,9 +524,7 @@ begin
     exit;
     exit;
     end;
     end;
   if IBResVerbose in Options then
   if IBResVerbose in Options then
-    result:=GetOutput('Restore')
-  else if IBResWait in Options then
-    WaitForServiceCompletion(0);
+    result:=GetOutput('Restore');
 end;
 end;
 
 
 
 
@@ -822,5 +766,41 @@ begin
   result:=GetOutput('GetLogFile');
   result:=GetOutput('GetLogFile');
 end;
 end;
 
 
+function TFBAdmin.GetDatabaseStats(Database:string;Options: TIBStatOptions; TableNames: String
+  ): boolean;
+var
+  spb:string;
+  param: Integer;
+begin
+  Result:=CheckConnected('GetDatabaseStats');
+  param := 0;
+  if (IBDataPages in Options) then
+    param := param or isc_spb_sts_data_pages;
+  if (IBDbLog in Options) then
+    param := param or isc_spb_sts_db_log;
+  if (IBHeaderPages in Options) then
+    param := param or isc_spb_sts_hdr_pages;
+  if (IBIndexPages in Options) then
+    param := param or isc_spb_sts_idx_pages;
+  if (IBSystemRelations in Options) then
+    param := param or isc_spb_sts_sys_relations;
+  if (IBRecordVersions in Options) then
+    param := param or isc_spb_sts_record_versions;
+  if (IBStatTables in Options) then
+    param := param or isc_spb_sts_table;
+  spb  := Char(isc_action_svc_db_stats)+IBSPBParamSerialize(isc_spb_dbname,Database)+
+    IBSPBParamSerialize(isc_spb_options, param);
+  if (IBStatTables in Options) and (TableNames <> '') then
+    spb := spb+IBSPBParamSerialize(isc_spb_command_line, TableNames);
+  Result:=isc_service_start(@FStatus[0], @FSvcHandle, nil, length(spb),
+    @spb[1])=0;
+  if not Result then
+    begin
+    CheckError('GetDatabaseStats',FStatus);
+    exit;
+    end;
+  Result:=GetOutput('GetDatabaseStats');
+end;
+
 end.
 end.