1 |
tony |
45 |
(* |
2 |
|
|
* Firebird Interface (fbintf). The fbintf components provide a set of |
3 |
|
|
* Pascal language bindings for the Firebird API. Although predominantly |
4 |
|
|
* a new development they include source code taken from IBX and may be |
5 |
|
|
* considered a derived product. This software thus also includes the copyright |
6 |
|
|
* notice and license conditions from IBX. |
7 |
|
|
* |
8 |
|
|
* Except for those parts dervied from IBX, contents of this file are subject |
9 |
|
|
* to the Initial Developer's Public License Version 1.0 (the "License"); you |
10 |
|
|
* may not use this file except in compliance with the License. You may obtain a |
11 |
|
|
* copy of the License here: |
12 |
|
|
* |
13 |
|
|
* http://www.firebirdsql.org/index.php?op=doc&id=idpl |
14 |
|
|
* |
15 |
|
|
* Software distributed under the License is distributed on an "AS |
16 |
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or |
17 |
|
|
* implied. See the License for the specific language governing rights |
18 |
|
|
* and limitations under the License. |
19 |
|
|
* |
20 |
|
|
* The Initial Developer of the Original Code is Tony Whyman. |
21 |
|
|
* |
22 |
|
|
* The Original Code is (C) 2016 Tony Whyman, MWA Software |
23 |
|
|
* (http://www.mwasoftware.co.uk). |
24 |
|
|
* |
25 |
|
|
* All Rights Reserved. |
26 |
|
|
* |
27 |
|
|
* Contributor(s): ______________________________________. |
28 |
|
|
* |
29 |
|
|
*) |
30 |
|
|
{************************************************************************} |
31 |
|
|
{ } |
32 |
|
|
{ Borland Delphi Visual Component Library } |
33 |
|
|
{ InterBase Express core components } |
34 |
|
|
{ } |
35 |
|
|
{ Copyright (c) 1998-2000 Inprise Corporation } |
36 |
|
|
{ } |
37 |
|
|
{ InterBase Express is based in part on the product } |
38 |
|
|
{ Free IB Components, written by Gregory H. Deatz for } |
39 |
|
|
{ Hoagland, Longo, Moran, Dunst & Doukas Company. } |
40 |
|
|
{ Free IB Components is used under license. } |
41 |
|
|
{ } |
42 |
|
|
{ The contents of this file are subject to the InterBase } |
43 |
|
|
{ Public License Version 1.0 (the "License"); you may not } |
44 |
|
|
{ use this file except in compliance with the License. You } |
45 |
|
|
{ may obtain a copy of the License at http://www.Inprise.com/IPL.html } |
46 |
|
|
{ Software distributed under the License is distributed on } |
47 |
|
|
{ an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either } |
48 |
|
|
{ express or implied. See the License for the specific language } |
49 |
|
|
{ governing rights and limitations under the License. } |
50 |
|
|
{ The Original Code was created by InterBase Software Corporation } |
51 |
|
|
{ and its successors. } |
52 |
|
|
{ Portions created by Inprise Corporation are Copyright (C) Inprise } |
53 |
|
|
{ Corporation. All Rights Reserved. } |
54 |
|
|
{ Contributor(s): Jeff Overcash } |
55 |
|
|
{ } |
56 |
|
|
{ IBX For Lazarus (Firebird Express) } |
57 |
|
|
{ Contributor: Tony Whyman, MWA Software http://www.mwasoftware.co.uk } |
58 |
|
|
{ Portions created by MWA Software are copyright McCallum Whyman } |
59 |
|
|
{ Associates Ltd 2011 - 2015 } |
60 |
|
|
{ } |
61 |
|
|
{************************************************************************} |
62 |
|
|
unit FB25Services; |
63 |
|
|
|
64 |
|
|
{$IFDEF FPC} |
65 |
|
|
{$mode objfpc}{$H+} |
66 |
|
|
{$interfaces COM} |
67 |
|
|
{$ENDIF} |
68 |
|
|
|
69 |
|
|
interface |
70 |
|
|
|
71 |
|
|
uses |
72 |
|
|
Classes, SysUtils, IB, FB25ClientAPI, IBHeader, FBParamBlock, FBOutputBlock, |
73 |
|
|
FBServices; |
74 |
|
|
|
75 |
|
|
type |
76 |
|
|
{ TFBServiceManager } |
77 |
|
|
|
78 |
|
|
TFB25ServiceManager = class(TFBServiceManager,IServiceManager) |
79 |
|
|
private |
80 |
|
|
FHandle: TISC_SVC_HANDLE; |
81 |
|
|
procedure CheckActive; |
82 |
|
|
procedure CheckInactive; |
83 |
|
|
protected |
84 |
|
|
procedure InternalAttach(ConnectString: string); override; |
85 |
|
|
public |
86 |
|
|
property Handle: TISC_SVC_HANDLE read FHandle; |
87 |
|
|
|
88 |
|
|
public |
89 |
|
|
{IServiceManager} |
90 |
|
|
procedure Detach(Force: boolean=false); override; |
91 |
|
|
function IsAttached: boolean; |
92 |
|
|
procedure Start(Request: ISRB); |
93 |
|
|
function Query(SQPB: ISQPB; Request: ISRB): IServiceQueryResults; override; |
94 |
|
|
end; |
95 |
|
|
|
96 |
|
|
implementation |
97 |
|
|
|
98 |
|
|
uses FBMessages; |
99 |
|
|
|
100 |
|
|
{ TFBServiceManager } |
101 |
|
|
|
102 |
|
|
procedure TFB25ServiceManager.CheckActive; |
103 |
|
|
begin |
104 |
|
|
if FHandle = nil then |
105 |
|
|
IBError(ibxeServiceActive, [nil]); |
106 |
|
|
end; |
107 |
|
|
|
108 |
|
|
procedure TFB25ServiceManager.CheckInactive; |
109 |
|
|
begin |
110 |
|
|
if FHandle <> nil then |
111 |
|
|
IBError(ibxeServiceInActive, [nil]); |
112 |
|
|
end; |
113 |
|
|
|
114 |
|
|
procedure TFB25ServiceManager.InternalAttach(ConnectString: String); |
115 |
|
|
begin |
116 |
|
|
with Firebird25ClientAPI do |
117 |
|
|
if FSPB = nil then |
118 |
|
|
begin |
119 |
|
|
if isc_service_attach(StatusVector, Length(ConnectString), |
120 |
|
|
PChar(ConnectString), @FHandle, 0, nil) > 0 then |
121 |
|
|
IBDataBaseError; |
122 |
|
|
end |
123 |
|
|
else |
124 |
|
|
begin |
125 |
|
|
if isc_service_attach(StatusVector, Length(ConnectString), |
126 |
|
|
PChar(ConnectString), @FHandle, |
127 |
|
|
(FSPB as TSPB).getDataLength, |
128 |
|
|
(FSPB as TSPB).getBuffer) > 0 then |
129 |
|
|
IBDataBaseError; |
130 |
|
|
end; |
131 |
|
|
end; |
132 |
|
|
|
133 |
|
|
procedure TFB25ServiceManager.Detach(Force: boolean); |
134 |
|
|
begin |
135 |
|
|
if FHandle = nil then |
136 |
|
|
Exit; |
137 |
|
|
with Firebird25ClientAPI do |
138 |
|
|
if isc_service_detach(StatusVector, @FHandle) > 0 then |
139 |
|
|
begin |
140 |
|
|
FHandle := nil; |
141 |
|
|
if not Force then |
142 |
|
|
IBDataBaseError; |
143 |
|
|
end |
144 |
|
|
else |
145 |
|
|
FHandle := nil; |
146 |
|
|
end; |
147 |
|
|
|
148 |
|
|
function TFB25ServiceManager.IsAttached: boolean; |
149 |
|
|
begin |
150 |
|
|
Result := FHandle <> nil; |
151 |
|
|
end; |
152 |
|
|
|
153 |
|
|
procedure TFB25ServiceManager.Start(Request: ISRB); |
154 |
|
|
begin |
155 |
|
|
CheckActive; |
156 |
|
|
with Firebird25ClientAPI do |
157 |
|
|
if isc_service_start(StatusVector, @FHandle, nil, |
158 |
|
|
(Request as TSRB).getDataLength, |
159 |
|
|
(Request as TSRB).getBuffer) > 0 then |
160 |
|
|
IBDataBaseError; |
161 |
|
|
end; |
162 |
|
|
|
163 |
|
|
function TFB25ServiceManager.Query(SQPB: ISQPB; Request: ISRB |
164 |
|
|
): IServiceQueryResults; |
165 |
|
|
var QueryResults: TServiceQueryResults; |
166 |
|
|
begin |
167 |
|
|
CheckActive; |
168 |
|
|
QueryResults := TServiceQueryResults.Create; |
169 |
|
|
Result := QueryResults; |
170 |
|
|
with Firebird25ClientAPI do |
171 |
|
|
if SQPB = nil then |
172 |
|
|
begin |
173 |
|
|
if isc_service_query(StatusVector, @FHandle, nil,0,nil, |
174 |
|
|
(Request as TSRB).getDataLength, |
175 |
|
|
(Request as TSRB).getBuffer, |
176 |
|
|
QueryResults.getBufSize, |
177 |
|
|
QueryResults.Buffer) > 0 then |
178 |
|
|
IBDataBaseError; |
179 |
|
|
end |
180 |
|
|
else |
181 |
|
|
if isc_service_query(StatusVector, @FHandle, nil, |
182 |
|
|
(SQPB as TSQPB).getDataLength, |
183 |
|
|
(SQPB as TSQPB).getBuffer, |
184 |
|
|
(Request as TSRB).getDataLength, |
185 |
|
|
(Request as TSRB).getBuffer, |
186 |
|
|
QueryResults.getBufSize, |
187 |
|
|
QueryResults.Buffer) > 0 then |
188 |
|
|
IBDataBaseError; |
189 |
|
|
|
190 |
|
|
end; |
191 |
|
|
|
192 |
|
|
end. |
193 |
|
|
|