1 |
(*
|
2 |
* Firebird Interface (fbintf). The fbintf components provide a set of
|
3 |
* Pascal language bindings for the Firebird API.
|
4 |
*
|
5 |
* The contents of this file are subject to the Initial Developer's
|
6 |
* Public License Version 1.0 (the "License"); you may not use this
|
7 |
* file except in compliance with the License. You may obtain a copy
|
8 |
* of the License here:
|
9 |
*
|
10 |
* http://www.firebirdsql.org/index.php?op=doc&id=idpl
|
11 |
*
|
12 |
* Software distributed under the License is distributed on an "AS
|
13 |
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
14 |
* implied. See the License for the specific language governing rights
|
15 |
* and limitations under the License.
|
16 |
*
|
17 |
* The Initial Developer of the Original Code is Tony Whyman.
|
18 |
*
|
19 |
* The Original Code is (C) 2016 Tony Whyman, MWA Software
|
20 |
* (http://www.mwasoftware.co.uk).
|
21 |
*
|
22 |
* All Rights Reserved.
|
23 |
*
|
24 |
* Contributor(s): ______________________________________.
|
25 |
*
|
26 |
*)
|
27 |
unit FB30Services;
|
28 |
{$IFDEF MSWINDOWS}
|
29 |
{$DEFINE WINDOWS}
|
30 |
{$ENDIF}
|
31 |
|
32 |
{$IFDEF FPC}
|
33 |
{$mode delphi}
|
34 |
{$interfaces COM}
|
35 |
{$ENDIF}
|
36 |
|
37 |
interface
|
38 |
|
39 |
uses
|
40 |
Classes, SysUtils, Firebird, IB, FB30ClientAPI, FBParamBlock, FBOutputBlock,
|
41 |
FBServices;
|
42 |
|
43 |
type
|
44 |
{ TFBServiceManager }
|
45 |
|
46 |
TFB30ServiceManager = class(TFBServiceManager,IServiceManager)
|
47 |
private
|
48 |
FServiceIntf: Firebird.IService;
|
49 |
procedure CheckActive;
|
50 |
procedure CheckInactive;
|
51 |
protected
|
52 |
procedure InternalAttach(ConnectString: AnsiString); override;
|
53 |
public
|
54 |
property ServiceIntf: Firebird.IService read FServiceIntf;
|
55 |
|
56 |
public
|
57 |
{IServiceManager}
|
58 |
procedure Detach(Force: boolean=false); override;
|
59 |
function IsAttached: boolean;
|
60 |
procedure Start(Request: ISRB);
|
61 |
function Query(SQPB: ISQPB; Request: ISRB): IServiceQueryResults; override;
|
62 |
end;
|
63 |
|
64 |
implementation
|
65 |
|
66 |
uses FBMessages;
|
67 |
|
68 |
{ TFBServiceManager }
|
69 |
|
70 |
procedure TFB30ServiceManager.CheckActive;
|
71 |
begin
|
72 |
if FServiceIntf = nil then
|
73 |
IBError(ibxeServiceActive, [nil]);
|
74 |
end;
|
75 |
|
76 |
procedure TFB30ServiceManager.CheckInactive;
|
77 |
begin
|
78 |
if FServiceIntf <> nil then
|
79 |
IBError(ibxeServiceInActive, [nil]);
|
80 |
end;
|
81 |
|
82 |
procedure TFB30ServiceManager.InternalAttach(ConnectString: AnsiString);
|
83 |
begin
|
84 |
with Firebird30ClientAPI do
|
85 |
if FSPB = nil then
|
86 |
begin
|
87 |
FServiceIntf := ProviderIntf.attachServiceManager(StatusIntf, PAnsiChar(ConnectString), 0, nil);
|
88 |
Check4DataBaseError;
|
89 |
end
|
90 |
else
|
91 |
begin
|
92 |
FServiceIntf := ProviderIntf.attachServiceManager(StatusIntf,
|
93 |
PAnsiChar(ConnectString),
|
94 |
(FSPB as TSPB).getDataLength,
|
95 |
BytePtr((FSPB as TSPB).getBuffer));
|
96 |
Check4DataBaseError;
|
97 |
end;
|
98 |
end;
|
99 |
|
100 |
procedure TFB30ServiceManager.Detach(Force: boolean);
|
101 |
begin
|
102 |
if FServiceIntf = nil then
|
103 |
Exit;
|
104 |
with Firebird30ClientAPI do
|
105 |
begin
|
106 |
FServiceIntf.detach(StatusIntf);
|
107 |
if not Force and InErrorState then
|
108 |
IBDataBaseError;
|
109 |
FServiceIntf := nil;
|
110 |
end;
|
111 |
end;
|
112 |
|
113 |
function TFB30ServiceManager.IsAttached: boolean;
|
114 |
begin
|
115 |
Result := FServiceIntf <> nil;
|
116 |
end;
|
117 |
|
118 |
procedure TFB30ServiceManager.Start(Request: ISRB);
|
119 |
begin
|
120 |
CheckActive;
|
121 |
with Firebird30ClientAPI do
|
122 |
begin
|
123 |
FServiceIntf.Start(StatusIntf,
|
124 |
(Request as TSRB).getDataLength,
|
125 |
BytePtr((Request as TSRB).getBuffer));
|
126 |
Check4DataBaseError;
|
127 |
end;
|
128 |
end;
|
129 |
|
130 |
function TFB30ServiceManager.Query(SQPB: ISQPB; Request: ISRB
|
131 |
): IServiceQueryResults;
|
132 |
var QueryResults: TServiceQueryResults;
|
133 |
begin
|
134 |
CheckActive;
|
135 |
QueryResults := TServiceQueryResults.Create;
|
136 |
Result := QueryResults;
|
137 |
with Firebird30ClientAPI do
|
138 |
begin
|
139 |
if SQPB <> nil then
|
140 |
begin
|
141 |
FServiceIntf.query(StatusIntf,
|
142 |
(SQPB as TSQPB).getDataLength,
|
143 |
BytePtr((SQPB as TSQPB).getBuffer),
|
144 |
(Request as TSRB).getDataLength,
|
145 |
BytePtr((Request as TSRB).getBuffer),
|
146 |
QueryResults.getBufSize,
|
147 |
BytePtr(QueryResults.Buffer));
|
148 |
Check4DataBaseError;
|
149 |
end
|
150 |
else
|
151 |
FServiceIntf.query(StatusIntf, 0, nil,
|
152 |
(Request as TSRB).getDataLength,
|
153 |
BytePtr((Request as TSRB).getBuffer),
|
154 |
QueryResults.getBufSize,
|
155 |
BytePtr(QueryResults.Buffer));
|
156 |
Check4DataBaseError;
|
157 |
end;
|
158 |
end;
|
159 |
|
160 |
end.
|
161 |
|