{************************************************************************}
{ }
{ Borland Delphi Visual Component Library }
{ InterBase Express core components }
{ }
{ Copyright (c) 1998-2001 Borland Software Corporation }
{ }
{ InterBase Express is based in part on the product }
{ Free IB Components, written by Gregory H. Deatz for }
{ Hoagland, Longo, Moran, Dunst & Doukas Company. }
{ Free IB Components is used under license. }
{ }
{ The contents of this file are subject to the InterBase }
{ Public License Version 1.0 (the "License"); you may not }
{ use this file except in compliance with the License. You may obtain }
{ a copy of the License at http://www.borland.com/interbase/IPL.html }
{ Software distributed under the License is distributed on }
{ an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either }
{ express or implied. See the License for the specific language }
{ governing rights and limitations under the License. }
{ The Original Code was created by InterBase Software Corporation }
{ and its successors. }
{ Portions created by Borland Software Corporation are Copyright }
{ (C) Borland Software Corporation. All Rights Reserved. }
{ Contributor(s): Jeff Overcash }
{ }
{************************************************************************}
{
InterBase Express provides component interfaces to
functions introduced in InterBase 6.0. The Services
components (TIB*Service, TIBServerProperties) and
Install components (TIBInstall, TIBUninstall, TIBSetup)
function only if you have installed InterBase 6.0 or
later software
}
unit IBServices;
interface
uses
SysUtils, Classes,
Controls, Forms,
IBDialogs, IBHeader, IB, IBExternals;
const
DefaultBufferSize = 32000;
SPBPrefix = 'isc_spb_';
SPBConstantNames: array[1..isc_spb_last_spb_constant] of String = (
'user_name',
'sys_user_name',
'sys_user_name_enc',
'password',
'password_enc',
'command_line',
'db_name',
'verbose',
'options',
'connect_timeout',
'dummy_packet_interval',
'sql_role_name'
);
SPBConstantValues: array[1..isc_spb_last_spb_constant] of Integer = (
isc_spb_user_name_mapped_to_server,
isc_spb_sys_user_name_mapped_to_server,
isc_spb_sys_user_name_enc_mapped_to_server,
isc_spb_password_mapped_to_server,
isc_spb_password_enc_mapped_to_server,
isc_spb_command_line_mapped_to_server,
isc_spb_dbname_mapped_to_server,
isc_spb_verbose_mapped_to_server,
isc_spb_options_mapped_to_server,
isc_spb_connect_timeout_mapped_to_server,
isc_spb_dummy_packet_interval_mapped_to_server,
isc_spb_sql_role_name_mapped_to_server
);
type
TProtocol = (TCP, SPX, NamedPipe, Local);
TOutputBufferOption = (ByLine, ByChunk);
TIBCustomService = class;
TLoginEvent = procedure(Database: TIBCustomService;
LoginParams: TStrings) of object;
TIBCustomService = class(TComponent)
private
FIBLoaded: Boolean;
FParamsChanged : Boolean;
FSPB, FQuerySPB : PChar;
FSPBLength, FQuerySPBLength : Short;
FTraceFlags: TTraceFlags;
FOnLogin: TLoginEvent;
FLoginPrompt: Boolean;
FBufferSize: Integer;
FOutputBuffer: PChar;
FQueryParams: String;
FServerName: string;
FHandle: TISC_SVC_HANDLE;
FStreamedActive : Boolean;
FOnAttach: TNotifyEvent;
FOutputBufferOption: TOutputBufferOption;
FProtocol: TProtocol;
FParams: TStrings;
function GetActive: Boolean;
function GetServiceParamBySPB(const Idx: Integer): String;
procedure SetActive(const Value: Boolean);
procedure SetBufferSize(const Value: Integer);
procedure SetParams(const Value: TStrings);
procedure SetServerName(const Value: string);
procedure SetProtocol(const Value: TProtocol);
procedure SetServiceParamBySPB(const Idx: Integer;
const Value: String);
function IndexOfSPBConst(st: String): Integer;
procedure ParamsChange(Sender: TObject);
procedure ParamsChanging(Sender: TObject);
procedure CheckServerName;
function Call(ErrCode: ISC_STATUS; RaiseError: Boolean): ISC_STATUS;
function ParseString(var RunLen: Integer): string;
function ParseInteger(var RunLen: Integer): Integer;
procedure GenerateSPB(sl: TStrings; var SPB: String; var SPBLength: Short);
protected
procedure Loaded; override;
function Login: Boolean;
procedure CheckActive;
procedure CheckInactive;
property OutputBuffer : PChar read FOutputBuffer;
property OutputBufferOption : TOutputBufferOption read FOutputBufferOption write FOutputBufferOption;
property BufferSize : Integer read FBufferSize write SetBufferSize default DefaultBufferSize;
procedure InternalServiceQuery;
property ServiceQueryParams: String read FQueryParams write FQueryParams;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Attach;
procedure Detach;
property Handle: TISC_SVC_HANDLE read FHandle;
property ServiceParamBySPB[const Idx: Integer]: String read GetServiceParamBySPB
write SetServiceParamBySPB;
published
property Active: Boolean read GetActive write SetActive default False;
property ServerName: string read FServerName write SetServerName;
property Protocol: TProtocol read FProtocol write SetProtocol default Local;
property Params: TStrings read FParams write SetParams;
property LoginPrompt: Boolean read FLoginPrompt write FLoginPrompt default True;
property TraceFlags: TTraceFlags read FTraceFlags write FTraceFlags;
property OnAttach: TNotifyEvent read FOnAttach write FOnAttach;
property OnLogin: TLoginEvent read FOnLogin write FOnLogin;
end;
TDatabaseInfo = class
public
NoOfAttachments: Integer;
NoOfDatabases: Integer;
DbName: array of string;
constructor Create;
destructor Destroy; override;
end;
TLicenseInfo = class
public
Key: array of string;
Id: array of string;
Desc: array of string;
LicensedUsers: Integer;
constructor Create;
destructor Destroy; override;
end;
TLicenseMaskInfo = class
public
LicenseMask: Integer;
CapabilityMask: Integer;
end;
TConfigFileData = class
public
ConfigFileValue: array of integer;
ConfigFileKey: array of integer;
constructor Create;
destructor Destroy; override;
end;
TConfigParams = class
public
ConfigFileData: TConfigFileData;
ConfigFileParams: array of string;
BaseLocation: string;
LockFileLocation: string;
MessageFileLocation: string;
SecurityDatabaseLocation: string;
constructor Create;
destructor Destroy; override;
end;
TVersionInfo = class
ServerVersion: String;
ServerImplementation: string;
ServiceVersion: Integer;
end;
TPropertyOption = (Database, License, LicenseMask, ConfigParameters, Version);
TPropertyOptions = set of TPropertyOption;
TIBServerProperties = class(TIBCustomService)
private
FOptions: TPropertyOptions;
FDatabaseInfo: TDatabaseInfo;
FLicenseInfo: TLicenseInfo;
FLicenseMaskInfo: TLicenseMaskInfo;
FVersionInfo: TVersionInfo;
FConfigParams: TConfigParams;
procedure ParseConfigFileData(var RunLen: Integer);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Fetch;
procedure FetchDatabaseInfo;
procedure FetchLicenseInfo;
procedure FetchLicenseMaskInfo;
procedure FetchConfigParams;
procedure FetchVersionInfo;
property DatabaseInfo: TDatabaseInfo read FDatabaseInfo;
property LicenseInfo: TLicenseInfo read FLicenseInfo;
property LicenseMaskInfo: TLicenseMaskInfo read FLicenseMaskInfo;
property VersionInfo: TVersionInfo read FVersionInfo;
property ConfigParams: TConfigParams read FConfigParams;
published
property Options : TPropertyOptions read FOptions