ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/runtime/IBServices.pas
Revision: 45
Committed: Tue Dec 6 10:33:46 2016 UTC (7 years, 11 months ago) by tony
Content type: text/x-pascal
File size: 59664 byte(s)
Log Message:
Committing updates for Release R2-0-0

File Contents

# User Rev Content
1 tony 33 {************************************************************************}
2     { }
3     { Borland Delphi Visual Component Library }
4     { InterBase Express core components }
5     { }
6     { Copyright (c) 1998-2000 Inprise Corporation }
7     { }
8     { InterBase Express is based in part on the product }
9     { Free IB Components, written by Gregory H. Deatz for }
10     { Hoagland, Longo, Moran, Dunst & Doukas Company. }
11     { Free IB Components is used under license. }
12     { }
13     { The contents of this file are subject to the InterBase }
14     { Public License Version 1.0 (the "License"); you may not }
15     { use this file except in compliance with the License. You }
16     { may obtain a copy of the License at http://www.Inprise.com/IPL.html }
17     { Software distributed under the License is distributed on }
18     { an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either }
19     { express or implied. See the License for the specific language }
20     { governing rights and limitations under the License. }
21     { The Original Code was created by InterBase Software Corporation }
22     { and its successors. }
23     { Portions created by Inprise Corporation are Copyright (C) Inprise }
24     { Corporation. All Rights Reserved. }
25     { Contributor(s): Jeff Overcash }
26     { }
27     { IBX For Lazarus (Firebird Express) }
28     { Contributor: Tony Whyman, MWA Software http://www.mwasoftware.co.uk }
29     { Portions created by MWA Software are copyright McCallum Whyman }
30     { Associates Ltd 2011 }
31     { }
32     {************************************************************************}
33    
34     {
35     InterBase Express provides component interfaces to
36     functions introduced in InterBase 6.0. The Services
37     components (TIB*Service, TIBServerProperties)
38     function only if you have installed InterBase 6.0 or
39     later software, including Firebird
40     }
41    
42     unit IBServices;
43    
44     {$Mode Delphi}
45 tony 39 {$codepage UTF8}
46 tony 33
47     interface
48    
49     uses
50     {$IFDEF WINDOWS }
51     Windows,
52     {$ELSE}
53     unix,
54     {$ENDIF}
55 tony 45 SysUtils, Classes, IBHeader, IB, IBExternals, CustApp, IBTypes, IBSQL;
56 tony 33
57     const
58     DefaultBufferSize = 32000;
59    
60     SPBPrefix = 'isc_spb_';
61 tony 45 isc_spb_last_spb_constant = 12;
62 tony 33 SPBConstantNames: array[1..isc_spb_last_spb_constant] of String = (
63     'user_name',
64     'sys_user_name',
65     'sys_user_name_enc',
66     'password',
67     'password_enc',
68     'command_line',
69     'db_name',
70     'verbose',
71     'options',
72     'connect_timeout',
73     'dummy_packet_interval',
74     'sql_role_name'
75     );
76    
77     SPBConstantValues: array[1..isc_spb_last_spb_constant] of Integer = (
78 tony 45 isc_spb_user_name,
79     isc_spb_sys_user_name,
80     isc_spb_sys_user_name_enc,
81     isc_spb_password,
82     isc_spb_password_enc,
83     isc_spb_command_line,
84     isc_spb_dbname,
85     isc_spb_verbose,
86     isc_spb_options,
87     isc_spb_connect_timeout,
88     isc_spb_dummy_packet_interval,
89     isc_spb_sql_role_name
90 tony 33 );
91    
92     type
93     TOutputBufferOption = (ByLine, ByChunk);
94    
95     TIBCustomService = class;
96    
97     TLoginEvent = procedure(Database: TIBCustomService;
98     LoginParams: TStrings) of object;
99    
100     { TIBCustomService }
101    
102     TIBCustomService = class(TComponent)
103     private
104     FParamsChanged : Boolean;
105 tony 45 FQueryParams: String;
106     FSPB : ISPB;
107     FSRB: ISRB;
108     FSQPB: ISQPB;
109 tony 33 FTraceFlags: TTraceFlags;
110     FOnLogin: TLoginEvent;
111     FLoginPrompt: Boolean;
112     FServerName: string;
113 tony 45 FService: IServiceManager;
114 tony 33 FStreamedActive : Boolean;
115     FOnAttach: TNotifyEvent;
116     FOutputBufferOption: TOutputBufferOption;
117     FProtocol: TProtocol;
118     FParams: TStrings;
119 tony 45 FServiceQueryResults: IServiceQueryResults;
120 tony 33 function GetActive: Boolean;
121     function GetServiceParamBySPB(const Idx: Integer): String;
122 tony 45 function GetSQPB: ISQPB;
123     function GetSRB: ISRB;
124 tony 33 procedure SetActive(const Value: Boolean);
125     procedure SetParams(const Value: TStrings);
126     procedure SetServerName(const Value: string);
127     procedure SetProtocol(const Value: TProtocol);
128 tony 45 procedure SetService(AValue: IServiceManager);
129 tony 33 procedure SetServiceParamBySPB(const Idx: Integer;
130     const Value: String);
131 tony 45 function IndexOfSPBConst(action: byte): Integer;
132     function GetSPBConstName(action: byte): string;
133 tony 33 procedure ParamsChange(Sender: TObject);
134     procedure ParamsChanging(Sender: TObject);
135     procedure CheckServerName;
136 tony 45 function GenerateSPB(sl: TStrings): ISPB;
137 tony 33
138     protected
139     procedure Loaded; override;
140 tony 39 function Login(var aServerName: string): Boolean;
141 tony 33 procedure CheckActive;
142     procedure CheckInactive;
143     procedure HandleException(Sender: TObject);
144     procedure InternalServiceQuery;
145 tony 45 property SRB: ISRB read GetSRB;
146     property SQPB: ISQPB read GetSQPB;
147     property ServiceQueryResults: IServiceQueryResults read FServiceQueryResults;
148 tony 33
149     public
150     constructor Create(AOwner: TComponent); override;
151     destructor Destroy; override;
152     procedure Attach;
153     procedure Detach;
154 tony 45 property ServiceIntf: IServiceManager read FService write SetService;
155 tony 33 property ServiceParamBySPB[const Idx: Integer]: String read GetServiceParamBySPB
156     write SetServiceParamBySPB;
157     published
158     property Active: Boolean read GetActive write SetActive default False;
159     property ServerName: string read FServerName write SetServerName;
160     property Protocol: TProtocol read FProtocol write SetProtocol default Local;
161     property Params: TStrings read FParams write SetParams;
162     property LoginPrompt: Boolean read FLoginPrompt write FLoginPrompt default True;
163     property TraceFlags: TTraceFlags read FTraceFlags write FTraceFlags;
164     property OnAttach: TNotifyEvent read FOnAttach write FOnAttach;
165     property OnLogin: TLoginEvent read FOnLogin write FOnLogin;
166     end;
167    
168     TDatabaseInfo = class
169     public
170     NoOfAttachments: Integer;
171     NoOfDatabases: Integer;
172     DbName: array of string;
173     constructor Create;
174     destructor Destroy; override;
175     end;
176    
177     TLicenseInfo = class
178     public
179     Key: array of string;
180     Id: array of string;
181     Desc: array of string;
182     LicensedUsers: Integer;
183     constructor Create;
184     destructor Destroy; override;
185     end;
186    
187     TLicenseMaskInfo = class
188     public
189     LicenseMask: Integer;
190     CapabilityMask: Integer;
191     end;
192    
193     TConfigFileData = class
194     public
195     ConfigFileValue: array of integer;
196     ConfigFileKey: array of integer;
197     constructor Create;
198     destructor Destroy; override;
199     end;
200    
201     TConfigParams = class
202     public
203     ConfigFileData: TConfigFileData;
204     ConfigFileParams: array of string;
205     BaseLocation: string;
206     LockFileLocation: string;
207     MessageFileLocation: string;
208     SecurityDatabaseLocation: string;
209     constructor Create;
210     destructor Destroy; override;
211     end;
212    
213     TVersionInfo = class
214     ServerVersion: String;
215     ServerImplementation: string;
216     ServiceVersion: Integer;
217     end;
218    
219     TPropertyOption = (Database, License, LicenseMask, ConfigParameters, Version);
220     TPropertyOptions = set of TPropertyOption;
221    
222     TIBServerProperties = class(TIBCustomService)
223     private
224     FOptions: TPropertyOptions;
225     FDatabaseInfo: TDatabaseInfo;
226     FLicenseInfo: TLicenseInfo;
227     FLicenseMaskInfo: TLicenseMaskInfo;
228     FVersionInfo: TVersionInfo;
229     FConfigParams: TConfigParams;
230     public
231     constructor Create(AOwner: TComponent); override;
232     destructor Destroy; override;
233     procedure Fetch;
234     procedure FetchDatabaseInfo;
235     procedure FetchLicenseInfo;
236     procedure FetchLicenseMaskInfo;
237     procedure FetchConfigParams;
238     procedure FetchVersionInfo;
239     property DatabaseInfo: TDatabaseInfo read FDatabaseInfo;
240     property LicenseInfo: TLicenseInfo read FLicenseInfo;
241     property LicenseMaskInfo: TLicenseMaskInfo read FLicenseMaskInfo;
242     property VersionInfo: TVersionInfo read FVersionInfo;
243     property ConfigParams: TConfigParams read FConfigParams;
244     published
245     property Options : TPropertyOptions read FOptions write FOptions;
246     end;
247    
248 tony 45 { TIBControlService }
249    
250 tony 33 TIBControlService = class (TIBCustomService)
251     private
252     function GetIsServiceRunning: Boolean;
253     protected
254 tony 45 procedure CheckServiceNotRunning;
255     procedure InternalServiceStart;
256 tony 33 procedure SetServiceStartOptions; virtual;
257    
258     public
259     constructor Create(AOwner: TComponent); override;
260     procedure ServiceStart; virtual;
261     property IsServiceRunning : Boolean read GetIsServiceRunning;
262     end;
263    
264 tony 45 { TIBControlAndQueryService }
265    
266 tony 33 TIBControlAndQueryService = class (TIBControlService)
267     private
268     FEof: Boolean;
269     FAction: Integer;
270     procedure SetAction(Value: Integer);
271     protected
272     property Action: Integer read FAction write SetAction;
273     public
274     constructor create (AOwner: TComponent); override;
275     function GetNextLine : String;
276     function GetNextChunk : String;
277 tony 45 function WriteNextChunk(stream: TStream): integer;
278 tony 33 property Eof: boolean read FEof;
279     end;
280    
281     TShutdownMode = (Forced, DenyTransaction, DenyAttachment);
282    
283     TIBConfigService = class(TIBControlService)
284     private
285     FDatabaseName: string;
286     procedure SetDatabaseName(const Value: string);
287     protected
288    
289     public
290     procedure ServiceStart; override;
291     procedure ShutdownDatabase (Options: TShutdownMode; Wait: Integer);
292     procedure SetSweepInterval (Value: Integer);
293     procedure SetDBSqlDialect (Value: Integer);
294     procedure SetPageBuffers (Value: Integer);
295     procedure ActivateShadow;
296     procedure BringDatabaseOnline;
297     procedure SetReserveSpace (Value: Boolean);
298     procedure SetAsyncMode (Value: Boolean);
299     procedure SetReadOnly (Value: Boolean);
300     published
301     property DatabaseName: string read FDatabaseName write SetDatabaseName;
302     end;
303    
304     TIBLogService = class(TIBControlAndQueryService)
305     private
306    
307     protected
308     procedure SetServiceStartOptions; override;
309     public
310     published
311     end;
312    
313 tony 43 TStatOption = (DataPages, {DbLog,} HeaderPages, IndexPages, SystemRelations);
314 tony 33 TStatOptions = set of TStatOption;
315    
316     TIBStatisticalService = class(TIBControlAndQueryService)
317     private
318     FDatabaseName: string;
319     FOptions: TStatOptions;
320     procedure SetDatabaseName(const Value: string);
321     protected
322     procedure SetServiceStartOptions; override;
323     public
324     published
325     property DatabaseName: string read FDatabaseName write SetDatabaseName;
326     property Options : TStatOptions read FOptions write FOptions;
327     end;
328    
329 tony 45 TBackupLocation = (flServerSide,flClientSide);
330 tony 33
331 tony 45 { TIBBackupRestoreService }
332    
333 tony 33 TIBBackupRestoreService = class(TIBControlAndQueryService)
334     private
335 tony 45 FBackupFileLocation: TBackupLocation;
336 tony 33 FVerbose: Boolean;
337     protected
338     public
339 tony 45 constructor Create(AOwner: TComponent); override;
340 tony 33 published
341     property Verbose : Boolean read FVerbose write FVerbose default False;
342 tony 45 property BackupFileLocation: TBackupLocation read FBackupFileLocation
343     write FBackupFileLocation default flServerSide;
344 tony 33 end;
345    
346     TBackupOption = (IgnoreChecksums, IgnoreLimbo, MetadataOnly, NoGarbageCollection,
347     OldMetadataDesc, NonTransportable, ConvertExtTables);
348     TBackupOptions = set of TBackupOption;
349    
350     TIBBackupService = class (TIBBackupRestoreService)
351     private
352     FDatabaseName: string;
353     FOptions: TBackupOptions;
354     FBackupFile: TStrings;
355     FBlockingFactor: Integer;
356     procedure SetBackupFile(const Value: TStrings);
357     protected
358     procedure SetServiceStartOptions; override;
359     public
360     constructor Create(AOwner: TComponent); override;
361     destructor Destroy; override;
362    
363     published
364     { a name=value pair of filename and length }
365     property BackupFile: TStrings read FBackupFile write SetBackupFile;
366     property BlockingFactor: Integer read FBlockingFactor write FBlockingFactor;
367     property DatabaseName: string read FDatabaseName write FDatabaseName;
368     property Options : TBackupOptions read FOptions write FOptions;
369     end;
370    
371     TRestoreOption = (DeactivateIndexes, NoShadow, NoValidityCheck, OneRelationAtATime,
372     Replace, CreateNewDB, UseAllSpace);
373    
374     TRestoreOptions = set of TRestoreOption;
375 tony 45
376     { TIBRestoreService }
377    
378 tony 33 TIBRestoreService = class (TIBBackupRestoreService)
379     private
380     FDatabaseName: TStrings;
381     FBackupFile: TStrings;
382     FOptions: TRestoreOptions;
383     FPageSize: Integer;
384     FPageBuffers: Integer;
385 tony 45 FSendBytes: integer;
386 tony 33 procedure SetBackupFile(const Value: TStrings);
387     procedure SetDatabaseName(const Value: TStrings);
388     protected
389     procedure SetServiceStartOptions; override;
390     public
391     constructor Create(AOwner: TComponent); override;
392     destructor Destroy; override;
393 tony 45 function SendNextChunk(stream: TStream; var line: String): integer;
394 tony 33 published
395     { a name=value pair of filename and length }
396     property DatabaseName: TStrings read FDatabaseName write SetDatabaseName;
397     property BackupFile: TStrings read FBackupFile write SetBackupFile;
398     property PageSize: Integer read FPageSize write FPageSize;
399     property PageBuffers: Integer read FPageBuffers write FPageBuffers;
400     property Options : TRestoreOptions read FOptions write FOptions default [CreateNewDB];
401     end;
402    
403     TValidateOption = (LimboTransactions, CheckDB, IgnoreChecksum, KillShadows, MendDB,
404     SweepDB, ValidateDB, ValidateFull);
405     TValidateOptions = set of TValidateOption;
406    
407     TTransactionGlobalAction = (CommitGlobal, RollbackGlobal, RecoverTwoPhaseGlobal,
408     NoGlobalAction);
409     TTransactionState = (LimboState, CommitState, RollbackState, UnknownState);
410     TTransactionAdvise = (CommitAdvise, RollbackAdvise, UnknownAdvise);
411     TTransactionAction = (CommitAction, RollbackAction);
412    
413     TLimboTransactionInfo = class
414     public
415     MultiDatabase: Boolean;
416     ID: Integer;
417     HostSite: String;
418     RemoteSite: String;
419     RemoteDatabasePath: String;
420     State: TTransactionState;
421     Advise: TTransactionAdvise;
422     Action: TTransactionAction;
423     end;
424    
425     TIBValidationService = class(TIBControlAndQueryService)
426     private
427     FDatabaseName: string;
428     FOptions: TValidateOptions;
429     FLimboTransactionInfo: array of TLimboTransactionInfo;
430     FGlobalAction: TTransactionGlobalAction;
431     procedure SetDatabaseName(const Value: string);
432     function GetLimboTransactionInfo(index: integer): TLimboTransactionInfo;
433     function GetLimboTransactionInfoCount: integer;
434    
435     protected
436     procedure SetServiceStartOptions; override;
437     public
438     constructor Create(AOwner: TComponent); override;
439     destructor Destroy; override;
440     procedure FetchLimboTransactionInfo;
441     procedure FixLimboTransactionErrors;
442     property LimboTransactionInfo[Index: integer]: TLimboTransactionInfo read GetLimboTransactionInfo;
443     property LimboTransactionInfoCount: Integer read GetLimboTransactionInfoCount;
444    
445     published
446     property DatabaseName: string read FDatabaseName write SetDatabaseName;
447     property Options: TValidateOptions read FOptions write FOptions;
448     property GlobalAction: TTransactionGlobalAction read FGlobalAction
449     write FGlobalAction;
450     end;
451    
452     TUserInfo = class
453     public
454     UserName: string;
455     FirstName: string;
456     MiddleName: string;
457     LastName: string;
458     GroupID: Integer;
459     UserID: Integer;
460     end;
461    
462     TSecurityAction = (ActionAddUser, ActionDeleteUser, ActionModifyUser, ActionDisplayUser);
463     TSecurityModifyParam = (ModifyFirstName, ModifyMiddleName, ModifyLastName, ModifyUserId,
464     ModifyGroupId, ModifyPassword);
465     TSecurityModifyParams = set of TSecurityModifyParam;
466    
467     TIBSecurityService = class(TIBControlAndQueryService)
468     private
469     FUserID: Integer;
470     FGroupID: Integer;
471     FFirstName: string;
472     FUserName: string;
473     FPassword: string;
474     FSQLRole: string;
475     FLastName: string;
476     FMiddleName: string;
477     FUserInfo: array of TUserInfo;
478     FSecurityAction: TSecurityAction;
479     FModifyParams: TSecurityModifyParams;
480     procedure ClearParams;
481     procedure SetSecurityAction (Value: TSecurityAction);
482     procedure SetFirstName (Value: String);
483     procedure SetMiddleName (Value: String);
484     procedure SetLastName (Value: String);
485     procedure SetPassword (Value: String);
486     procedure SetUserId (Value: Integer);
487     procedure SetGroupId (Value: Integer);
488    
489     procedure FetchUserInfo;
490     function GetUserInfo(Index: Integer): TUserInfo;
491     function GetUserInfoCount: Integer;
492    
493     protected
494     procedure Loaded; override;
495     procedure SetServiceStartOptions; override;
496     public
497     constructor Create(AOwner: TComponent); override;
498     destructor Destroy; override;
499     procedure DisplayUsers;
500     procedure DisplayUser(UserName: string);
501     procedure AddUser;
502     procedure DeleteUser;
503     procedure ModifyUser;
504     property UserInfo[Index: Integer]: TUserInfo read GetUserInfo;
505     property UserInfoCount: Integer read GetUserInfoCount;
506    
507     published
508     property SecurityAction: TSecurityAction read FSecurityAction
509     write SetSecurityAction;
510     property SQlRole : string read FSQLRole write FSQLrole;
511     property UserName : string read FUserName write FUserName;
512     property FirstName : string read FFirstName write SetFirstName;
513     property MiddleName : string read FMiddleName write SetMiddleName;
514     property LastName : string read FLastName write SetLastName;
515     property UserID : Integer read FUserID write SetUserID;
516     property GroupID : Integer read FGroupID write SetGroupID;
517     property Password : string read FPassword write setPassword;
518     end;
519    
520    
521     implementation
522    
523     uses
524 tony 45 IBSQLMonitor, Math, FBMessages;
525 tony 33
526 tony 45 { TIBBackupRestoreService }
527    
528     constructor TIBBackupRestoreService.Create(AOwner: TComponent);
529     begin
530     inherited Create(AOwner);
531     FBackupFileLocation := flServerSide;
532     end;
533    
534 tony 33 { TIBCustomService }
535    
536     procedure TIBCustomService.Attach;
537 tony 45 var aServerName: string;
538 tony 33 begin
539     CheckInactive;
540     CheckServerName;
541    
542 tony 39 aServerName := FServerName;
543 tony 45
544 tony 39 if FLoginPrompt and not Login(aServerName) then
545 tony 33 IBError(ibxeOperationCancelled, [nil]);
546    
547     { Generate a new SPB if necessary }
548     if FParamsChanged then
549     begin
550     FParamsChanged := False;
551 tony 45 FSPB := GenerateSPB(FParams);
552 tony 33 end;
553    
554 tony 45 FService := FirebirdAPI.GetServiceManager(aServerName,FProtocol,FSPB);
555    
556 tony 33 if Assigned(FOnAttach) then
557     FOnAttach(Self);
558    
559     MonitorHook.ServiceAttach(Self);
560     end;
561    
562     procedure TIBCustomService.Loaded;
563     begin
564     inherited Loaded;
565     try
566     if FStreamedActive and (not Active) then
567     Attach;
568     except
569     if csDesigning in ComponentState then
570     HandleException(self)
571     else
572     raise;
573     end;
574     end;
575    
576 tony 39 function TIBCustomService.Login(var aServerName: string): Boolean;
577 tony 33 var
578     IndexOfUser, IndexOfPassword: Integer;
579     Username, Password: String;
580     LoginParams: TStrings;
581     begin
582     if Assigned(FOnLogin) then begin
583     result := True;
584     LoginParams := TStringList.Create;
585     try
586     LoginParams.Assign(Params);
587     FOnLogin(Self, LoginParams);
588     Params.Assign (LoginParams);
589 tony 39 aServerName := ServerName;
590 tony 33 finally
591     LoginParams.Free;
592     end;
593     end
594     else
595     if assigned(IBGUIInterface) then
596     begin
597 tony 45 IndexOfUser := IndexOfSPBConst(isc_spb_user_name);
598 tony 33 if IndexOfUser <> -1 then
599     Username := Copy(Params[IndexOfUser],
600     Pos('=', Params[IndexOfUser]) + 1, {mbcs ok}
601     Length(Params[IndexOfUser]));
602 tony 45 IndexOfPassword := IndexOfSPBConst(isc_spb_password);
603 tony 33 if IndexOfPassword <> -1 then
604     Password := Copy(Params[IndexOfPassword],
605     Pos('=', Params[IndexOfPassword]) + 1, {mbcs ok}
606     Length(Params[IndexOfPassword]));
607 tony 39 result := IBGUIInterface.ServerLoginDialog(aServerName, Username, Password);
608 tony 33 if result then
609     begin
610 tony 45 IndexOfPassword := IndexOfSPBConst(isc_spb_password);
611 tony 33 if IndexOfUser = -1 then
612 tony 45 Params.Add(GetSPBConstName(isc_spb_user_name) + '=' + Username)
613 tony 33 else
614 tony 45 Params[IndexOfUser] := GetSPBConstName(isc_spb_user_name) +
615 tony 33 '=' + Username;
616     if IndexOfPassword = -1 then
617 tony 45 Params.Add(GetSPBConstName(isc_spb_password) + '=' + Password)
618 tony 33 else
619 tony 45 Params[IndexOfPassword] := GetSPBConstName(isc_spb_password) +
620 tony 33 '=' + Password;
621     end
622     end
623     else
624     IBError(ibxeNoLoginDialog,[]);
625     end;
626    
627     procedure TIBCustomService.CheckActive;
628     begin
629     if FStreamedActive and (not Active) then
630     Loaded;
631 tony 45 if FService = nil then
632 tony 33 IBError(ibxeServiceActive, [nil]);
633     end;
634    
635     procedure TIBCustomService.CheckInactive;
636     begin
637 tony 45 if FService <> nil then
638 tony 33 IBError(ibxeServiceInActive, [nil]);
639     end;
640    
641     procedure TIBCustomService.HandleException(Sender: TObject);
642     var aParent: TComponent;
643     begin
644     aParent := Owner;
645     while aParent <> nil do
646     begin
647     if aParent is TCustomApplication then
648     begin
649     TCustomApplication(aParent).HandleException(Sender);
650     Exit;
651     end;
652     aParent := aParent.Owner;
653     end;
654     SysUtils.ShowException(ExceptObject,ExceptAddr);
655     end;
656    
657     constructor TIBCustomService.Create(AOwner: TComponent);
658     begin
659     inherited Create(AOwner);
660     FserverName := '';
661     FParams := TStringList.Create;
662     FParamsChanged := True;
663     TStringList(FParams).OnChange := ParamsChange;
664     TStringList(FParams).OnChanging := ParamsChanging;
665     FLoginPrompt := True;
666     FTraceFlags := [];
667 tony 45 FService := nil;
668     FSRB := nil;
669     FSPB := nil;
670     FServiceQueryResults := nil;
671 tony 33 FProtocol := Local;
672     if (AOwner <> nil) and
673     (AOwner is TCustomApplication) and
674     TCustomApplication(AOwner).ConsoleApplication then
675     LoginPrompt := false;
676     end;
677    
678     destructor TIBCustomService.Destroy;
679     begin
680 tony 45 if FService <> nil then
681 tony 33 Detach;
682 tony 45 FSRB := nil;
683     FSPB := nil;
684     FParams.Free;
685     FServiceQueryResults := nil;
686 tony 33 inherited Destroy;
687     end;
688    
689     procedure TIBCustomService.Detach;
690     begin
691     CheckActive;
692 tony 45 FService.Detach;
693     FService := nil;
694 tony 33 MonitorHook.ServiceDetach(Self);
695     end;
696    
697     function TIBCustomService.GetActive: Boolean;
698     begin
699 tony 45 result := FService <> nil;
700 tony 33 end;
701    
702     function TIBCustomService.GetServiceParamBySPB(const Idx: Integer): String;
703     var
704     ConstIdx, EqualsIdx: Integer;
705     begin
706     if (Idx > 0) and (Idx <= isc_spb_last_spb_constant) then
707     begin
708 tony 45 ConstIdx := IndexOfSPBConst(Idx);
709 tony 33 if ConstIdx = -1 then
710     result := ''
711     else
712     begin
713     result := Params[ConstIdx];
714     EqualsIdx := Pos('=', result); {mbcs ok}
715     if EqualsIdx = 0 then
716     result := ''
717     else
718     result := Copy(result, EqualsIdx + 1, Length(result));
719     end;
720     end
721     else
722     result := '';
723     end;
724    
725 tony 45 function TIBCustomService.GetSQPB: ISQPB;
726     begin
727     CheckActive;
728     if FSQPB = nil then
729     FSQPB := FService.AllocateSQPB;
730     Result := FSQPB;
731     end;
732    
733     function TIBCustomService.GetSRB: ISRB;
734     begin
735     CheckActive;
736     if FSRB = nil then
737     FSRB := FService.AllocateSRB;
738     Result := FSRB;
739     end;
740    
741 tony 33 procedure TIBCustomService.InternalServiceQuery;
742     begin
743 tony 45 FServiceQueryResults := FService.Query(FSQPB,FSRB);
744     FSQPB := nil;
745     FSRB := nil;
746 tony 33 MonitorHook.ServiceQuery(Self);
747     end;
748    
749     procedure TIBCustomService.SetActive(const Value: Boolean);
750     begin
751     if csReading in ComponentState then
752     FStreamedActive := Value
753     else
754 tony 45 if Value <> Active then
755     begin
756 tony 33 if Value then
757     Attach
758     else
759     Detach;
760 tony 45 end
761     else if Value then
762     begin
763     FService.Detach;
764     FService.Attach;
765     end;
766 tony 33 end;
767    
768     procedure TIBCustomService.SetParams(const Value: TStrings);
769     begin
770     FParams.Assign(Value);
771     end;
772    
773     procedure TIBCustomService.SetServerName(const Value: string);
774     begin
775     if FServerName <> Value then
776     begin
777     CheckInactive;
778     FServerName := Value;
779     end;
780     end;
781    
782     procedure TIBCustomService.SetProtocol(const Value: TProtocol);
783     begin
784     if FProtocol <> Value then
785     begin
786     CheckInactive;
787     FProtocol := Value;
788     if (Value = Local) then
789     FServerName := '';
790     end;
791     end;
792    
793 tony 45 procedure TIBCustomService.SetService(AValue: IServiceManager);
794     begin
795     if FService = AValue then Exit;
796     FService := AValue;
797     if AValue <> nil then
798     FServerName := FService.getServerName;
799     end;
800    
801 tony 33 procedure TIBCustomService.SetServiceParamBySPB(const Idx: Integer;
802     const Value: String);
803     var
804     ConstIdx: Integer;
805     begin
806 tony 45 ConstIdx := IndexOfSPBConst(Idx);
807 tony 33 if (Value = '') then
808     begin
809     if ConstIdx <> -1 then
810     Params.Delete(ConstIdx);
811     end
812     else
813     begin
814     if (ConstIdx = -1) then
815 tony 45 Params.Add(GetSPBConstName(Idx) + '=' + Value)
816 tony 33 else
817 tony 45 Params[ConstIdx] := GetSPBConstName(Idx) + '=' + Value;
818 tony 33 end;
819     end;
820    
821 tony 45 function TIBCustomService.IndexOfSPBConst(action: byte): Integer;
822 tony 33 var
823 tony 45 i, pos_of_str: Integer;
824     st: string;
825 tony 33 begin
826     result := -1;
827 tony 45 st := GetSPBConstName(action);
828     if st <> '' then
829 tony 33 for i := 0 to Params.Count - 1 do
830     begin
831     pos_of_str := Pos(st, Params[i]); {mbcs ok}
832     if (pos_of_str = 1) or (pos_of_str = Length(SPBPrefix) + 1) then
833     begin
834     result := i;
835     break;
836     end;
837     end;
838     end;
839    
840 tony 45 function TIBCustomService.GetSPBConstName(action: byte): string;
841     var i: integer;
842     begin
843     Result := '';
844     for i := Low(SPBConstantValues) to High(SPBConstantValues) do
845     if SPBConstantValues[i] = action then
846     begin
847     Result := SPBConstantNames[i];
848     break;
849     end;
850     end;
851    
852 tony 33 procedure TIBCustomService.ParamsChange(Sender: TObject);
853     begin
854     FParamsChanged := True;
855     end;
856    
857     procedure TIBCustomService.ParamsChanging(Sender: TObject);
858     begin
859     CheckInactive;
860     end;
861    
862     procedure TIBCustomService.CheckServerName;
863     begin
864     if (FServerName = '') and (FProtocol <> Local) then
865     IBError(ibxeServerNameMissing, [nil]);
866     end;
867    
868     {
869     * GenerateSPB -
870     * Given a string containing a textual representation
871     * of the Service parameters, generate a service
872 tony 45 * parameter buffer, and return it .
873 tony 33 }
874 tony 45 function TIBCustomService.GenerateSPB(sl: TStrings): ISPB;
875 tony 33 var
876     i, j, SPBVal, SPBServerVal: UShort;
877     param_name, param_value: String;
878     begin
879     { The SPB is initially empty, with the exception that
880     the SPB version must be the first byte of the string.
881     }
882 tony 45 Result := FirebirdAPI.AllocateSPB;
883    
884 tony 33 { Iterate through the textual service parameters, constructing
885     a SPB on-the-fly }
886     if sl.Count > 0 then
887     for i := 0 to sl.Count - 1 do
888     begin
889     { Get the parameter's name and value from the list,
890     and make sure that the name is all lowercase with
891     no leading 'isc_spb_' prefix }
892     if (Trim(sl.Names[i]) = '') then continue;
893     param_name := LowerCase(sl.Names[i]); {mbcs ok}
894     param_value := Copy(sl[i], Pos('=', sl[i]) + 1, Length(sl[i])); {mbcs ok}
895     if (Pos(SPBPrefix, param_name) = 1) then {mbcs ok}
896     Delete(param_name, 1, Length(SPBPrefix));
897     { We want to translate the parameter name to some integer
898     value. We do this by scanning through a list of known
899     service parameter names (SPBConstantNames, defined above). }
900     SPBVal := 0;
901     SPBServerVal := 0;
902     { Find the parameter }
903     for j := 1 to isc_spb_last_spb_constant do
904     if (param_name = SPBConstantNames[j]) then
905     begin
906     SPBVal := j;
907     SPBServerVal := SPBConstantValues[j];
908     break;
909     end;
910 tony 45 case SPBServerVal of
911 tony 33 isc_spb_user_name, isc_spb_password:
912 tony 45 Result.Add(SPBServerVal).AsString := param_value;
913 tony 33 else
914     begin
915 tony 45 if GetSPBConstName(SPBServerVal) <> '' then
916 tony 33 IBError(ibxeSPBConstantNotSupported,
917 tony 45 [GetSPBConstName(SPBServerVal)])
918 tony 33 else
919 tony 45 IBError(ibxeSPBConstantUnknown, [SPBServerVal]);
920 tony 33 end;
921     end;
922     end;
923     end;
924    
925     { TIBServerProperties }
926     constructor TIBServerProperties.Create(AOwner: TComponent);
927     begin
928     inherited Create(AOwner);
929     FDatabaseInfo := TDatabaseInfo.Create;
930     FLicenseInfo := TLicenseInfo.Create;
931     FLicenseMaskInfo := TLicenseMaskInfo.Create;
932     FVersionInfo := TVersionInfo.Create;
933     FConfigParams := TConfigParams.Create;
934     end;
935    
936     destructor TIBServerProperties.Destroy;
937     begin
938     FDatabaseInfo.Free;
939     FLicenseInfo.Free;
940     FLicenseMaskInfo.Free;
941     FVersionInfo.Free;
942     FConfigParams.Free;
943     inherited Destroy;
944     end;
945    
946     procedure TIBServerProperties.Fetch;
947     begin
948     if (Database in Options) then
949     FetchDatabaseInfo;
950     if (License in Options) then
951     FetchLicenseInfo;
952     if (LicenseMask in Options) then
953     FetchLicenseMaskInfo;
954     if (ConfigParameters in Options) then
955     FetchConfigParams;
956     if (Version in Options) then
957     FetchVersionInfo;
958     end;
959    
960     procedure TIBServerProperties.FetchConfigParams;
961     var
962 tony 45 i, j: Integer;
963 tony 33
964     begin
965 tony 45 SRB.Add(isc_info_svc_get_config);
966     SRB.Add(isc_info_svc_get_env);
967     SRB.Add(isc_info_svc_get_env_lock);
968     SRB.Add(isc_info_svc_get_env_msg);
969     SRB.Add(isc_info_svc_user_dbpath);
970 tony 33
971     InternalServiceQuery;
972 tony 45
973     for i := 0 to FServiceQueryResults.Count - 1 do
974     with FServiceQueryResults[i] do
975 tony 33 begin
976 tony 45 case getItemType of
977 tony 33 isc_info_svc_get_config:
978     begin
979 tony 45 SetLength (FConfigParams.ConfigFileData.ConfigFileValue, Count);
980     SetLength (FConfigParams.ConfigFileData.ConfigFileKey, Count);
981    
982     for j := 0 to Count - 1 do
983     begin
984     FConfigParams.ConfigFileData.ConfigFileKey[j] := getItemType;
985     FConfigParams.ConfigFileData.ConfigFileValue[j] := AsInteger;
986     end;
987 tony 33 end;
988    
989     isc_info_svc_get_env:
990 tony 45 FConfigParams.BaseLocation := AsString;
991 tony 33
992     isc_info_svc_get_env_lock:
993 tony 45 FConfigParams.LockFileLocation := AsString;
994 tony 33
995     isc_info_svc_get_env_msg:
996 tony 45 FConfigParams.MessageFileLocation := AsString;
997 tony 33
998     isc_info_svc_user_dbpath:
999 tony 45 FConfigParams.SecurityDatabaseLocation := AsString;
1000    
1001 tony 33 else
1002 tony 45 IBError(ibxeOutputParsingError, [getItemType]);
1003 tony 33 end;
1004     end;
1005     end;
1006    
1007     procedure TIBServerProperties.FetchDatabaseInfo;
1008     var
1009 tony 45 i,j: Integer;
1010 tony 33 begin
1011 tony 45 SRB.Add(isc_info_svc_svr_db_info);
1012 tony 33 InternalServiceQuery;
1013 tony 45
1014     SetLength(FDatabaseInfo.DbName,0);
1015     for i := 0 to FServiceQueryResults.Count - 1 do
1016     with FServiceQueryResults[i] do
1017 tony 33 begin
1018 tony 45 case getItemType of
1019     isc_info_svc_svr_db_info:
1020     for j := 0 to FServiceQueryResults[i].Count - 1 do
1021     with FServiceQueryResults[i][j] do
1022     case getItemType of
1023     isc_spb_num_att:
1024     FDatabaseInfo.NoOfAttachments := AsInteger;
1025    
1026     isc_spb_num_db:
1027     FDatabaseInfo.NoOfDatabases := AsInteger;
1028    
1029     isc_spb_dbname:
1030     begin
1031     SetLength(FDatabaseInfo.DbName,length(FDatabaseInfo.DbName)+1);
1032     FDatabaseInfo.DbName[length(FDatabaseInfo.DbName)-1] := AsString;
1033     end;
1034     else
1035     IBError(ibxeOutputParsingError, [getItemType]);
1036     end;
1037     else
1038     IBError(ibxeOutputParsingError, [getItemType]);
1039     end;
1040     end;
1041 tony 33 end;
1042    
1043     procedure TIBServerProperties.FetchLicenseInfo;
1044     var
1045 tony 45 i,j : Integer;
1046 tony 33 begin
1047 tony 45 SRB.Add(isc_info_svc_get_license);
1048     SRB.Add(isc_info_svc_get_licensed_users);
1049 tony 33 InternalServiceQuery;
1050    
1051 tony 45 SetLength(FLicenseInfo.key, 0);
1052     SetLength(FLicenseInfo.id, 0);
1053     SetLength(FLicenseInfo.desc, 0);
1054    
1055     for i := 0 to FServiceQueryResults.Count - 1 do
1056     with FServiceQueryResults[i] do
1057     begin
1058     case getItemType of
1059 tony 33 isc_info_svc_get_license:
1060     begin
1061 tony 45 SetLength(FLicenseInfo.key, Count);
1062     SetLength(FLicenseInfo.id, Count);
1063     SetLength(FLicenseInfo.desc, Count);
1064    
1065     for j := 0 to Count -1 do
1066     with Items[j] do
1067     case getItemType of
1068     isc_spb_lic_id:
1069     FLicenseInfo.id[j] := AsString;
1070    
1071     isc_spb_lic_key:
1072     FLicenseInfo.key[j] := AsString;
1073    
1074     isc_spb_lic_desc:
1075     FLicenseInfo.desc[j] := AsString;
1076     else
1077     IBError(ibxeOutputParsingError, [getItemType]);
1078 tony 33 end;
1079     end;
1080     else
1081 tony 45 IBError(ibxeOutputParsingError, [getItemType]);
1082 tony 33 end;
1083     end;
1084     end;
1085    
1086     procedure TIBServerProperties.FetchLicenseMaskInfo();
1087     var
1088 tony 45 i : Integer;
1089 tony 33 begin
1090 tony 45 SRB.Add(isc_info_svc_get_license_mask);
1091     SRB.Add(isc_info_svc_capabilities);
1092 tony 33 InternalServiceQuery;
1093 tony 45
1094     for i := 0 to FServiceQueryResults.Count - 1 do
1095     with FServiceQueryResults[i] do
1096 tony 33 begin
1097 tony 45 case getItemType of
1098 tony 33 isc_info_svc_get_license_mask:
1099 tony 45 FLicenseMaskInfo.LicenseMask := AsInteger;
1100 tony 33 isc_info_svc_capabilities:
1101 tony 45 FLicenseMaskInfo.CapabilityMask := AsInteger;
1102 tony 33 else
1103 tony 45 IBError(ibxeOutputParsingError, [getItemType]);
1104 tony 33 end;
1105     end;
1106     end;
1107    
1108    
1109     procedure TIBServerProperties.FetchVersionInfo;
1110     var
1111 tony 45 i : Integer;
1112 tony 33 begin
1113 tony 45 SRB.Add(isc_info_svc_version);
1114     SRB.Add(isc_info_svc_server_version);
1115     SRB.Add(isc_info_svc_implementation);
1116 tony 33 InternalServiceQuery;
1117    
1118 tony 45 for i := 0 to FServiceQueryResults.Count - 1 do
1119     with FServiceQueryResults[i] do
1120 tony 33 begin
1121 tony 45 case getItemType of
1122 tony 33 isc_info_svc_version:
1123 tony 45 FVersionInfo.ServiceVersion := AsInteger;
1124 tony 33 isc_info_svc_server_version:
1125 tony 45 FVersionInfo.ServerVersion := AsString;
1126 tony 33 isc_info_svc_implementation:
1127 tony 45 FVersionInfo.ServerImplementation := AsString;
1128 tony 33 else
1129 tony 45 IBError(ibxeOutputParsingError, [getItemType]);
1130 tony 33 end;
1131     end;
1132     end;
1133    
1134     { TIBControlService }
1135 tony 45
1136 tony 33 procedure TIBControlService.SetServiceStartOptions;
1137     begin
1138    
1139     end;
1140    
1141     function TIBControlService.GetIsServiceRunning: Boolean;
1142     begin
1143 tony 45 SRB.Add(isc_info_svc_running);
1144 tony 33 InternalServiceQuery;
1145    
1146 tony 45 Result := (FServiceQueryResults.Count > 0) and
1147     (FServiceQueryResults[0].getItemType = isc_info_svc_running) and
1148     (FServiceQueryResults[0].AsInteger = 1);
1149 tony 33 end;
1150    
1151 tony 45 procedure TIBControlService.CheckServiceNotRunning;
1152 tony 33 begin
1153 tony 45 if IsServiceRunning then
1154     IBError(ibxeServiceRunning,[nil]);
1155 tony 33 end;
1156    
1157     constructor TIBControlService.Create(AOwner: TComponent);
1158     begin
1159     inherited create(AOwner);
1160 tony 45 FSRB := nil;
1161     FSPB := nil;
1162 tony 33 end;
1163    
1164     procedure TIBControlService.InternalServiceStart;
1165     begin
1166 tony 45 if SRB = nil then
1167 tony 33 IBError(ibxeStartParamsError, [nil]);
1168 tony 45
1169 tony 33 try
1170 tony 45 FService.Start(SRB);
1171 tony 33 finally
1172 tony 45 FSRB := nil;
1173 tony 33 end;
1174     MonitorHook.ServiceStart(Self);
1175     end;
1176    
1177     procedure TIBControlService.ServiceStart;
1178     begin
1179     CheckActive;
1180 tony 45 CheckServiceNotRunning;
1181 tony 33 SetServiceStartOptions;
1182     InternalServiceStart;
1183     end;
1184    
1185     { TIBConfigService }
1186    
1187     procedure TIBConfigService.ServiceStart;
1188     begin
1189     IBError(ibxeUseSpecificProcedures, [nil]);
1190     end;
1191    
1192     procedure TIBConfigService.ActivateShadow;
1193     begin
1194 tony 45 SRB.Add(isc_action_svc_properties);
1195     SRB.Add(isc_spb_dbname).AsString := FDatabaseName;
1196     SRB.Add(isc_spb_options).AsInteger := isc_spb_prp_activate;
1197 tony 33 InternalServiceStart;
1198     end;
1199    
1200     procedure TIBConfigService.BringDatabaseOnline;
1201     begin
1202 tony 45 SRB.Add(isc_action_svc_properties);
1203     SRB.Add(isc_spb_dbname).AsString := FDatabaseName;
1204     SRB.Add(isc_spb_options).AsInteger := isc_spb_prp_db_online;
1205 tony 33 InternalServiceStart;
1206     end;
1207    
1208     procedure TIBConfigService.SetAsyncMode(Value: Boolean);
1209     begin
1210 tony 45 SRB.Add(isc_action_svc_properties);
1211     SRB.Add(isc_spb_dbname).AsString := FDatabaseName;
1212     with SRB.Add(isc_spb_prp_write_mode) do
1213 tony 33 if Value then
1214 tony 45 AsInteger := isc_spb_prp_wm_async
1215 tony 33 else
1216 tony 45 AsInteger := isc_spb_prp_wm_sync;
1217 tony 33 InternalServiceStart;
1218     end;
1219    
1220     procedure TIBConfigService.SetDatabaseName(const Value: string);
1221     begin
1222     FDatabaseName := Value;
1223     end;
1224    
1225     procedure TIBConfigService.SetPageBuffers(Value: Integer);
1226     begin
1227 tony 45 SRB.Add(isc_action_svc_properties);
1228     SRB.Add(isc_spb_dbname).AsString := FDatabaseName;
1229     SRB.Add(isc_spb_prp_page_buffers).AsInteger := Value;
1230 tony 33 InternalServiceStart;
1231     end;
1232    
1233     procedure TIBConfigService.SetReadOnly(Value: Boolean);
1234     begin
1235 tony 45 SRB.Add(isc_action_svc_properties);
1236     SRB.Add(isc_spb_dbname).AsString := FDatabaseName;
1237     with SRB.Add(isc_spb_prp_access_mode) do
1238 tony 33 if Value then
1239 tony 45 AsInteger := isc_spb_prp_am_readonly
1240 tony 33 else
1241 tony 45 AsInteger := isc_spb_prp_am_readwrite;
1242 tony 33 InternalServiceStart;
1243     end;
1244    
1245     procedure TIBConfigService.SetReserveSpace(Value: Boolean);
1246     begin
1247 tony 45 SRB.Add(isc_action_svc_properties);
1248     SRB.Add(isc_spb_dbname).AsString := FDatabaseName;
1249     with SRB.Add(isc_spb_prp_reserve_space) do
1250 tony 33 if Value then
1251 tony 45 AsInteger := isc_spb_prp_res
1252 tony 33 else
1253 tony 45 AsInteger := isc_spb_prp_res_use_full;
1254 tony 33 InternalServiceStart;
1255     end;
1256    
1257     procedure TIBConfigService.SetSweepInterval(Value: Integer);
1258     begin
1259 tony 45 SRB.Add(isc_action_svc_properties);
1260     SRB.Add(isc_spb_dbname).AsString := FDatabaseName;
1261     SRB.Add(isc_spb_prp_sweep_interval).AsInteger := Value;
1262 tony 33 InternalServiceStart;
1263     end;
1264    
1265     procedure TIBConfigService.SetDBSqlDialect(Value: Integer);
1266     begin
1267 tony 45 SRB.Add(isc_action_svc_properties);
1268     SRB.Add(isc_spb_dbname).AsString := FDatabaseName;
1269     SRB.Add(isc_spb_prp_set_sql_dialect).AsInteger := Value;
1270 tony 33 InternalServiceStart;
1271     end;
1272    
1273     procedure TIBConfigService.ShutdownDatabase(Options: TShutdownMode;
1274     Wait: Integer);
1275     begin
1276 tony 45 SRB.Add(isc_action_svc_properties);
1277     SRB.Add(isc_spb_dbname).AsString := FDatabaseName;
1278 tony 33 if (Options = Forced) then
1279 tony 45 SRB.Add(isc_spb_prp_shutdown_db).AsInteger := Wait
1280 tony 33 else if (Options = DenyTransaction) then
1281 tony 45 SRB.Add(isc_spb_prp_deny_new_transactions).AsInteger := Wait
1282 tony 33 else
1283 tony 45 SRB.Add(isc_spb_prp_deny_new_attachments).AsInteger := Wait;
1284 tony 33 InternalServiceStart;
1285     end;
1286    
1287 tony 45
1288 tony 33 { TIBStatisticalService }
1289    
1290     procedure TIBStatisticalService.SetDatabaseName(const Value: string);
1291     begin
1292     FDatabaseName := Value;
1293     end;
1294    
1295     procedure TIBStatisticalService.SetServiceStartOptions;
1296 tony 45 var param: integer;
1297 tony 33 begin
1298     if FDatabaseName = '' then
1299     IBError(ibxeStartParamsError, [nil]);
1300 tony 45
1301 tony 33 param := 0;
1302     if (DataPages in Options) then
1303     param := param or isc_spb_sts_data_pages;
1304 tony 43 { if (DbLog in Options) then
1305     param := param or isc_spb_sts_db_log; -- removed from Firebird 2}
1306 tony 33 if (HeaderPages in Options) then
1307     param := param or isc_spb_sts_hdr_pages;
1308     if (IndexPages in Options) then
1309     param := param or isc_spb_sts_idx_pages;
1310     if (SystemRelations in Options) then
1311     param := param or isc_spb_sts_sys_relations;
1312     Action := isc_action_svc_db_stats;
1313 tony 45 SRB.Add(isc_action_svc_db_stats);
1314     SRB.Add(isc_spb_dbname).AsString := FDatabaseName;
1315     SRB.Add(isc_spb_options).AsInteger := param;
1316 tony 33 end;
1317    
1318     { TIBBackupService }
1319     procedure TIBBackupService.SetServiceStartOptions;
1320     var
1321     param, i: Integer;
1322     value: String;
1323     begin
1324     if FDatabaseName = '' then
1325     IBError(ibxeStartParamsError, [nil]);
1326     param := 0;
1327     if (IgnoreChecksums in Options) then
1328     param := param or isc_spb_bkp_ignore_checksums;
1329     if (IgnoreLimbo in Options) then
1330     param := param or isc_spb_bkp_ignore_limbo;
1331     if (MetadataOnly in Options) then
1332     param := param or isc_spb_bkp_metadata_only;
1333     if (NoGarbageCollection in Options) then
1334     param := param or isc_spb_bkp_no_garbage_collect;
1335     if (OldMetadataDesc in Options) then
1336     param := param or isc_spb_bkp_old_descriptions;
1337     if (NonTransportable in Options) then
1338     param := param or isc_spb_bkp_non_transportable;
1339     if (ConvertExtTables in Options) then
1340     param := param or isc_spb_bkp_convert;
1341     Action := isc_action_svc_backup;
1342 tony 45 SRB.Add(isc_action_svc_backup);
1343     SRB.Add(isc_spb_dbname).AsString := FDatabaseName;
1344     SRB.Add(isc_spb_options).AsInteger := param;
1345     if Verbose and (BackupFileLocation = flServerSide) then
1346     SRB.Add(isc_spb_verbose);
1347 tony 33 if FBlockingFactor > 0 then
1348 tony 45 SRB.Add(isc_spb_bkp_factor).AsInteger := FBlockingFactor;
1349     if BackupFileLocation = flServerSide then
1350 tony 33 for i := 0 to FBackupFile.Count - 1 do
1351     begin
1352     if (Trim(FBackupFile[i]) = '') then
1353     continue;
1354     if (Pos('=', FBackupFile[i]) <> 0) then
1355     begin {mbcs ok}
1356 tony 45 SRB.Add(isc_spb_bkp_file).AsString := FBackupFile.Names[i];
1357 tony 33 value := Copy(FBackupFile[i], Pos('=', FBackupFile[i]) + 1, Length(FBackupFile.Names[i])); {mbcs ok}
1358 tony 45 SRB.Add(isc_spb_bkp_length).AsInteger := StrToInt(value);;
1359 tony 33 end
1360     else
1361 tony 45 SRB.Add(isc_spb_bkp_file).AsString := FBackupFile[i];
1362     end
1363     else
1364     SRB.Add(isc_spb_bkp_file).AsString := 'stdout';
1365 tony 33 end;
1366    
1367     constructor TIBBackupService.Create(AOwner: TComponent);
1368     begin
1369     inherited Create(AOwner);
1370     FBackupFile := TStringList.Create;
1371     end;
1372    
1373     destructor TIBBackupService.Destroy;
1374     begin
1375     FBackupFile.Free;
1376     inherited Destroy;
1377     end;
1378    
1379     procedure TIBBackupService.SetBackupFile(const Value: TStrings);
1380     begin
1381     FBackupFile.Assign(Value);
1382     end;
1383    
1384     { TIBRestoreService }
1385    
1386     procedure TIBRestoreService.SetServiceStartOptions;
1387     var
1388     param, i: Integer;
1389     value: String;
1390     begin
1391     param := 0;
1392     if (DeactivateIndexes in Options) then
1393     param := param or isc_spb_res_deactivate_idx;
1394     if (NoShadow in Options) then
1395     param := param or isc_spb_res_no_shadow;
1396     if (NoValidityCheck in Options) then
1397     param := param or isc_spb_res_no_validity;
1398     if (OneRelationAtATime in Options) then
1399     param := param or isc_spb_res_one_at_a_time;
1400     if (Replace in Options) then
1401     param := param or isc_spb_res_replace;
1402     if (CreateNewDB in Options) then
1403     param := param or isc_spb_res_create;
1404     if (UseAllSpace in Options) then
1405     param := param or isc_spb_res_use_all_space;
1406     Action := isc_action_svc_restore;
1407 tony 45 SRB.Add(isc_action_svc_restore);
1408     SRB.Add(isc_spb_options).AsInteger := param;
1409     if Verbose then
1410     SRB.Add(isc_spb_verbose);
1411 tony 33 if FPageSize > 0 then
1412 tony 45 SRB.Add(isc_spb_res_page_size).AsInteger := FPageSize;
1413 tony 33 if FPageBuffers > 0 then
1414 tony 45 SRB.Add(isc_spb_res_buffers).AsInteger := FPageBuffers;
1415     if BackupFileLocation = flServerSide then
1416 tony 33 for i := 0 to FBackupFile.Count - 1 do
1417     begin
1418     if (Trim(FBackupFile[i]) = '') then continue;
1419     if (Pos('=', FBackupFile[i]) <> 0) then {mbcs ok}
1420     begin
1421 tony 45 SRB.Add(isc_spb_bkp_file).AsString := FBackupFile.Names[i];
1422 tony 33 value := Copy(FBackupFile[i], Pos('=', FBackupFile[i]) + 1, Length(FBackupFile.Names[i])); {mbcs ok}
1423 tony 45 SRB.Add(isc_spb_bkp_length).AsInteger := StrToInt(value);;
1424 tony 33 end
1425     else
1426 tony 45 SRB.Add(isc_spb_bkp_file).AsString := FBackupFile[i];
1427     end
1428     else
1429     SRB.Add(isc_spb_bkp_file).AsString := 'stdin';
1430    
1431 tony 33 for i := 0 to FDatabaseName.Count - 1 do
1432     begin
1433     if (Trim(FDatabaseName[i]) = '') then continue;
1434     if (Pos('=', FDatabaseName[i]) <> 0) then {mbcs ok}
1435 tony 45 begin
1436     SRB.Add(isc_spb_dbname).AsString := FDatabaseName.Names[i];
1437 tony 33 value := Copy(FDatabaseName[i], Pos('=', FDatabaseName[i]) + 1, Length(FDatabaseName[i])); {mbcs ok}
1438 tony 45 SRB.Add(isc_spb_res_length).AsInteger := StrToInt(value);
1439 tony 33 end
1440     else
1441 tony 45 SRB.Add(isc_spb_dbname).AsString := FDatabaseName[i];
1442 tony 33 end;
1443     end;
1444    
1445     constructor TIBRestoreService.Create(AOwner: TComponent);
1446     begin
1447     inherited Create(AOwner);
1448     FDatabaseName := TStringList.Create;
1449     FBackupFile := TStringList.Create;
1450     Include (FOptions, CreateNewDB);
1451     end;
1452    
1453     destructor TIBRestoreService.Destroy;
1454     begin
1455     FDatabaseName.Free;
1456     FBackupFile.Free;
1457     inherited Destroy;
1458     end;
1459    
1460 tony 45 function TIBRestoreService.SendNextChunk(stream: TStream; var line: String
1461     ): integer;
1462     var
1463     i: Integer;
1464     begin
1465     Result := 0;
1466     line := '';
1467     if (FEof = True) then
1468     exit;
1469    
1470     if (FAction = 0) then
1471     IBError(ibxeQueryParamsError, [nil]);
1472    
1473     SRB.Add(isc_info_svc_line);
1474     SRB.Add(isc_info_svc_stdin);
1475    
1476     SQPB.Add(isc_info_svc_timeout).AsInteger := 1;
1477     if FSendBytes > 0 then
1478     Result := SQPB.Add(isc_info_svc_line).CopyFrom(stream,FSendBytes);
1479     InternalServiceQuery;
1480    
1481     FSendBytes := 0;
1482     for i := 0 to FServiceQueryResults.Count - 1 do
1483     with FServiceQueryResults[i] do
1484     begin
1485     case getItemType of
1486     isc_info_svc_line:
1487     line := AsString;
1488    
1489     isc_info_svc_stdin:
1490     FSendBytes := AsInteger;
1491    
1492     isc_info_svc_timeout,
1493     isc_info_data_not_ready:
1494     {ignore};
1495     else
1496     IBError(ibxeOutputParsingError, [getItemType]);
1497     end;
1498     end;
1499     FEOF := (FSendBytes = 0) and (line = '');
1500     end;
1501    
1502 tony 33 procedure TIBRestoreService.SetBackupFile(const Value: TStrings);
1503     begin
1504     FBackupFile.Assign(Value);
1505     end;
1506    
1507     procedure TIBRestoreService.SetDatabaseName(const Value: TStrings);
1508     begin
1509     FDatabaseName.Assign(Value);
1510     end;
1511    
1512     { TIBValidationService }
1513     constructor TIBValidationService.Create(AOwner: TComponent);
1514     begin
1515     inherited Create(AOwner);
1516     end;
1517    
1518     destructor TIBValidationService.Destroy;
1519     var
1520     i : Integer;
1521     begin
1522     for i := 0 to High(FLimboTransactionInfo) do
1523     FLimboTransactionInfo[i].Free;
1524     FLimboTransactionInfo := nil;
1525     inherited Destroy;
1526     end;
1527    
1528     procedure TIBValidationService.FetchLimboTransactionInfo;
1529 tony 45
1530     procedure NextLimboTransaction(index: integer);
1531     begin
1532     SetLength(FLimboTransactionInfo, index+1);
1533     FLimboTransactionInfo[index] := TLimboTransactionInfo.Create;
1534     { if no advice commit as default }
1535     FLimboTransactionInfo[index].Advise := UnknownAdvise;
1536     FLimboTransactionInfo[index].Action:= CommitAction;
1537     end;
1538    
1539 tony 33 var
1540 tony 45 i,j, k: Integer;
1541 tony 33 Value: Char;
1542     begin
1543     for i := 0 to High(FLimboTransactionInfo) do
1544     FLimboTransactionInfo[i].Free;
1545 tony 45 SetLength(FLimboTransactionInfo,0);
1546    
1547     SRB.Add(isc_info_svc_limbo_trans);
1548     InternalServiceQuery;
1549    
1550     k := -1;
1551     for i := 0 to FServiceQueryResults.Count - 1 do
1552     with FServiceQueryResults[i] do
1553     case getItemType of
1554     isc_info_svc_limbo_trans:
1555 tony 33 begin
1556 tony 45 if FServiceQueryResults[i].Count = 0 then continue;
1557     NextLimboTransaction(0);
1558     for j := 0 to FServiceQueryResults[i].Count - 1 do
1559 tony 33 begin
1560 tony 45 with FServiceQueryResults[i][j] do
1561     begin
1562     case getItemType of
1563     isc_spb_single_tra_id:
1564     begin
1565     Inc(k);
1566     if k > 0 then
1567     NextLimboTransaction(k);
1568     FLimboTransactionInfo[k].MultiDatabase := False;
1569     FLimboTransactionInfo[k].ID := AsInteger;
1570     end;
1571    
1572     isc_spb_multi_tra_id:
1573     begin
1574     Inc(k);
1575     if k > 0 then
1576     NextLimboTransaction(k);
1577     FLimboTransactionInfo[k].MultiDatabase := True;
1578     FLimboTransactionInfo[k].ID := AsInteger;
1579     end;
1580    
1581     isc_spb_tra_host_site:
1582     FLimboTransactionInfo[k].HostSite := AsString;
1583    
1584     isc_spb_tra_state:
1585     case AsByte of
1586     isc_spb_tra_state_limbo:
1587     FLimboTransactionInfo[k].State := LimboState;
1588    
1589     isc_spb_tra_state_commit:
1590     FLimboTransactionInfo[k].State := CommitState;
1591    
1592     isc_spb_tra_state_rollback:
1593     FLimboTransactionInfo[k].State := RollbackState;
1594    
1595     else
1596     FLimboTransactionInfo[k].State := UnknownState;
1597     end;
1598    
1599     isc_spb_tra_remote_site:
1600     FLimboTransactionInfo[k].RemoteSite := AsString;
1601    
1602     isc_spb_tra_db_path:
1603     FLimboTransactionInfo[k].RemoteDatabasePath := AsString;
1604    
1605     isc_spb_tra_advise:
1606     with FLimboTransactionInfo[k] do
1607     begin
1608     case (AsByte) of
1609     isc_spb_tra_advise_commit:
1610     begin
1611     Advise := CommitAdvise;
1612     Action:= CommitAction;
1613     end;
1614    
1615     isc_spb_tra_advise_rollback:
1616     begin
1617     Advise := RollbackAdvise;
1618     Action := RollbackAction;
1619     end;
1620    
1621     else
1622     Advise := UnknownAdvise;
1623     end;
1624     end;
1625    
1626 tony 33 else
1627 tony 45 IBError(ibxeOutputParsingError, [getItemType]);
1628 tony 33 end;
1629 tony 45 end;
1630 tony 33 end;
1631     end;
1632 tony 45 else
1633     IBError(ibxeOutputParsingError, [getItemType]);
1634 tony 33 end;
1635     end;
1636    
1637     procedure TIBValidationService.FixLimboTransactionErrors;
1638     var
1639     i: Integer;
1640     begin
1641 tony 45 SRB.Add(isc_action_svc_repair);
1642     SRB.Add(isc_spb_dbname).AsString := FDatabaseName;
1643     case FGlobalAction of
1644     NoGlobalAction:
1645 tony 33 begin
1646 tony 45 for i := 0 to LimboTransactionInfoCount - 1 do
1647     begin
1648     if (FLimboTransactionInfo[i].Action = CommitAction) then
1649     SRB.Add(isc_spb_rpr_commit_trans).AsInteger := FLimboTransactionInfo[i].ID
1650     else
1651     SRB.Add(isc_spb_rpr_rollback_trans).AsInteger := FLimboTransactionInfo[i].ID;
1652     end;
1653 tony 33 end;
1654 tony 45
1655     CommitGlobal:
1656     begin
1657     for i := 0 to LimboTransactionInfoCount - 1 do
1658     SRB.Add(isc_spb_rpr_commit_trans).AsInteger := FLimboTransactionInfo[i].ID;
1659     end;
1660    
1661     RollbackGlobal:
1662 tony 33 begin
1663 tony 45 for i := 0 to LimboTransactionInfoCount - 1 do
1664     SRB.Add(isc_spb_rpr_rollback_trans).AsInteger := FLimboTransactionInfo[i].ID;
1665 tony 33 end;
1666 tony 45
1667     RecoverTwoPhaseGlobal:
1668     begin
1669     for i := 0 to LimboTransactionInfoCount - 1 do
1670     SRB.Add(isc_spb_rpr_recover_two_phase).AsInteger := FLimboTransactionInfo[i].ID;
1671     end;
1672 tony 33 end;
1673     InternalServiceStart;
1674     end;
1675    
1676     function TIBValidationService.GetLimboTransactionInfo(index: integer): TLimboTransactionInfo;
1677     begin
1678     if index <= High(FLimboTransactionInfo) then
1679     result := FLimboTransactionInfo[index]
1680     else
1681     result := nil;
1682     end;
1683    
1684     function TIBValidationService.GetLimboTransactionInfoCount: integer;
1685     begin
1686 tony 45 Result := Length(FLimboTransactionInfo);
1687 tony 33 end;
1688    
1689     procedure TIBValidationService.SetDatabaseName(const Value: string);
1690     begin
1691     FDatabaseName := Value;
1692     end;
1693    
1694     procedure TIBValidationService.SetServiceStartOptions;
1695     var
1696     param: Integer;
1697     begin
1698     Action := isc_action_svc_repair;
1699     if FDatabaseName = '' then
1700     IBError(ibxeStartParamsError, [nil]);
1701 tony 45 SRB.Add(isc_action_svc_repair);
1702     SRB.Add(isc_spb_dbname).AsString := FDatabaseName;
1703 tony 33 param := 0;
1704     if (SweepDB in Options) then
1705     param := param or isc_spb_rpr_sweep_db;
1706     if (ValidateDB in Options) then
1707     param := param or isc_spb_rpr_validate_db;
1708 tony 45
1709 tony 33 if (LimboTransactions in Options) then
1710     param := param or isc_spb_rpr_list_limbo_trans;
1711     if (CheckDB in Options) then
1712     param := param or isc_spb_rpr_check_db;
1713     if (IgnoreChecksum in Options) then
1714     param := param or isc_spb_rpr_ignore_checksum;
1715     if (KillShadows in Options) then
1716     param := param or isc_spb_rpr_kill_shadows;
1717     if (MendDB in Options) then
1718     param := param or isc_spb_rpr_mend_db;
1719     if (ValidateFull in Options) then
1720     begin
1721     param := param or isc_spb_rpr_full;
1722     if not (MendDB in Options) then
1723     param := param or isc_spb_rpr_validate_db;
1724     end;
1725     if param > 0 then
1726 tony 45 SRB.Add(isc_spb_options).AsInteger := param;
1727 tony 33 end;
1728    
1729     { TIBSecurityService }
1730     constructor TIBSecurityService.Create(AOwner: TComponent);
1731     begin
1732     inherited Create(AOwner);
1733     FModifyParams := [];
1734     end;
1735    
1736     destructor TIBSecurityService.Destroy;
1737     var
1738     i : Integer;
1739     begin
1740     for i := 0 to High(FUserInfo) do
1741     FUserInfo[i].Free;
1742     FUserInfo := nil;
1743     inherited Destroy;
1744     end;
1745    
1746     procedure TIBSecurityService.FetchUserInfo;
1747     var
1748 tony 45 i, j, k: Integer;
1749 tony 33 begin
1750 tony 45 SRB.Add(isc_info_svc_get_users);
1751 tony 33 InternalServiceQuery;
1752 tony 45
1753 tony 33 for i := 0 to High(FUserInfo) do
1754     FUserInfo[i].Free;
1755 tony 45 for i := 0 to FServiceQueryResults.Count - 1 do
1756     with FServiceQueryResults[i] do
1757 tony 33 begin
1758 tony 45 case getItemType of
1759     isc_info_svc_get_users:
1760     begin
1761     SetLength(FUserInfo,1);
1762     k := 0;
1763     FUserInfo[0] := TUserInfo.Create;
1764     FUserInfo[0].UserName := '';
1765     for j := 0 to FServiceQueryResults[i].Count - 1 do
1766     begin
1767     with FServiceQueryResults[i][j] do
1768     case getItemType of
1769     isc_spb_sec_username:
1770     begin
1771     if FUserInfo[k].UserName <> '' then
1772     begin
1773     Inc(k);
1774     SetLength(FUserInfo,k+1);
1775     if FUserInfo[k] = nil then
1776     FUserInfo[k] := TUserInfo.Create;
1777     end;
1778     FUserInfo[k].UserName := AsString;
1779     end;
1780    
1781     isc_spb_sec_firstname:
1782     FUserInfo[k].FirstName := AsString;
1783    
1784     isc_spb_sec_middlename:
1785     FUserInfo[k].MiddleName := AsString;
1786    
1787     isc_spb_sec_lastname:
1788     FUserInfo[k].LastName := AsString;
1789    
1790     isc_spb_sec_userId:
1791     FUserInfo[k].UserId := AsInteger;
1792    
1793     isc_spb_sec_groupid:
1794     FUserInfo[k].GroupID := AsInteger;
1795    
1796     else
1797     IBError(ibxeOutputParsingError, [getItemType]);
1798     end;
1799     end;
1800     end;
1801     else
1802     IBError(ibxeOutputParsingError, [getItemType]);
1803     end;
1804 tony 33 end;
1805     end;
1806    
1807     function TIBSecurityService.GetUserInfo(Index: Integer): TUserInfo;
1808     begin
1809     if Index <= High(FUSerInfo) then
1810     result := FUserInfo[Index]
1811     else
1812     result := nil;
1813     end;
1814    
1815     function TIBSecurityService.GetUserInfoCount: Integer;
1816     begin
1817 tony 45 Result := Length(FUserInfo);
1818 tony 33 end;
1819    
1820     procedure TIBSecurityService.AddUser;
1821     begin
1822     SecurityAction := ActionAddUser;
1823     ServiceStart;
1824     end;
1825    
1826     procedure TIBSecurityService.DeleteUser;
1827     begin
1828     SecurityAction := ActionDeleteUser;
1829     ServiceStart;
1830     end;
1831    
1832     procedure TIBSecurityService.DisplayUsers;
1833     begin
1834     SecurityAction := ActionDisplayUser;
1835 tony 45 SRB.Add(isc_action_svc_display_user);
1836 tony 33 InternalServiceStart;
1837     FetchUserInfo;
1838     end;
1839    
1840     procedure TIBSecurityService.DisplayUser(UserName: String);
1841     begin
1842     SecurityAction := ActionDisplayUser;
1843 tony 45 SRB.Add(isc_action_svc_display_user);
1844     SRB.Add(isc_spb_sec_username).AsString := UserName;
1845 tony 33 InternalServiceStart;
1846     FetchUserInfo;
1847     end;
1848    
1849     procedure TIBSecurityService.ModifyUser;
1850     begin
1851     SecurityAction := ActionModifyUser;
1852     ServiceStart;
1853     end;
1854    
1855     procedure TIBSecurityService.SetSecurityAction (Value: TSecurityAction);
1856     begin
1857     FSecurityAction := Value;
1858     if Value = ActionDeleteUser then
1859     ClearParams;
1860     end;
1861    
1862     procedure TIBSecurityService.ClearParams;
1863     begin
1864     FModifyParams := [];
1865     FFirstName := '';
1866     FMiddleName := '';
1867     FLastName := '';
1868     FGroupID := 0;
1869     FUserID := 0;
1870     FPassword := '';
1871     end;
1872    
1873     procedure TIBSecurityService.SetFirstName (Value: String);
1874     begin
1875     FFirstName := Value;
1876     Include (FModifyParams, ModifyFirstName);
1877     end;
1878    
1879     procedure TIBSecurityService.SetMiddleName (Value: String);
1880     begin
1881     FMiddleName := Value;
1882     Include (FModifyParams, ModifyMiddleName);
1883     end;
1884    
1885     procedure TIBSecurityService.SetLastName (Value: String);
1886     begin
1887     FLastName := Value;
1888     Include (FModifyParams, ModifyLastName);
1889     end;
1890    
1891     procedure TIBSecurityService.SetPassword (Value: String);
1892     begin
1893     FPassword := Value;
1894     Include (FModifyParams, ModifyPassword);
1895     end;
1896    
1897     procedure TIBSecurityService.SetUserId (Value: Integer);
1898     begin
1899     FUserId := Value;
1900     Include (FModifyParams, ModifyUserId);
1901     end;
1902    
1903     procedure TIBSecurityService.SetGroupId (Value: Integer);
1904     begin
1905     FGroupId := Value;
1906     Include (FModifyParams, ModifyGroupId);
1907     end;
1908    
1909     procedure TIBSecurityService.Loaded;
1910     begin
1911     inherited Loaded;
1912     ClearParams;
1913     end;
1914    
1915     procedure TIBSecurityService.SetServiceStartOptions;
1916     var
1917     Len: UShort;
1918    
1919     begin
1920     case FSecurityAction of
1921     ActionAddUser:
1922     begin
1923     Action := isc_action_svc_add_user;
1924     if ( Pos(' ', FUserName) > 0 ) then
1925     IBError(ibxeStartParamsError, [nil]);
1926     Len := Length(FUserName);
1927     if (Len = 0) then
1928     IBError(ibxeStartParamsError, [nil]);
1929 tony 45 SRB.Add(isc_action_svc_add_user);
1930     SRB.Add(isc_spb_sec_username).AsString := FUserName;
1931     SRB.Add(isc_spb_sql_role_name).AsString := FSQLRole;
1932     SRB.Add(isc_spb_sec_userid).AsInteger := FUserID;
1933     SRB.Add(isc_spb_sec_groupid).AsInteger := FGroupID;
1934     SRB.Add(isc_spb_sec_password).AsString := FPassword;
1935     SRB.Add(isc_spb_sec_firstname).AsString := FFirstName;
1936     SRB.Add(isc_spb_sec_middlename).AsString := FMiddleName;
1937     SRB.Add(isc_spb_sec_lastname).AsString := FLastName;
1938 tony 33 end;
1939     ActionDeleteUser:
1940     begin
1941     Action := isc_action_svc_delete_user;
1942     Len := Length(FUserName);
1943     if (Len = 0) then
1944     IBError(ibxeStartParamsError, [nil]);
1945 tony 45 SRB.Add(isc_action_svc_delete_user);
1946     SRB.Add(isc_spb_sec_username).AsString := FUserName;
1947     SRB.Add(isc_spb_sql_role_name).AsString := FSQLRole;
1948 tony 33 end;
1949     ActionModifyUser:
1950     begin
1951     Action := isc_action_svc_modify_user;
1952     Len := Length(FUserName);
1953     if (Len = 0) then
1954     IBError(ibxeStartParamsError, [nil]);
1955 tony 45 SRB.Add(isc_action_svc_modify_user);
1956     SRB.Add(isc_spb_sec_username).AsString := FUserName;
1957     SRB.Add(isc_spb_sql_role_name).AsString := FSQLRole;
1958 tony 33 if (ModifyUserId in FModifyParams) then
1959 tony 45 SRB.Add(isc_spb_sec_userid).AsInteger := FUserID;
1960 tony 33 if (ModifyGroupId in FModifyParams) then
1961 tony 45 SRB.Add(isc_spb_sec_groupid).AsInteger := FGroupID;
1962 tony 33 if (ModifyPassword in FModifyParams) then
1963 tony 45 SRB.Add(isc_spb_sec_password).AsString := FPassword;
1964 tony 33 if (ModifyFirstName in FModifyParams) then
1965 tony 45 SRB.Add(isc_spb_sec_firstname).AsString := FFirstName;
1966 tony 33 if (ModifyMiddleName in FModifyParams) then
1967 tony 45 SRB.Add(isc_spb_sec_middlename).AsString := FMiddleName;
1968 tony 33 if (ModifyLastName in FModifyParams) then
1969 tony 45 SRB.Add(isc_spb_sec_lastname).AsString := FLastName;
1970 tony 33 end;
1971     end;
1972     ClearParams;
1973     end;
1974    
1975     { TIBUnStructuredService }
1976 tony 45 constructor TIBControlAndQueryService.create(AOwner: TComponent);
1977 tony 33 begin
1978     inherited Create(AOwner);
1979     FEof := False;
1980     FAction := 0;
1981     end;
1982    
1983     procedure TIBControlAndQueryService.SetAction(Value: Integer);
1984     begin
1985     FEof := False;
1986     FAction := Value;
1987     end;
1988    
1989    
1990     function TIBControlAndQueryService.GetNextChunk: String;
1991     var
1992 tony 45 i: Integer;
1993 tony 33 begin
1994     if (FEof = True) then
1995     begin
1996     result := '';
1997     exit;
1998     end;
1999     if (FAction = 0) then
2000     IBError(ibxeQueryParamsError, [nil]);
2001 tony 45
2002     SRB.Add(isc_info_svc_to_eof);
2003 tony 33 InternalServiceQuery;
2004 tony 45
2005     FEof := True;
2006     for i := 0 to FServiceQueryResults.Count - 1 do
2007     with FServiceQueryResults[i] do
2008     begin
2009     case getItemType of
2010     isc_info_svc_to_eof:
2011     Result := AsString;
2012    
2013     isc_info_truncated:
2014     FEof := False;
2015 tony 33 else
2016 tony 45 IBError(ibxeOutputParsingError, [getItemType]);
2017     end;
2018     end;
2019 tony 33 end;
2020    
2021 tony 45 function TIBControlAndQueryService.WriteNextChunk(stream: TStream): integer;
2022     var
2023     i: Integer;
2024     begin
2025     result := 0;
2026     if (FEof = True) then
2027     exit;
2028     if (FAction = 0) then
2029     IBError(ibxeQueryParamsError, [nil]);
2030    
2031     SQPB.Add(isc_info_svc_timeout).AsInteger := 1;
2032     SRB.Add(isc_info_svc_to_eof);
2033     InternalServiceQuery;
2034    
2035     FEof := True;
2036     for i := 0 to FServiceQueryResults.Count - 1 do
2037     with FServiceQueryResults[i] do
2038     begin
2039     case getItemType of
2040     isc_info_svc_to_eof:
2041     begin
2042     Result := CopyTo(stream,0);
2043     FEof := Result = 0;
2044     end;
2045    
2046     isc_info_truncated:
2047     FEof := False;
2048    
2049     isc_info_svc_timeout:
2050     {ignore};
2051     else
2052     IBError(ibxeOutputParsingError, [getItemType]);
2053     end;
2054     end;
2055     end;
2056    
2057 tony 33 function TIBControlAndQueryService.GetNextLine: String;
2058     var
2059 tony 45 i: Integer;
2060 tony 33 begin
2061 tony 45 Result := '';
2062 tony 33 if (FEof = True) then
2063     exit;
2064 tony 45
2065 tony 33 if (FAction = 0) then
2066     IBError(ibxeQueryParamsError, [nil]);
2067 tony 45
2068     SRB.Add(isc_info_svc_line);
2069 tony 33 InternalServiceQuery;
2070 tony 45
2071     for i := 0 to FServiceQueryResults.Count - 1 do
2072     with FServiceQueryResults[i] do
2073 tony 33 begin
2074 tony 45 case getItemType of
2075     isc_info_svc_line:
2076     Result := AsString;
2077     else
2078     IBError(ibxeOutputParsingError, [getItemType]);
2079     end;
2080 tony 33 end;
2081 tony 45 FEOF := Result = '';
2082 tony 33 end;
2083    
2084     { TIBLogService }
2085    
2086     procedure TIBLogService.SetServiceStartOptions;
2087     begin
2088     Action := isc_action_svc_get_ib_log;
2089 tony 45 SRB.Add(isc_action_svc_get_ib_log);
2090 tony 33 end;
2091    
2092     { TDatabaseInfo }
2093    
2094     constructor TDatabaseInfo.Create;
2095     begin
2096     DbName := nil;
2097     end;
2098    
2099     destructor TDatabaseInfo.Destroy;
2100     begin
2101     DbName := nil;
2102     inherited Destroy;
2103     end;
2104    
2105     { TLicenseInfo }
2106    
2107     constructor TLicenseInfo.Create;
2108     begin
2109     Key := nil;
2110     Id := nil;
2111     Desc := nil;
2112     end;
2113    
2114     destructor TLicenseInfo.Destroy;
2115     begin
2116     Key := nil;
2117     Id := nil;
2118     Desc := nil;
2119     inherited Destroy;
2120     end;
2121    
2122     { TConfigFileData }
2123    
2124     constructor TConfigFileData.Create;
2125     begin
2126     ConfigFileValue := nil;
2127     ConfigFileKey := nil;
2128     end;
2129    
2130     destructor TConfigFileData.Destroy;
2131     begin
2132     ConfigFileValue := nil;
2133     ConfigFileKey := nil;
2134     inherited Destroy;
2135     end;
2136    
2137     { TConfigParams }
2138    
2139     constructor TConfigParams.Create;
2140     begin
2141     ConfigFileData := TConfigFileData.Create;
2142     ConfigFileParams := nil;
2143     end;
2144    
2145     destructor TConfigParams.Destroy;
2146     begin
2147     ConfigFileData.Free;
2148     ConfigFileParams := nil;
2149     inherited Destroy;
2150     end;
2151    
2152     end.