1 |
(* |
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 FB25ClientAPI; |
63 |
{$IFDEF MSWINDOWS} |
64 |
{$DEFINE WINDOWS} |
65 |
{$ENDIF} |
66 |
|
67 |
{$IFDEF FPC} |
68 |
{$mode delphi} |
69 |
{$interfaces COM} |
70 |
{$ENDIF} |
71 |
|
72 |
interface |
73 |
|
74 |
uses |
75 |
Classes, SysUtils, FBClientAPI, IBHeader, IBExternals, IB; |
76 |
|
77 |
type |
78 |
|
79 |
{ TFB25Status } |
80 |
|
81 |
TFB25Status = class(TFBStatus,IStatus) |
82 |
protected |
83 |
function GetIBMessage: Ansistring; override; |
84 |
public |
85 |
function Clone: IStatus; override; |
86 |
function StatusVector: PStatusVector; override; |
87 |
function InErrorState: boolean; override; |
88 |
end; |
89 |
|
90 |
{ TFB25ClientAPI } |
91 |
|
92 |
TFB25ClientAPI = class(TFBClientAPI,IFirebirdAPI) |
93 |
private |
94 |
FIBServiceAPIPresent: boolean; |
95 |
FStatus: TFB25Status; |
96 |
FStatusIntf: IStatus; {Keep a reference to the interface - automatic destroy |
97 |
when this class is freed and last reference to IStatus |
98 |
goes out of scope.} |
99 |
public |
100 |
constructor Create(aFBLibrary: TFBLibrary); |
101 |
destructor Destroy; override; |
102 |
function StatusVector: PISC_STATUS; |
103 |
function LoadInterface: boolean; override; |
104 |
function GetAPI: IFirebirdAPI; override; |
105 |
{$IFDEF UNIX} |
106 |
function GetFirebirdLibList: string; override; |
107 |
{$ENDIF} |
108 |
property IBServiceAPIPresent: boolean read FIBServiceAPIPresent; |
109 |
property Status: TFB25Status read FStatus; |
110 |
|
111 |
public |
112 |
|
113 |
{fbclient API} |
114 |
BLOB_get: TBLOB_get; |
115 |
BLOB_put: TBLOB_put; |
116 |
isc_wait_for_event: Tisc_wait_for_event; |
117 |
isc_vax_integer: Tisc_vax_integer; |
118 |
isc_blob_info: Tisc_blob_info; |
119 |
isc_blob_lookup_desc: Tisc_blob_lookup_desc; |
120 |
isc_open_blob2: Tisc_open_blob2; |
121 |
isc_close_blob: Tisc_close_blob; |
122 |
isc_get_segment: Tisc_get_segment; |
123 |
isc_put_segment: Tisc_put_segment; |
124 |
isc_create_blob2: Tisc_create_blob2; |
125 |
isc_cancel_blob: Tisc_cancel_blob; |
126 |
isc_service_attach: Tisc_service_attach; |
127 |
isc_service_detach: Tisc_service_detach; |
128 |
isc_service_query: Tisc_service_query; |
129 |
isc_service_start: Tisc_service_start; |
130 |
isc_decode_date: Tisc_decode_date; |
131 |
isc_decode_sql_date: Tisc_decode_sql_date; |
132 |
isc_decode_sql_time: Tisc_decode_sql_time; |
133 |
isc_decode_timestamp: Tisc_decode_timestamp; |
134 |
isc_encode_date: Tisc_encode_date; |
135 |
isc_encode_sql_date: Tisc_encode_sql_date; |
136 |
isc_encode_sql_time: Tisc_encode_sql_time; |
137 |
isc_encode_timestamp: Tisc_encode_timestamp; |
138 |
isc_dsql_free_statement: Tisc_dsql_free_statement; |
139 |
isc_dsql_execute2: Tisc_dsql_execute2; |
140 |
isc_dsql_execute: Tisc_dsql_execute; |
141 |
isc_dsql_set_cursor_name: Tisc_dsql_set_cursor_name; |
142 |
isc_dsql_fetch: Tisc_dsql_fetch; |
143 |
isc_dsql_sql_info: Tisc_dsql_sql_info; |
144 |
isc_dsql_alloc_statement2: Tisc_dsql_alloc_statement2; |
145 |
isc_dsql_prepare: Tisc_dsql_prepare; |
146 |
isc_dsql_describe_bind: Tisc_dsql_describe_bind; |
147 |
isc_dsql_describe: Tisc_dsql_describe; |
148 |
isc_dsql_execute_immediate: Tisc_dsql_execute_immediate; |
149 |
isc_drop_database: Tisc_drop_database; |
150 |
isc_detach_database: Tisc_detach_database; |
151 |
isc_attach_database: Tisc_attach_database; |
152 |
isc_database_info: Tisc_database_info; |
153 |
isc_transaction_info: Tisc_transaction_info; |
154 |
isc_start_transaction: Tisc_start_transaction; |
155 |
isc_start_multiple: Tisc_start_multiple; |
156 |
isc_commit_transaction: Tisc_commit_transaction; |
157 |
isc_commit_retaining: Tisc_commit_retaining; |
158 |
isc_rollback_transaction: Tisc_rollback_transaction; |
159 |
isc_rollback_retaining: Tisc_rollback_retaining; |
160 |
isc_cancel_events: Tisc_cancel_events; |
161 |
isc_que_events: Tisc_que_events; |
162 |
isc_add_user : Tisc_add_user; |
163 |
isc_delete_user: Tisc_delete_user; |
164 |
isc_modify_user: Tisc_modify_user; |
165 |
isc_array_lookup_bounds: Tisc_array_lookup_bounds; |
166 |
isc_array_get_slice: Tisc_array_get_slice; |
167 |
isc_array_put_slice: Tisc_array_put_slice; |
168 |
isc_prepare_transaction: Tisc_prepare_transaction; |
169 |
isc_version: Tisc_Version; |
170 |
isc_interprete: Tisc_interprete; |
171 |
fb_interpret: Tfb_interpret; |
172 |
|
173 |
public |
174 |
{Helper Functions} |
175 |
procedure SQLEncodeDate(aDate: TDateTime; bufptr: PByte); override; |
176 |
function SQLDecodeDate(bufptr: PByte): TDateTime; override; |
177 |
procedure SQLEncodeTime(aTime: TDateTime; bufptr: PByte); override; |
178 |
function SQLDecodeTime(bufptr: PByte): TDateTime; override; |
179 |
procedure SQLEncodeDateTime(aDateTime: TDateTime; bufptr: PByte); override; |
180 |
function SQLDecodeDateTime(bufptr: PByte): TDateTime; override; |
181 |
public |
182 |
{IFirebirdAPI} |
183 |
|
184 |
{Database connections} |
185 |
function AllocateDPB: IDPB; |
186 |
function OpenDatabase(DatabaseName: AnsiString; DPB: IDPB; RaiseExceptionOnConnectError: boolean=true): IAttachment; |
187 |
function CreateDatabase(DatabaseName: AnsiString; DPB: IDPB; RaiseExceptionOnError: boolean=true): IAttachment; overload; |
188 |
function CreateDatabase(sql: AnsiString; aSQLDialect: integer; RaiseExceptionOnError: boolean=true): IAttachment; overload; |
189 |
|
190 |
{Start Transaction against multiple databases} |
191 |
function AllocateTPB: ITPB; |
192 |
function StartTransaction(Attachments: array of IAttachment; |
193 |
TPB: array of byte; DefaultCompletion: TTransactionCompletion; aName: AnsiString=''): ITransaction; overload; |
194 |
function StartTransaction(Attachments: array of IAttachment; |
195 |
TPB: ITPB; DefaultCompletion: TTransactionCompletion; aName: AnsiString=''): ITransaction; overload; |
196 |
|
197 |
{Service Manager} |
198 |
function AllocateSPB: ISPB; |
199 |
function HasServiceAPI: boolean; |
200 |
function GetServiceManager(ServerName: AnsiString; Protocol: TProtocol; SPB: ISPB): IServiceManager; overload; |
201 |
function GetServiceManager(ServerName: AnsiString; Port: AnsiString; Protocol: TProtocol; SPB: ISPB): IServiceManager; overload; |
202 |
|
203 |
{Information} |
204 |
function GetStatus: IStatus; override; |
205 |
function HasRollbackRetaining: boolean; |
206 |
function IsEmbeddedServer: boolean; override; |
207 |
function GetClientMajor: integer; override; |
208 |
function GetClientMinor: integer; override; |
209 |
|
210 |
{Firebird 3 API} |
211 |
function HasMasterIntf: boolean; |
212 |
function GetIMaster: TObject; |
213 |
|
214 |
end; |
215 |
|
216 |
implementation |
217 |
|
218 |
uses FBMessages, |
219 |
{$IFDEF WINDOWS}Windows, {$ENDIF} |
220 |
{$IFDEF FPC} Dynlibs, {$ENDIF} |
221 |
FB25Attachment, FB25Transaction, FB25Services, |
222 |
IBUtils, FBAttachment, FBTransaction, FBServices; |
223 |
|
224 |
{ Stubs for 6.0 only functions } |
225 |
function isc_rollback_retaining_stub(status_vector : PISC_STATUS; |
226 |
tran_handle : PISC_TR_HANDLE): |
227 |
ISC_STATUS; {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} |
228 |
begin |
229 |
Result := 0; |
230 |
IBError(ibxeIB60feature, ['isc_rollback_retaining']); {do not localize} |
231 |
end; |
232 |
|
233 |
function isc_service_attach_stub(status_vector : PISC_STATUS; |
234 |
isc_arg2 : UShort; |
235 |
isc_arg3 : PAnsiChar; |
236 |
service_handle : PISC_SVC_HANDLE; |
237 |
isc_arg5 : UShort; |
238 |
isc_arg6 : PAnsiChar): |
239 |
ISC_STATUS; {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} |
240 |
begin |
241 |
Result := 0; |
242 |
IBError(ibxeIB60feature, ['isc_service_attach']); {do not localize} |
243 |
end; |
244 |
|
245 |
function isc_service_detach_stub(status_vector : PISC_STATUS; |
246 |
service_handle : PISC_SVC_HANDLE): |
247 |
ISC_STATUS; {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} |
248 |
begin |
249 |
Result := 0; |
250 |
IBError(ibxeIB60feature, ['isc_service_detach']); {do not localize} |
251 |
end; |
252 |
|
253 |
function isc_service_query_stub(status_vector : PISC_STATUS; |
254 |
service_handle : PISC_SVC_HANDLE; |
255 |
recv_handle : PISC_SVC_HANDLE; |
256 |
isc_arg4 : UShort; |
257 |
isc_arg5 : PAnsiChar; |
258 |
isc_arg6 : UShort; |
259 |
isc_arg7 : PAnsiChar; |
260 |
isc_arg8 : UShort; |
261 |
isc_arg9 : PAnsiChar): |
262 |
ISC_STATUS; {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} |
263 |
begin |
264 |
Result := 0; |
265 |
IBError(ibxeIB60feature, ['isc_service_query']); {do not localize} |
266 |
end; |
267 |
|
268 |
function isc_service_start_stub(status_vector : PISC_STATUS; |
269 |
service_handle : PISC_SVC_HANDLE; |
270 |
recv_handle : PISC_SVC_HANDLE; |
271 |
isc_arg4 : UShort; |
272 |
isc_arg5 : PAnsiChar): |
273 |
ISC_STATUS; {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} |
274 |
begin |
275 |
Result := 0; |
276 |
IBError(ibxeIB60feature, ['isc_service_start']); {do not localize} |
277 |
end; |
278 |
|
279 |
procedure isc_encode_sql_date_stub(tm_date : PCTimeStructure; |
280 |
ib_date : PISC_DATE); |
281 |
{$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} |
282 |
begin |
283 |
IBError(ibxeIB60feature, ['isc_encode_sql_date']); {do not localize} |
284 |
end; |
285 |
|
286 |
procedure isc_encode_sql_time_stub(tm_date : PCTimeStructure; |
287 |
ib_time : PISC_TIME); |
288 |
{$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} |
289 |
begin |
290 |
IBError(ibxeIB60feature, ['isc_encode_sql_time']); {do not localize} |
291 |
end; |
292 |
|
293 |
procedure isc_encode_timestamp_stub(tm_date : PCTimeStructure; |
294 |
ib_timestamp : PISC_TIMESTAMP); |
295 |
{$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} |
296 |
begin |
297 |
IBError(ibxeIB60feature, ['isc_encode_sql_timestamp']); {do not localize} |
298 |
end; |
299 |
|
300 |
procedure isc_decode_sql_date_stub(ib_date : PISC_DATE; |
301 |
tm_date : PCTimeStructure); |
302 |
{$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} |
303 |
begin |
304 |
IBError(ibxeIB60feature, ['isc_decode_sql_date']); {do not localize} |
305 |
end; |
306 |
|
307 |
procedure isc_decode_sql_time_stub(ib_time : PISC_TIME; |
308 |
tm_date : PCTimeStructure); |
309 |
{$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} |
310 |
begin |
311 |
IBError(ibxeIB60feature, ['isc_decode_sql_time']); {do not localize} |
312 |
end; |
313 |
|
314 |
procedure isc_decode_timestamp_stub(ib_timestamp : PISC_TIMESTAMP; |
315 |
tm_date : PCTimeStructure); |
316 |
{$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} |
317 |
begin |
318 |
IBError(ibxeIB60feature, ['isc_decode_timestamp']); {do not localize} |
319 |
end; |
320 |
|
321 |
{ TFB25Status } |
322 |
|
323 |
threadvar |
324 |
FStatusVector: TStatusVector; |
325 |
|
326 |
{ TFB25ActivityReporter } |
327 |
|
328 |
function TFB25Status.GetIBMessage: Ansistring; |
329 |
var psb: PStatusVector; |
330 |
local_buffer: array[0..IBHugeLocalBufferLength - 1] of AnsiChar; |
331 |
begin |
332 |
psb := StatusVector; |
333 |
Result := ''; |
334 |
with FOwner as TFB25ClientAPI do |
335 |
if assigned(fb_interpret) then |
336 |
begin |
337 |
if fb_interpret(@local_buffer,sizeof(local_buffer),@psb) > 0 then |
338 |
Result := strpas(local_buffer); |
339 |
end |
340 |
else |
341 |
if assigned(isc_interprete) then |
342 |
while isc_interprete(@local_buffer,@psb) > 0 do |
343 |
begin |
344 |
if (Result <> '') and (Result[Length(Result)] <> LF) then |
345 |
Result := Result + LineEnding + '-'; |
346 |
Result := Result + strpas(local_buffer); |
347 |
end; |
348 |
end; |
349 |
|
350 |
function TFB25Status.Clone: IStatus; |
351 |
begin |
352 |
Result := TFB25Status.Copy(self); |
353 |
end; |
354 |
|
355 |
function TFB25Status.StatusVector: PStatusVector; |
356 |
begin |
357 |
Result := @FStatusVector; |
358 |
end; |
359 |
|
360 |
function TFB25Status.InErrorState: boolean; |
361 |
begin |
362 |
Result := StatusVector^[0] > 0; |
363 |
end; |
364 |
|
365 |
|
366 |
{ TFB25ClientAPI } |
367 |
|
368 |
{$IFDEF UNIX} |
369 |
function TFB25ClientAPI.GetFirebirdLibList: string; |
370 |
begin |
371 |
Result := 'libfbembed.so:libfbembed.so.2.5:libfbembed.so.2.1:libfbclient.so:libfbclient.so.2'; |
372 |
end; |
373 |
{$ENDIF} |
374 |
|
375 |
function TFB25ClientAPI.LoadInterface: boolean; |
376 |
begin |
377 |
Result := inherited LoadInterface; |
378 |
BLOB_get := GetProcAddr('BLOB_get'); {do not localize} |
379 |
BLOB_put := GetProcAddr('BLOB_put'); {do not localize} |
380 |
isc_wait_for_event := GetProcAddr('isc_wait_for_event'); {do not localize} |
381 |
isc_vax_integer := GetProcAddr('isc_vax_integer'); {do not localize} |
382 |
isc_blob_info := GetProcAddr('isc_blob_info'); {do not localize} |
383 |
isc_blob_lookup_desc := GetProcAddr('isc_blob_lookup_desc'); {do not localize} |
384 |
isc_open_blob2 := GetProcAddr('isc_open_blob2'); {do not localize} |
385 |
isc_close_blob := GetProcAddr('isc_close_blob'); {do not localize} |
386 |
isc_get_segment := GetProcAddr('isc_get_segment'); {do not localize} |
387 |
isc_put_segment := GetProcAddr('isc_put_segment'); {do not localize} |
388 |
isc_create_blob2 := GetProcAddr('isc_create_blob2'); {do not localize} |
389 |
isc_cancel_blob := GetProcAddr('isc_cancel_blob'); {do not localize} |
390 |
isc_decode_date := GetProcAddr('isc_decode_date'); {do not localize} |
391 |
isc_encode_date := GetProcAddr('isc_encode_date'); {do not localize} |
392 |
isc_dsql_free_statement := GetProcAddr('isc_dsql_free_statement'); {do not localize} |
393 |
isc_dsql_execute2 := GetProcAddr('isc_dsql_execute2'); {do not localize} |
394 |
isc_dsql_execute := GetProcAddr('isc_dsql_execute'); {do not localize} |
395 |
isc_dsql_set_cursor_name := GetProcAddr('isc_dsql_set_cursor_name'); {do not localize} |
396 |
isc_dsql_fetch := GetProcAddr('isc_dsql_fetch'); {do not localize} |
397 |
isc_dsql_sql_info := GetProcAddr('isc_dsql_sql_info'); {do not localize} |
398 |
isc_dsql_alloc_statement2 := GetProcAddr('isc_dsql_alloc_statement2'); {do not localize} |
399 |
isc_dsql_prepare := GetProcAddr('isc_dsql_prepare'); {do not localize} |
400 |
isc_dsql_describe_bind := GetProcAddr('isc_dsql_describe_bind'); {do not localize} |
401 |
isc_dsql_describe := GetProcAddr('isc_dsql_describe'); {do not localize} |
402 |
isc_dsql_execute_immediate := GetProcAddr('isc_dsql_execute_immediate'); {do not localize} |
403 |
isc_drop_database := GetProcAddr('isc_drop_database'); {do not localize} |
404 |
isc_detach_database := GetProcAddr('isc_detach_database'); {do not localize} |
405 |
isc_attach_database := GetProcAddr('isc_attach_database'); {do not localize} |
406 |
isc_database_info := GetProcAddr('isc_database_info'); {do not localize} |
407 |
isc_transaction_info := GetProcAddr('isc_transaction_info'); {do not localize} |
408 |
isc_start_transaction := GetProcAddr('isc_start_transaction'); {do not localize} |
409 |
isc_start_multiple := GetProcAddr('isc_start_multiple'); {do not localize} |
410 |
isc_commit_transaction := GetProcAddr('isc_commit_transaction'); {do not localize} |
411 |
isc_commit_retaining := GetProcAddr('isc_commit_retaining'); {do not localize} |
412 |
isc_rollback_transaction := GetProcAddr('isc_rollback_transaction'); {do not localize} |
413 |
isc_cancel_events := GetProcAddr('isc_cancel_events'); {do not localize} |
414 |
isc_que_events := GetProcAddr('isc_que_events'); {do not localize} |
415 |
isc_add_user := GetProcAddr('isc_add_user'); {do not localize} |
416 |
isc_delete_user := GetProcAddr('isc_delete_user'); {do not localize} |
417 |
isc_modify_user := GetProcAddr('isc_modify_user'); {do not localize} |
418 |
isc_array_lookup_bounds := GetProcAddr('isc_array_lookup_bounds'); {do not localize} |
419 |
isc_array_get_slice := GetProcAddr('isc_array_get_slice'); {do not localize} |
420 |
isc_array_put_slice := GetProcAddr('isc_array_put_slice'); {do not localize} |
421 |
isc_prepare_transaction := GetProcAddr('isc_prepare_transaction'); {do not localize} |
422 |
isc_version := GetProcAddr('isc_version'); {do not localize} |
423 |
isc_interprete := GetProcAddr('isc_interprete'); {do not localize} |
424 |
fb_interpret := GetProcAddr('fb_interpret'); {do not localize} |
425 |
|
426 |
FIBServiceAPIPresent := true; |
427 |
isc_rollback_retaining := GetProcAddress(FFBLibrary.IBLibrary, 'isc_rollback_retaining'); {do not localize} |
428 |
if Assigned(isc_rollback_retaining) then |
429 |
begin |
430 |
isc_service_attach := GetProcAddr('isc_service_attach'); {do not localize} |
431 |
isc_service_detach := GetProcAddr('isc_service_detach'); {do not localize} |
432 |
isc_service_query := GetProcAddr('isc_service_query'); {do not localize} |
433 |
isc_service_start := GetProcAddr('isc_service_start'); {do not localize} |
434 |
isc_decode_sql_date := GetProcAddr('isc_decode_sql_date'); {do not localize} |
435 |
isc_decode_sql_time := GetProcAddr('isc_decode_sql_time'); {do not localize} |
436 |
isc_decode_timestamp := GetProcAddr('isc_decode_timestamp'); {do not localize} |
437 |
isc_encode_sql_date := GetProcAddr('isc_encode_sql_date'); {do not localize} |
438 |
isc_encode_sql_time := GetProcAddr('isc_encode_sql_time'); {do not localize} |
439 |
isc_encode_timestamp := GetProcAddr('isc_encode_timestamp'); {do not localize} |
440 |
end else |
441 |
begin |
442 |
FIBServiceAPIPresent := false; |
443 |
isc_rollback_retaining := @isc_rollback_retaining_stub; |
444 |
isc_service_attach := @isc_service_attach_stub; |
445 |
isc_service_detach := @isc_service_detach_stub; |
446 |
isc_service_query := @isc_service_query_stub; |
447 |
isc_service_start := @isc_service_start_stub; |
448 |
isc_decode_sql_date := @isc_decode_sql_date_stub; |
449 |
isc_decode_sql_time := @isc_decode_sql_time_stub; |
450 |
isc_decode_timestamp := @isc_decode_timestamp_stub; |
451 |
isc_encode_sql_date := @isc_encode_sql_date_stub; |
452 |
isc_encode_sql_time := @isc_encode_sql_time_stub; |
453 |
isc_encode_timestamp := @isc_encode_timestamp_stub; |
454 |
end; |
455 |
Result := Result and assigned(isc_attach_database); |
456 |
end; |
457 |
|
458 |
function TFB25ClientAPI.GetAPI: IFirebirdAPI; |
459 |
begin |
460 |
Result := self; |
461 |
end; |
462 |
|
463 |
constructor TFB25ClientAPI.Create(aFBLibrary: TFBLibrary); |
464 |
begin |
465 |
inherited Create(aFBLibrary); |
466 |
FStatus := TFB25Status.Create(self); |
467 |
FStatusIntf := FStatus; |
468 |
end; |
469 |
|
470 |
destructor TFB25ClientAPI.Destroy; |
471 |
begin |
472 |
FStatusIntf := nil; |
473 |
inherited Destroy; |
474 |
end; |
475 |
|
476 |
|
477 |
function TFB25ClientAPI.StatusVector: PISC_STATUS; |
478 |
begin |
479 |
Result := PISC_STATUS(FStatus.StatusVector); |
480 |
end; |
481 |
|
482 |
function TFB25ClientAPI.GetStatus: IStatus; |
483 |
begin |
484 |
Result := FStatus; |
485 |
end; |
486 |
|
487 |
function TFB25ClientAPI.AllocateDPB: IDPB; |
488 |
begin |
489 |
Result := TDPB.Create(self); |
490 |
end; |
491 |
|
492 |
function TFB25ClientAPI.OpenDatabase(DatabaseName: AnsiString; DPB: IDPB; |
493 |
RaiseExceptionOnConnectError: boolean): IAttachment; |
494 |
begin |
495 |
Result := TFB25Attachment.Create(self,DatabaseName,DPB,RaiseExceptionOnConnectError); |
496 |
if not Result.IsConnected then |
497 |
Result := nil; |
498 |
end; |
499 |
|
500 |
function TFB25ClientAPI.CreateDatabase(DatabaseName: AnsiString; DPB: IDPB; |
501 |
RaiseExceptionOnError: boolean): IAttachment; |
502 |
begin |
503 |
Result := TFB25Attachment.CreateDatabase(self,DatabaseName, DPB, RaiseExceptionOnError ); |
504 |
if (Result <> nil) and not Result.IsConnected then |
505 |
Result := nil; |
506 |
end; |
507 |
|
508 |
function TFB25ClientAPI.CreateDatabase(sql: AnsiString; aSQLDialect: integer; |
509 |
RaiseExceptionOnError: boolean): IAttachment; |
510 |
begin |
511 |
Result := TFB25Attachment.CreateDatabase(self,sql,aSQLDialect, RaiseExceptionOnError ); |
512 |
if (Result <> nil) and not Result.IsConnected then |
513 |
Result := nil; |
514 |
end; |
515 |
|
516 |
function TFB25ClientAPI.AllocateSPB: ISPB; |
517 |
begin |
518 |
Result := TSPB.Create(self); |
519 |
end; |
520 |
|
521 |
function TFB25ClientAPI.AllocateTPB: ITPB; |
522 |
begin |
523 |
Result := TTPB.Create(self); |
524 |
end; |
525 |
|
526 |
function TFB25ClientAPI.GetServiceManager(ServerName: AnsiString; |
527 |
Protocol: TProtocol; SPB: ISPB): IServiceManager; |
528 |
begin |
529 |
if HasServiceAPI then |
530 |
Result := TFB25ServiceManager.Create(self,ServerName,Protocol,SPB) |
531 |
else |
532 |
Result := nil; |
533 |
end; |
534 |
|
535 |
function TFB25ClientAPI.GetServiceManager(ServerName: AnsiString; |
536 |
Port: AnsiString; Protocol: TProtocol; SPB: ISPB): IServiceManager; |
537 |
begin |
538 |
if HasServiceAPI then |
539 |
Result := TFB25ServiceManager.Create(self,ServerName,Protocol,SPB,Port) |
540 |
else |
541 |
Result := nil; |
542 |
end; |
543 |
|
544 |
function TFB25ClientAPI.StartTransaction(Attachments: array of IAttachment; |
545 |
TPB: array of byte; DefaultCompletion: TTransactionCompletion; aName: AnsiString): ITransaction; |
546 |
begin |
547 |
Result := TFB25Transaction.Create(self,Attachments,TPB,DefaultCompletion,aName); |
548 |
end; |
549 |
|
550 |
function TFB25ClientAPI.StartTransaction(Attachments: array of IAttachment; |
551 |
TPB: ITPB; DefaultCompletion: TTransactionCompletion; aName: AnsiString): ITransaction; |
552 |
begin |
553 |
Result := TFB25Transaction.Create(self,Attachments,TPB,DefaultCompletion, aName); |
554 |
end; |
555 |
|
556 |
function TFB25ClientAPI.HasServiceAPI: boolean; |
557 |
begin |
558 |
Result := IBServiceAPIPresent; |
559 |
end; |
560 |
|
561 |
function TFB25ClientAPI.HasRollbackRetaining: boolean; |
562 |
begin |
563 |
Result := assigned(isc_rollback_retaining); |
564 |
end; |
565 |
|
566 |
function TFB25ClientAPI.IsEmbeddedServer: boolean; |
567 |
begin |
568 |
Result := false; |
569 |
{$IFDEF UNIX} |
570 |
Result := Pos('libfbembed',FFBLibrary.GetLibraryName) = 1; |
571 |
{$ENDIF} |
572 |
{$IFDEF WINDOWS} |
573 |
Result := CompareText(FFBLibrary.GetLibraryName,FIREBIRD_EMBEDDED) = 0; |
574 |
{$ENDIF} |
575 |
end; |
576 |
|
577 |
function TFB25ClientAPI.GetClientMajor: integer; |
578 |
begin |
579 |
Result := 2; |
580 |
end; |
581 |
|
582 |
function TFB25ClientAPI.GetClientMinor: integer; |
583 |
begin |
584 |
Result := 5; |
585 |
end; |
586 |
|
587 |
function TFB25ClientAPI.HasMasterIntf: boolean; |
588 |
begin |
589 |
Result := false; |
590 |
end; |
591 |
|
592 |
function TFB25ClientAPI.GetIMaster: TObject; |
593 |
begin |
594 |
Result := nil; |
595 |
end; |
596 |
|
597 |
procedure TFB25ClientAPI.SQLEncodeDate(aDate: TDateTime; bufptr: PByte); |
598 |
var |
599 |
tm_date: TCTimeStructure; |
600 |
Yr, Mn, Dy: Word; |
601 |
begin |
602 |
DecodeDate(aDate, Yr, Mn, Dy); |
603 |
with tm_date do begin |
604 |
tm_sec := 0; |
605 |
tm_min := 0; |
606 |
tm_hour := 0; |
607 |
tm_mday := Dy; |
608 |
tm_mon := Mn - 1; |
609 |
tm_year := Yr - 1900; |
610 |
end; |
611 |
isc_encode_sql_date(@tm_date, PISC_DATE(bufptr)); |
612 |
end; |
613 |
|
614 |
function TFB25ClientAPI.SQLDecodeDate(bufptr: PByte): TDateTime; |
615 |
var |
616 |
tm_date: TCTimeStructure; |
617 |
begin |
618 |
isc_decode_sql_date(PISC_DATE(bufptr), @tm_date); |
619 |
try |
620 |
result := EncodeDate(Word(tm_date.tm_year + 1900), Word(tm_date.tm_mon + 1), |
621 |
Word(tm_date.tm_mday)); |
622 |
except |
623 |
on E: EConvertError do begin |
624 |
IBError(ibxeInvalidDataConversion, [nil]); |
625 |
end; |
626 |
end; |
627 |
end; |
628 |
|
629 |
procedure TFB25ClientAPI.SQLEncodeTime(aTime: TDateTime; bufptr: PByte); |
630 |
var |
631 |
tm_date: TCTimeStructure; |
632 |
Hr, Mt, S: Word; |
633 |
DMs: cardinal; {DMs = decimilliseconds} |
634 |
begin |
635 |
FBDecodeTime(aTime, Hr, Mt, S, DMs); |
636 |
with tm_date do begin |
637 |
tm_sec := S; |
638 |
tm_min := Mt; |
639 |
tm_hour := Hr; |
640 |
tm_mday := 0; |
641 |
tm_mon := 0; |
642 |
tm_year := 0; |
643 |
end; |
644 |
isc_encode_sql_time(@tm_date, PISC_TIME(bufptr)); |
645 |
if DMs > 0 then |
646 |
Inc(PISC_TIME(bufptr)^,DMs); |
647 |
end; |
648 |
|
649 |
function TFB25ClientAPI.SQLDecodeTime(bufptr: PByte): TDateTime; |
650 |
var |
651 |
tm_date: TCTimeStructure; |
652 |
DMs: cardinal; {DMs = decimilliseconds} |
653 |
begin |
654 |
isc_decode_sql_time(PISC_TIME(bufptr), @tm_date); |
655 |
try |
656 |
DMs := PISC_TIME(bufptr)^ mod 10000; |
657 |
result := FBEncodeTime(Word(tm_date.tm_hour), Word(tm_date.tm_min), |
658 |
Word(tm_date.tm_sec), DMs) |
659 |
except |
660 |
on E: EConvertError do begin |
661 |
IBError(ibxeInvalidDataConversion, [nil]); |
662 |
end; |
663 |
end; |
664 |
end; |
665 |
|
666 |
procedure TFB25ClientAPI.SQLEncodeDateTime(aDateTime: TDateTime; bufptr: PByte); |
667 |
var |
668 |
tm_date: TCTimeStructure; |
669 |
Yr, Mn, Dy, Hr, Mt, S, Ms: Word; |
670 |
DMs: cardinal; |
671 |
begin |
672 |
DecodeDate(aDateTime, Yr, Mn, Dy); |
673 |
FBDecodeTime(aDateTime, Hr, Mt, S, DMs); |
674 |
with tm_date do begin |
675 |
tm_sec := S; |
676 |
tm_min := Mt; |
677 |
tm_hour := Hr; |
678 |
tm_mday := Dy; |
679 |
tm_mon := Mn - 1; |
680 |
tm_year := Yr - 1900; |
681 |
end; |
682 |
isc_encode_date(@tm_date, PISC_QUAD(bufptr)); |
683 |
if DMs > 0 then |
684 |
Inc(PISC_TIMESTAMP(bufptr)^.timestamp_time,DMs); |
685 |
end; |
686 |
|
687 |
function TFB25ClientAPI.SQLDecodeDateTime(bufptr: PByte): TDateTime; |
688 |
var |
689 |
tm_date: TCTimeStructure; |
690 |
Dmsecs: Word; |
691 |
begin |
692 |
isc_decode_date(PISC_QUAD(bufptr), @tm_date); |
693 |
try |
694 |
result := EncodeDate(Word(tm_date.tm_year + 1900), Word(tm_date.tm_mon + 1), |
695 |
Word(tm_date.tm_mday)); |
696 |
Dmsecs := PISC_TIMESTAMP(bufptr)^.timestamp_time mod 10000; |
697 |
if result >= 0 then |
698 |
result := result + FBEncodeTime(Word(tm_date.tm_hour), Word(tm_date.tm_min), |
699 |
Word(tm_date.tm_sec), Dmsecs) |
700 |
else |
701 |
result := result - FBEncodeTime(Word(tm_date.tm_hour), Word(tm_date.tm_min), |
702 |
Word(tm_date.tm_sec), Dmsecs) |
703 |
except |
704 |
on E: EConvertError do begin |
705 |
IBError(ibxeInvalidDataConversion, [nil]); |
706 |
end; |
707 |
end; |
708 |
end; |
709 |
|
710 |
end. |
711 |
|
712 |
|