ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/fbintf/client/2.5/FB25ClientAPI.pas
Revision: 308
Committed: Sat Jul 18 10:26:30 2020 UTC (3 years, 9 months ago) by tony
Content type: text/x-pascal
File size: 26762 byte(s)
Log Message:
Fixes Merged

File Contents

# Content
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 const
78 FBClientInterfaceVersion = '2.5';
79
80 type
81
82 { TFB25Status }
83
84 TFB25Status = class(TFBStatus,IStatus)
85 public
86 function StatusVector: PStatusVector; override;
87 end;
88
89 { TFB25ClientAPI }
90
91 TFB25ClientAPI = class(TFBClientAPI,IFirebirdAPI)
92 private
93 FIBServiceAPIPresent: boolean;
94 FStatus: TFB25Status;
95 FStatusIntf: IStatus; {Keep a reference to the interface - automatic destroy
96 when this class is freed and last reference to IStatus
97 goes out of scope.}
98 public
99 constructor Create(aFBLibrary: TFBLibrary);
100 destructor Destroy; override;
101 function StatusVector: PISC_STATUS;
102 function LoadInterface: boolean; override;
103 function GetAPI: IFirebirdAPI; override;
104 {$IFDEF UNIX}
105 function GetFirebirdLibList: string; override;
106 {$ENDIF}
107 property IBServiceAPIPresent: boolean read FIBServiceAPIPresent;
108 property Status: TFB25Status read FStatus;
109
110 public
111
112 {fbclient API}
113 BLOB_get: TBLOB_get;
114 BLOB_put: TBLOB_put;
115 isc_wait_for_event: Tisc_wait_for_event;
116 isc_vax_integer: Tisc_vax_integer;
117 isc_portable_integer: Tisc_portable_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_start_transaction: Tisc_start_transaction;
154 isc_start_multiple: Tisc_start_multiple;
155 isc_commit_transaction: Tisc_commit_transaction;
156 isc_commit_retaining: Tisc_commit_retaining;
157 isc_rollback_transaction: Tisc_rollback_transaction;
158 isc_rollback_retaining: Tisc_rollback_retaining;
159 isc_cancel_events: Tisc_cancel_events;
160 isc_que_events: Tisc_que_events;
161 isc_add_user : Tisc_add_user;
162 isc_delete_user: Tisc_delete_user;
163 isc_modify_user: Tisc_modify_user;
164 isc_array_lookup_bounds: Tisc_array_lookup_bounds;
165 isc_array_get_slice: Tisc_array_get_slice;
166 isc_array_put_slice: Tisc_array_put_slice;
167 isc_prepare_transaction: Tisc_prepare_transaction;
168 isc_version: Tisc_Version;
169 isc_interprete: Tisc_interprete;
170
171 public
172 {Helper Functions}
173 function DecodeInteger(bufptr: PByte; len: short): integer; override;
174 procedure SQLEncodeDate(aDate: TDateTime; bufptr: PByte); override;
175 function SQLDecodeDate(bufptr: PByte): TDateTime; override;
176 procedure SQLEncodeTime(aTime: TDateTime; bufptr: PByte); override;
177 function SQLDecodeTime(bufptr: PByte): TDateTime; override;
178 procedure SQLEncodeDateTime(aDateTime: TDateTime; bufptr: PByte); override;
179 function SQLDecodeDateTime(bufptr: PByte): TDateTime; override;
180 function FormatStatus(Status: TFBStatus): AnsiString; 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): ITransaction; overload;
194 function StartTransaction(Attachments: array of IAttachment;
195 TPB: ITPB; DefaultCompletion: TTransactionCompletion): 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, FBParamBlock,
222 IBUtils;
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.StatusVector: PStatusVector;
329 begin
330 Result := @FStatusVector;
331 end;
332
333
334 { TFB25ClientAPI }
335
336 {$IFDEF UNIX}
337 function TFB25ClientAPI.GetFirebirdLibList: string;
338 begin
339 Result := 'libfbembed.so:libfbembed.so.2.5:libfbembed.so.2.1:libfbclient.so:libfbclient.so.2';
340 end;
341 {$ENDIF}
342
343 function TFB25ClientAPI.LoadInterface: boolean;
344 begin
345 Result := inherited LoadInterface;
346 BLOB_get := GetProcAddr('BLOB_get'); {do not localize}
347 BLOB_put := GetProcAddr('BLOB_put'); {do not localize}
348 isc_wait_for_event := GetProcAddr('isc_wait_for_event'); {do not localize}
349 isc_vax_integer := GetProcAddr('isc_vax_integer'); {do not localize}
350 isc_portable_integer := GetProcAddr('isc_portable_integer'); {do not localize}
351 isc_blob_info := GetProcAddr('isc_blob_info'); {do not localize}
352 isc_blob_lookup_desc := GetProcAddr('isc_blob_lookup_desc'); {do not localize}
353 isc_open_blob2 := GetProcAddr('isc_open_blob2'); {do not localize}
354 isc_close_blob := GetProcAddr('isc_close_blob'); {do not localize}
355 isc_get_segment := GetProcAddr('isc_get_segment'); {do not localize}
356 isc_put_segment := GetProcAddr('isc_put_segment'); {do not localize}
357 isc_create_blob2 := GetProcAddr('isc_create_blob2'); {do not localize}
358 isc_cancel_blob := GetProcAddr('isc_cancel_blob'); {do not localize}
359 isc_decode_date := GetProcAddr('isc_decode_date'); {do not localize}
360 isc_encode_date := GetProcAddr('isc_encode_date'); {do not localize}
361 isc_dsql_free_statement := GetProcAddr('isc_dsql_free_statement'); {do not localize}
362 isc_dsql_execute2 := GetProcAddr('isc_dsql_execute2'); {do not localize}
363 isc_dsql_execute := GetProcAddr('isc_dsql_execute'); {do not localize}
364 isc_dsql_set_cursor_name := GetProcAddr('isc_dsql_set_cursor_name'); {do not localize}
365 isc_dsql_fetch := GetProcAddr('isc_dsql_fetch'); {do not localize}
366 isc_dsql_sql_info := GetProcAddr('isc_dsql_sql_info'); {do not localize}
367 isc_dsql_alloc_statement2 := GetProcAddr('isc_dsql_alloc_statement2'); {do not localize}
368 isc_dsql_prepare := GetProcAddr('isc_dsql_prepare'); {do not localize}
369 isc_dsql_describe_bind := GetProcAddr('isc_dsql_describe_bind'); {do not localize}
370 isc_dsql_describe := GetProcAddr('isc_dsql_describe'); {do not localize}
371 isc_dsql_execute_immediate := GetProcAddr('isc_dsql_execute_immediate'); {do not localize}
372 isc_drop_database := GetProcAddr('isc_drop_database'); {do not localize}
373 isc_detach_database := GetProcAddr('isc_detach_database'); {do not localize}
374 isc_attach_database := GetProcAddr('isc_attach_database'); {do not localize}
375 isc_database_info := GetProcAddr('isc_database_info'); {do not localize}
376 isc_start_transaction := GetProcAddr('isc_start_transaction'); {do not localize}
377 isc_start_multiple := GetProcAddr('isc_start_multiple'); {do not localize}
378 isc_commit_transaction := GetProcAddr('isc_commit_transaction'); {do not localize}
379 isc_commit_retaining := GetProcAddr('isc_commit_retaining'); {do not localize}
380 isc_rollback_transaction := GetProcAddr('isc_rollback_transaction'); {do not localize}
381 isc_cancel_events := GetProcAddr('isc_cancel_events'); {do not localize}
382 isc_que_events := GetProcAddr('isc_que_events'); {do not localize}
383 isc_add_user := GetProcAddr('isc_add_user'); {do not localize}
384 isc_delete_user := GetProcAddr('isc_delete_user'); {do not localize}
385 isc_modify_user := GetProcAddr('isc_modify_user'); {do not localize}
386 isc_array_lookup_bounds := GetProcAddr('isc_array_lookup_bounds'); {do not localize}
387 isc_array_get_slice := GetProcAddr('isc_array_get_slice'); {do not localize}
388 isc_array_put_slice := GetProcAddr('isc_array_put_slice'); {do not localize}
389 isc_prepare_transaction := GetProcAddr('isc_prepare_transaction'); {do not localize}
390 isc_version := GetProcAddr('isc_version'); {do not localize}
391 isc_interprete := GetProcAddr('isc_interprete'); {do not localize}
392
393 FIBServiceAPIPresent := true;
394 isc_rollback_retaining := GetProcAddress(FFBLibrary.IBLibrary, 'isc_rollback_retaining'); {do not localize}
395 if Assigned(isc_rollback_retaining) then
396 begin
397 isc_service_attach := GetProcAddr('isc_service_attach'); {do not localize}
398 isc_service_detach := GetProcAddr('isc_service_detach'); {do not localize}
399 isc_service_query := GetProcAddr('isc_service_query'); {do not localize}
400 isc_service_start := GetProcAddr('isc_service_start'); {do not localize}
401 isc_decode_sql_date := GetProcAddr('isc_decode_sql_date'); {do not localize}
402 isc_decode_sql_time := GetProcAddr('isc_decode_sql_time'); {do not localize}
403 isc_decode_timestamp := GetProcAddr('isc_decode_timestamp'); {do not localize}
404 isc_encode_sql_date := GetProcAddr('isc_encode_sql_date'); {do not localize}
405 isc_encode_sql_time := GetProcAddr('isc_encode_sql_time'); {do not localize}
406 isc_encode_timestamp := GetProcAddr('isc_encode_timestamp'); {do not localize}
407 end else
408 begin
409 FIBServiceAPIPresent := false;
410 isc_rollback_retaining := @isc_rollback_retaining_stub;
411 isc_service_attach := @isc_service_attach_stub;
412 isc_service_detach := @isc_service_detach_stub;
413 isc_service_query := @isc_service_query_stub;
414 isc_service_start := @isc_service_start_stub;
415 isc_decode_sql_date := @isc_decode_sql_date_stub;
416 isc_decode_sql_time := @isc_decode_sql_time_stub;
417 isc_decode_timestamp := @isc_decode_timestamp_stub;
418 isc_encode_sql_date := @isc_encode_sql_date_stub;
419 isc_encode_sql_time := @isc_encode_sql_time_stub;
420 isc_encode_timestamp := @isc_encode_timestamp_stub;
421 end;
422 Result := Result and assigned(isc_attach_database);
423 end;
424
425 function TFB25ClientAPI.GetAPI: IFirebirdAPI;
426 begin
427 Result := self;
428 end;
429
430 constructor TFB25ClientAPI.Create(aFBLibrary: TFBLibrary);
431 begin
432 inherited Create(aFBLibrary);
433 FStatus := TFB25Status.Create(self);
434 FStatusIntf := FStatus;
435 end;
436
437 destructor TFB25ClientAPI.Destroy;
438 begin
439 FStatusIntf := nil;
440 inherited Destroy;
441 end;
442
443
444 function TFB25ClientAPI.StatusVector: PISC_STATUS;
445 begin
446 Result := PISC_STATUS(FStatus.StatusVector);
447 end;
448
449 function TFB25ClientAPI.GetStatus: IStatus;
450 begin
451 Result := FStatus;
452 end;
453
454 function TFB25ClientAPI.AllocateDPB: IDPB;
455 begin
456 Result := TDPB.Create(self);
457 end;
458
459 function TFB25ClientAPI.OpenDatabase(DatabaseName: AnsiString; DPB: IDPB;
460 RaiseExceptionOnConnectError: boolean): IAttachment;
461 begin
462 Result := TFB25Attachment.Create(self,DatabaseName,DPB,RaiseExceptionOnConnectError);
463 if not Result.IsConnected then
464 Result := nil;
465 end;
466
467 function TFB25ClientAPI.CreateDatabase(DatabaseName: AnsiString; DPB: IDPB;
468 RaiseExceptionOnError: boolean): IAttachment;
469 begin
470 Result := TFB25Attachment.CreateDatabase(self,DatabaseName, DPB, RaiseExceptionOnError );
471 if (Result <> nil) and not Result.IsConnected then
472 Result := nil;
473 end;
474
475 function TFB25ClientAPI.CreateDatabase(sql: AnsiString; aSQLDialect: integer;
476 RaiseExceptionOnError: boolean): IAttachment;
477 begin
478 Result := TFB25Attachment.CreateDatabase(self,sql,aSQLDialect, RaiseExceptionOnError );
479 if (Result <> nil) and not Result.IsConnected then
480 Result := nil;
481 end;
482
483 function TFB25ClientAPI.AllocateSPB: ISPB;
484 begin
485 Result := TSPB.Create(self);
486 end;
487
488 function TFB25ClientAPI.AllocateTPB: ITPB;
489 begin
490 Result := TTPB.Create(self);
491 end;
492
493 function TFB25ClientAPI.GetServiceManager(ServerName: AnsiString;
494 Protocol: TProtocol; SPB: ISPB): IServiceManager;
495 begin
496 if HasServiceAPI then
497 Result := TFB25ServiceManager.Create(self,ServerName,Protocol,SPB)
498 else
499 Result := nil;
500 end;
501
502 function TFB25ClientAPI.GetServiceManager(ServerName: AnsiString;
503 Port: AnsiString; Protocol: TProtocol; SPB: ISPB): IServiceManager;
504 begin
505 if HasServiceAPI then
506 Result := TFB25ServiceManager.Create(self,ServerName,Protocol,SPB,Port)
507 else
508 Result := nil;
509 end;
510
511 function TFB25ClientAPI.StartTransaction(Attachments: array of IAttachment;
512 TPB: array of byte; DefaultCompletion: TTransactionCompletion): ITransaction;
513 begin
514 Result := TFB25Transaction.Create(self,Attachments,TPB,DefaultCompletion);
515 end;
516
517 function TFB25ClientAPI.StartTransaction(Attachments: array of IAttachment;
518 TPB: ITPB; DefaultCompletion: TTransactionCompletion): ITransaction;
519 begin
520 Result := TFB25Transaction.Create(self,Attachments,TPB,DefaultCompletion);
521 end;
522
523 function TFB25ClientAPI.HasServiceAPI: boolean;
524 begin
525 Result := IBServiceAPIPresent;
526 end;
527
528 function TFB25ClientAPI.HasRollbackRetaining: boolean;
529 begin
530 Result := assigned(isc_rollback_retaining);
531 end;
532
533 function TFB25ClientAPI.IsEmbeddedServer: boolean;
534 begin
535 Result := false;
536 {$IFDEF UNIX}
537 Result := Pos('libfbembed',FFBLibrary.GetLibraryName) = 1;
538 {$ENDIF}
539 {$IFDEF WINDOWS}
540 Result := CompareText(FFBLibrary.GetLibraryName,FIREBIRD_EMBEDDED) = 0;
541 {$ENDIF}
542 end;
543
544 function TFB25ClientAPI.GetClientMajor: integer;
545 begin
546 Result := 2;
547 end;
548
549 function TFB25ClientAPI.GetClientMinor: integer;
550 begin
551 Result := 5;
552 end;
553
554 function TFB25ClientAPI.HasMasterIntf: boolean;
555 begin
556 Result := false;
557 end;
558
559 function TFB25ClientAPI.GetIMaster: TObject;
560 begin
561 Result := nil;
562 end;
563
564 function TFB25ClientAPI.DecodeInteger(bufptr: PByte; len: short): integer;
565 begin
566 Result := isc_portable_integer(bufptr,len);
567 end;
568
569 procedure TFB25ClientAPI.SQLEncodeDate(aDate: TDateTime; bufptr: PByte);
570 var
571 tm_date: TCTimeStructure;
572 Yr, Mn, Dy: Word;
573 begin
574 DecodeDate(aDate, Yr, Mn, Dy);
575 with tm_date do begin
576 tm_sec := 0;
577 tm_min := 0;
578 tm_hour := 0;
579 tm_mday := Dy;
580 tm_mon := Mn - 1;
581 tm_year := Yr - 1900;
582 end;
583 isc_encode_sql_date(@tm_date, PISC_DATE(bufptr));
584 end;
585
586 function TFB25ClientAPI.SQLDecodeDate(bufptr: PByte): TDateTime;
587 var
588 tm_date: TCTimeStructure;
589 begin
590 isc_decode_sql_date(PISC_DATE(bufptr), @tm_date);
591 try
592 result := EncodeDate(Word(tm_date.tm_year + 1900), Word(tm_date.tm_mon + 1),
593 Word(tm_date.tm_mday));
594 except
595 on E: EConvertError do begin
596 IBError(ibxeInvalidDataConversion, [nil]);
597 end;
598 end;
599 end;
600
601 procedure TFB25ClientAPI.SQLEncodeTime(aTime: TDateTime; bufptr: PByte);
602 var
603 tm_date: TCTimeStructure;
604 Hr, Mt, S, Ms: Word;
605 begin
606 DecodeTime(aTime, Hr, Mt, S, Ms);
607 with tm_date do begin
608 tm_sec := S;
609 tm_min := Mt;
610 tm_hour := Hr;
611 tm_mday := 0;
612 tm_mon := 0;
613 tm_year := 0;
614 end;
615 isc_encode_sql_time(@tm_date, PISC_TIME(bufptr));
616 if Ms > 0 then
617 Inc(PISC_TIME(bufptr)^,Ms*10);
618 end;
619
620 function TFB25ClientAPI.SQLDecodeTime(bufptr: PByte): TDateTime;
621 var
622 tm_date: TCTimeStructure;
623 msecs: Word;
624 begin
625 isc_decode_sql_time(PISC_TIME(bufptr), @tm_date);
626 try
627 msecs := (PISC_TIME(bufptr)^ mod 10000) div 10;
628 result := EncodeTime(Word(tm_date.tm_hour), Word(tm_date.tm_min),
629 Word(tm_date.tm_sec), msecs)
630 except
631 on E: EConvertError do begin
632 IBError(ibxeInvalidDataConversion, [nil]);
633 end;
634 end;
635 end;
636
637 procedure TFB25ClientAPI.SQLEncodeDateTime(aDateTime: TDateTime; bufptr: PByte);
638 var
639 tm_date: TCTimeStructure;
640 Yr, Mn, Dy, Hr, Mt, S, Ms: Word;
641 begin
642 DecodeDate(aDateTime, Yr, Mn, Dy);
643 DecodeTime(aDateTime, Hr, Mt, S, Ms);
644 with tm_date do begin
645 tm_sec := S;
646 tm_min := Mt;
647 tm_hour := Hr;
648 tm_mday := Dy;
649 tm_mon := Mn - 1;
650 tm_year := Yr - 1900;
651 end;
652 isc_encode_date(@tm_date, PISC_QUAD(bufptr));
653 if Ms > 0 then
654 Inc(PISC_TIMESTAMP(bufptr)^.timestamp_time,Ms*10);
655 end;
656
657 function TFB25ClientAPI.SQLDecodeDateTime(bufptr: PByte): TDateTime;
658 var
659 tm_date: TCTimeStructure;
660 msecs: Word;
661 begin
662 isc_decode_date(PISC_QUAD(bufptr), @tm_date);
663 try
664 result := EncodeDate(Word(tm_date.tm_year + 1900), Word(tm_date.tm_mon + 1),
665 Word(tm_date.tm_mday));
666 msecs := (PISC_TIMESTAMP(bufptr)^.timestamp_time mod 10000) div 10;
667 if result >= 0 then
668 result := result + EncodeTime(Word(tm_date.tm_hour), Word(tm_date.tm_min),
669 Word(tm_date.tm_sec), msecs)
670 else
671 result := result - EncodeTime(Word(tm_date.tm_hour), Word(tm_date.tm_min),
672 Word(tm_date.tm_sec), msecs)
673 except
674 on E: EConvertError do begin
675 IBError(ibxeInvalidDataConversion, [nil]);
676 end;
677 end;
678 end;
679
680 function TFB25ClientAPI.FormatStatus(Status: TFBStatus): AnsiString;
681 var psb: PStatusVector;
682 local_buffer: array[0..IBHugeLocalBufferLength - 1] of AnsiChar;
683 begin
684 psb := Status.StatusVector;
685 Result := '';
686 while isc_interprete(@local_buffer,@psb) > 0 do
687 begin
688 if (Result <> '') and (Result[Length(Result)] <> LF) then
689 Result := Result + LineEnding + '-';
690 Result := Result + strpas(local_buffer);
691 end;
692 end;
693
694 end.
695
696