ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/runtime/IBServices.pas
Revision: 80
Committed: Mon Jan 1 11:31:07 2018 UTC (6 years, 10 months ago) by tony
Content type: text/x-pascal
File size: 60346 byte(s)
Log Message:
Fixes merged into public release

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