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 |
– |
protected |
99 |
– |
{$IFDEF UNIX} |
100 |
– |
function GetFirebirdLibList: string; override; |
101 |
– |
{$ENDIF} |
102 |
– |
procedure LoadInterface; override; |
98 |
|
public |
99 |
< |
constructor Create; |
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 |
|
|
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} |
177 |
|
function SQLDecodeTime(bufptr: PByte): TDateTime; override; |
178 |
|
procedure SQLEncodeDateTime(aDateTime: TDateTime; bufptr: PByte); override; |
179 |
|
function SQLDecodeDateTime(bufptr: PByte): TDateTime; override; |
180 |
< |
|
180 |
> |
function FormatStatus(Status: TFBStatus): AnsiString; override; |
181 |
|
public |
182 |
|
{IFirebirdAPI} |
183 |
|
|
197 |
|
{Service Manager} |
198 |
|
function AllocateSPB: ISPB; |
199 |
|
function HasServiceAPI: boolean; |
200 |
< |
function GetServiceManager(ServerName: AnsiString; Protocol: TProtocol; SPB: ISPB): IServiceManager; |
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 GetImplementationVersion: AnsiString; |
207 |
> |
function GetClientMajor: integer; override; |
208 |
> |
function GetClientMinor: integer; override; |
209 |
|
|
210 |
|
{Firebird 3 API} |
211 |
|
function HasMasterIntf: boolean; |
213 |
|
|
214 |
|
end; |
215 |
|
|
212 |
– |
var |
213 |
– |
Firebird25ClientAPI: TFB25ClientAPI = nil; |
214 |
– |
|
216 |
|
implementation |
217 |
|
|
218 |
|
uses FBMessages, |
323 |
|
threadvar |
324 |
|
FStatusVector: TStatusVector; |
325 |
|
|
326 |
+ |
{ TFB25ActivityReporter } |
327 |
+ |
|
328 |
|
function TFB25Status.StatusVector: PStatusVector; |
329 |
|
begin |
330 |
|
Result := @FStatusVector; |
340 |
|
end; |
341 |
|
{$ENDIF} |
342 |
|
|
343 |
< |
procedure TFB25ClientAPI.LoadInterface; |
343 |
> |
function TFB25ClientAPI.LoadInterface: boolean; |
344 |
|
begin |
345 |
< |
inherited LoadInterface; |
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} |
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(IBLibrary, 'isc_rollback_retaining'); {do not localize} |
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} |
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; |
430 |
> |
constructor TFB25ClientAPI.Create(aFBLibrary: TFBLibrary); |
431 |
|
begin |
432 |
< |
inherited; |
432 |
> |
inherited Create(aFBLibrary); |
433 |
|
FStatus := TFB25Status.Create(self); |
434 |
|
FStatusIntf := FStatus; |
424 |
– |
Firebird25ClientAPI := self; |
435 |
|
end; |
436 |
|
|
437 |
|
destructor TFB25ClientAPI.Destroy; |
438 |
|
begin |
439 |
|
FStatusIntf := nil; |
430 |
– |
Firebird25ClientAPI := nil; |
440 |
|
inherited Destroy; |
441 |
|
end; |
442 |
|
|
453 |
|
|
454 |
|
function TFB25ClientAPI.AllocateDPB: IDPB; |
455 |
|
begin |
456 |
< |
Result := TDPB.Create; |
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(DatabaseName,DPB,RaiseExceptionOnConnectError); |
462 |
> |
Result := TFB25Attachment.Create(self,DatabaseName,DPB,RaiseExceptionOnConnectError); |
463 |
|
if not Result.IsConnected then |
464 |
|
Result := nil; |
465 |
|
end; |
467 |
|
function TFB25ClientAPI.CreateDatabase(DatabaseName: AnsiString; DPB: IDPB; |
468 |
|
RaiseExceptionOnError: boolean): IAttachment; |
469 |
|
begin |
470 |
< |
Result := TFB25Attachment.CreateDatabase(DatabaseName, DPB, RaiseExceptionOnError ); |
470 |
> |
Result := TFB25Attachment.CreateDatabase(self,DatabaseName, DPB, RaiseExceptionOnError ); |
471 |
|
if (Result <> nil) and not Result.IsConnected then |
472 |
|
Result := nil; |
473 |
|
end; |
475 |
|
function TFB25ClientAPI.CreateDatabase(sql: AnsiString; aSQLDialect: integer; |
476 |
|
RaiseExceptionOnError: boolean): IAttachment; |
477 |
|
begin |
478 |
< |
Result := TFB25Attachment.CreateDatabase(sql,aSQLDialect, RaiseExceptionOnError ); |
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; |
485 |
> |
Result := TSPB.Create(self); |
486 |
|
end; |
487 |
|
|
488 |
|
function TFB25ClientAPI.AllocateTPB: ITPB; |
489 |
|
begin |
490 |
< |
Result := TTPB.Create; |
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(ServerName,Protocol,SPB) |
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; |
511 |
|
function TFB25ClientAPI.StartTransaction(Attachments: array of IAttachment; |
512 |
|
TPB: array of byte; DefaultCompletion: TTransactionCompletion): ITransaction; |
513 |
|
begin |
514 |
< |
Result := TFB25Transaction.Create(Attachments,TPB,DefaultCompletion); |
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(Attachments,TPB,DefaultCompletion); |
520 |
> |
Result := TFB25Transaction.Create(self,Attachments,TPB,DefaultCompletion); |
521 |
|
end; |
522 |
|
|
523 |
|
function TFB25ClientAPI.HasServiceAPI: boolean; |
534 |
|
begin |
535 |
|
Result := false; |
536 |
|
{$IFDEF UNIX} |
537 |
< |
Result := Pos('libfbembed',FFBLibraryName) = 1; |
537 |
> |
Result := Pos('libfbembed',FFBLibrary.GetLibraryName) = 1; |
538 |
|
{$ENDIF} |
539 |
|
{$IFDEF WINDOWS} |
540 |
< |
Result := CompareText(FFBLibraryName,FIREBIRD_EMBEDDED) = 0; |
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; |
561 |
|
Result := nil; |
562 |
|
end; |
563 |
|
|
536 |
– |
function TFB25ClientAPI.GetImplementationVersion: AnsiString; |
537 |
– |
begin |
538 |
– |
Result := FBClientInterfaceVersion; |
539 |
– |
end; |
540 |
– |
|
564 |
|
function TFB25ClientAPI.DecodeInteger(bufptr: PByte; len: short): integer; |
565 |
|
begin |
566 |
|
Result := isc_portable_integer(bufptr,len); |
612 |
|
tm_mon := 0; |
613 |
|
tm_year := 0; |
614 |
|
end; |
615 |
< |
with Firebird25ClientAPI do |
593 |
< |
isc_encode_sql_time(@tm_date, PISC_TIME(bufptr)); |
615 |
> |
isc_encode_sql_time(@tm_date, PISC_TIME(bufptr)); |
616 |
|
if Ms > 0 then |
617 |
|
Inc(PISC_TIME(bufptr)^,Ms*10); |
618 |
|
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 |
|
|