ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/branches/udr/client/2.5/FB25ClientAPI.pas
Revision: 386
Committed: Tue Jan 18 12:05:35 2022 UTC (2 years, 3 months ago) by tony
Content type: text/x-pascal
File size: 27200 byte(s)
Log Message:
Silent exceptions bug fixed

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

Properties

Name Value
svn:eol-style native