ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/branches/journaling/fbintf/client/2.5/FB25ClientAPI.pas
(Generate patch)

Comparing ibx/trunk/fbintf/client/2.5/FB25ClientAPI.pas (file contents):
Revision 47 by tony, Mon Jan 9 15:31:51 2017 UTC vs.
Revision 266 by tony, Wed Dec 26 18:34:32 2018 UTC

# Line 60 | Line 60
60   {                                                                        }
61   {************************************************************************}
62   unit FB25ClientAPI;
63 + {$IFDEF MSWINDOWS}
64 + {$DEFINE WINDOWS}
65 + {$ENDIF}
66  
67   {$IFDEF FPC}
68   {$mode delphi}
# Line 92 | Line 95 | type
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.}
95  protected
96    {$IFDEF UNIX}
97    function GetFirebirdLibList: string; override;
98    {$ENDIF}
99    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  
# Line 162 | Line 165 | type
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  
170    public
171      {Helper Functions}
172 <    function DecodeInteger(bufptr: PChar; len: short): integer; override;
173 <    procedure SQLEncodeDate(aDate: TDateTime; bufptr: PChar); override;
174 <    function SQLDecodeDate(bufptr: PChar): TDateTime; override;
175 <    procedure SQLEncodeTime(aTime: TDateTime; bufptr: PChar); override;
176 <    function SQLDecodeTime(bufptr: PChar): TDateTime;  override;
177 <    procedure SQLEncodeDateTime(aDateTime: TDateTime; bufptr: PChar); override;
178 <    function SQLDecodeDateTime(bufptr: PChar): TDateTime; override;
172 >    function DecodeInteger(bufptr: PByte; len: short): integer; override;
173 >    procedure SQLEncodeDate(aDate: TDateTime; bufptr: PByte); override;
174 >    function SQLDecodeDate(bufptr: PByte): TDateTime; override;
175 >    procedure SQLEncodeTime(aTime: TDateTime; bufptr: PByte); override;
176 >    function SQLDecodeTime(bufptr: PByte): TDateTime;  override;
177 >    procedure SQLEncodeDateTime(aDateTime: TDateTime; bufptr: PByte); override;
178 >    function SQLDecodeDateTime(bufptr: PByte): TDateTime; override;
179  
180    public
181      {IFirebirdAPI}
182  
183      {Database connections}
184      function AllocateDPB: IDPB;
185 <    function OpenDatabase(DatabaseName: string; DPB: IDPB; RaiseExceptionOnConnectError: boolean=true): IAttachment;
186 <    function CreateDatabase(DatabaseName: string; DPB: IDPB; RaiseExceptionOnError: boolean=true): IAttachment;  overload;
187 <    function CreateDatabase(sql: string; aSQLDialect: integer; RaiseExceptionOnError: boolean=true): IAttachment; overload;
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;
# Line 192 | Line 196 | type
196      {Service Manager}
197      function AllocateSPB: ISPB;
198      function HasServiceAPI: boolean;
199 <    function GetServiceManager(ServerName: string; Protocol: TProtocol; SPB: ISPB): IServiceManager;
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 GetImplementationVersion: string;
206 >    function GetImplementationVersion: AnsiString;
207  
208      {Firebird 3 API}
209      function HasMasterIntf: boolean;
# Line 206 | Line 211 | type
211  
212     end;
213  
209 const
210  Firebird25ClientAPI: TFB25ClientAPI = nil;
211
214   implementation
215  
216 < uses FBMessages, dynlibs, FB25Attachment, FB25Transaction, FB25Services, FBParamBlock,
216 > uses FBMessages,
217 >    {$IFDEF WINDOWS}Windows, {$ENDIF}
218 >    {$IFDEF FPC} Dynlibs, {$ENDIF}
219 >  FB25Attachment, FB25Transaction, FB25Services, FBParamBlock,
220    IBUtils;
221  
222   { Stubs for 6.0 only functions }
# Line 225 | Line 230 | end;
230  
231   function isc_service_attach_stub(status_vector      : PISC_STATUS;
232                                   isc_arg2           : UShort;
233 <                                 isc_arg3           : PChar;
233 >                                 isc_arg3           : PAnsiChar;
234                                   service_handle     : PISC_SVC_HANDLE;
235                                   isc_arg5           : UShort;
236 <                                 isc_arg6           : PChar):
236 >                                 isc_arg6           : PAnsiChar):
237                                   ISC_STATUS; {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
238   begin
239    Result := 0;
# Line 247 | Line 252 | function isc_service_query_stub(status_v
252                                  service_handle       : PISC_SVC_HANDLE;
253                                  recv_handle          : PISC_SVC_HANDLE;
254                                  isc_arg4             : UShort;
255 <                                isc_arg5             : PChar;
255 >                                isc_arg5             : PAnsiChar;
256                                  isc_arg6             : UShort;
257 <                                isc_arg7             : PChar;
257 >                                isc_arg7             : PAnsiChar;
258                                  isc_arg8             : UShort;
259 <                                isc_arg9             : PChar):
259 >                                isc_arg9             : PAnsiChar):
260                                  ISC_STATUS; {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
261   begin
262    Result := 0;
# Line 262 | Line 267 | function isc_service_start_stub(status_v
267                                  service_handle       : PISC_SVC_HANDLE;
268                                  recv_handle          : PISC_SVC_HANDLE;
269                                  isc_arg4             : UShort;
270 <                                isc_arg5             : PChar):
270 >                                isc_arg5             : PAnsiChar):
271                                  ISC_STATUS; {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
272   begin
273    Result := 0;
# Line 316 | Line 321 | end;
321   threadvar
322    FStatusVector: TStatusVector;
323  
324 + { TFB25ActivityReporter }
325 +
326   function TFB25Status.StatusVector: PStatusVector;
327   begin
328    Result := @FStatusVector;
# Line 331 | Line 338 | begin
338   end;
339   {$ENDIF}
340  
341 < procedure TFB25ClientAPI.LoadInterface;
341 > function TFB25ClientAPI.LoadInterface: boolean;
342   begin
343 <  inherited LoadInterface;
343 >  Result := inherited LoadInterface;
344    BLOB_get := GetProcAddr('BLOB_get'); {do not localize}
345    BLOB_put := GetProcAddr('BLOB_put'); {do not localize}
346    isc_wait_for_event := GetProcAddr('isc_wait_for_event'); {do not localize}
# Line 378 | Line 385 | begin
385    isc_array_get_slice := GetProcAddr('isc_array_get_slice'); {do not localize}
386    isc_array_put_slice := GetProcAddr('isc_array_put_slice'); {do not localize}
387    isc_prepare_transaction  := GetProcAddr('isc_prepare_transaction'); {do not localize}
388 +  isc_version  := GetProcAddr('isc_version'); {do not localize}
389  
390    FIBServiceAPIPresent := true;
391 <  isc_rollback_retaining := GetProcAddress(IBLibrary, 'isc_rollback_retaining'); {do not localize}
391 >  isc_rollback_retaining := GetProcAddress(FFBLibrary.IBLibrary, 'isc_rollback_retaining'); {do not localize}
392    if Assigned(isc_rollback_retaining) then
393    begin
394      isc_service_attach := GetProcAddr('isc_service_attach'); {do not localize}
# Line 408 | Line 416 | begin
416      isc_encode_sql_time := @isc_encode_sql_time_stub;
417      isc_encode_timestamp := @isc_encode_timestamp_stub;
418    end;
419 +  Result := Result and assigned(isc_attach_database);
420   end;
421  
422 < constructor TFB25ClientAPI.Create;
422 > function TFB25ClientAPI.GetAPI: IFirebirdAPI;
423   begin
424 <  inherited;
424 >  Result := self;
425 > end;
426 >
427 > constructor TFB25ClientAPI.Create(aFBLibrary: TFBLibrary);
428 > begin
429 >  inherited Create(aFBLibrary);
430    FStatus := TFB25Status.Create(self);
431    FStatusIntf := FStatus;
418  Firebird25ClientAPI := self;
432   end;
433  
434   destructor TFB25ClientAPI.Destroy;
435   begin
436    FStatusIntf := nil;
424  Firebird25ClientAPI := nil;
437    inherited Destroy;
438   end;
439  
# Line 438 | Line 450 | end;
450  
451   function TFB25ClientAPI.AllocateDPB: IDPB;
452   begin
453 <  Result := TDPB.Create;
453 >  Result := TDPB.Create(self);
454   end;
455  
456 < function TFB25ClientAPI.OpenDatabase(DatabaseName: string; DPB: IDPB;
456 > function TFB25ClientAPI.OpenDatabase(DatabaseName: AnsiString; DPB: IDPB;
457                                      RaiseExceptionOnConnectError: boolean): IAttachment;
458   begin
459 <   Result := TFB25Attachment.Create(DatabaseName,DPB,RaiseExceptionOnConnectError);
459 >   Result := TFB25Attachment.Create(self,DatabaseName,DPB,RaiseExceptionOnConnectError);
460     if not Result.IsConnected then
461       Result := nil;
462   end;
463  
464 < function TFB25ClientAPI.CreateDatabase(DatabaseName: string; DPB: IDPB;
464 > function TFB25ClientAPI.CreateDatabase(DatabaseName: AnsiString; DPB: IDPB;
465    RaiseExceptionOnError: boolean): IAttachment;
466   begin
467 <  Result := TFB25Attachment.CreateDatabase(DatabaseName, DPB, RaiseExceptionOnError );
467 >  Result := TFB25Attachment.CreateDatabase(self,DatabaseName, DPB, RaiseExceptionOnError );
468     if (Result <> nil) and not Result.IsConnected then
469       Result := nil;
470   end;
471  
472 < function TFB25ClientAPI.CreateDatabase(sql: string; aSQLDialect: integer;
472 > function TFB25ClientAPI.CreateDatabase(sql: AnsiString; aSQLDialect: integer;
473    RaiseExceptionOnError: boolean): IAttachment;
474   begin
475 <  Result := TFB25Attachment.CreateDatabase(sql,aSQLDialect, RaiseExceptionOnError );
475 >  Result := TFB25Attachment.CreateDatabase(self,sql,aSQLDialect, RaiseExceptionOnError );
476     if (Result <> nil) and not Result.IsConnected then
477       Result := nil;
478   end;
479  
480   function TFB25ClientAPI.AllocateSPB: ISPB;
481   begin
482 <  Result := TSPB.Create;
482 >  Result := TSPB.Create(self);
483   end;
484  
485   function TFB25ClientAPI.AllocateTPB: ITPB;
486   begin
487 <  Result := TTPB.Create;
487 >  Result := TTPB.Create(self);
488   end;
489  
490 < function TFB25ClientAPI.GetServiceManager(ServerName: string;
490 > function TFB25ClientAPI.GetServiceManager(ServerName: AnsiString;
491    Protocol: TProtocol; SPB: ISPB): IServiceManager;
492   begin
493    if HasServiceAPI then
494 <    Result := TFB25ServiceManager.Create(ServerName,Protocol,SPB)
494 >    Result := TFB25ServiceManager.Create(self,ServerName,Protocol,SPB)
495 >  else
496 >    Result := nil;
497 > end;
498 >
499 > function TFB25ClientAPI.GetServiceManager(ServerName: AnsiString;
500 >  Port: AnsiString; Protocol: TProtocol; SPB: ISPB): IServiceManager;
501 > begin
502 >  if HasServiceAPI then
503 >    Result := TFB25ServiceManager.Create(self,ServerName,Protocol,SPB,Port)
504    else
505      Result := nil;
506   end;
# Line 487 | Line 508 | end;
508   function TFB25ClientAPI.StartTransaction(Attachments: array of IAttachment;
509    TPB: array of byte; DefaultCompletion: TTransactionCompletion): ITransaction;
510   begin
511 <  Result := TFB25Transaction.Create(Attachments,TPB,DefaultCompletion);
511 >  Result := TFB25Transaction.Create(self,Attachments,TPB,DefaultCompletion);
512   end;
513  
514   function TFB25ClientAPI.StartTransaction(Attachments: array of IAttachment;
515    TPB: ITPB; DefaultCompletion: TTransactionCompletion): ITransaction;
516   begin
517 <  Result := TFB25Transaction.Create(Attachments,TPB,DefaultCompletion);
517 >  Result := TFB25Transaction.Create(self,Attachments,TPB,DefaultCompletion);
518   end;
519  
520   function TFB25ClientAPI.HasServiceAPI: boolean;
# Line 510 | Line 531 | function TFB25ClientAPI.IsEmbeddedServer
531   begin
532    Result := false;
533   {$IFDEF UNIX}
534 <  Result := Pos('libfbembed',FFBLibraryName) = 1;
534 >  Result := Pos('libfbembed',FFBLibrary.GetLibraryName) = 1;
535   {$ENDIF}
536   {$IFDEF WINDOWS}
537 <  Result := CompareText(FFBLibraryName,FIREBIRD_EMBEDDED) = 0;
537 >  Result := CompareText(FFBLibrary.GetLibraryName,FIREBIRD_EMBEDDED) = 0;
538   {$ENDIF}
539   end;
540  
# Line 527 | Line 548 | begin
548    Result := nil;
549   end;
550  
551 < function TFB25ClientAPI.GetImplementationVersion: string;
551 > function TFB25ClientAPI.GetImplementationVersion: AnsiString;
552   begin
553    Result := FBClientInterfaceVersion;
554   end;
555  
556 < function TFB25ClientAPI.DecodeInteger(bufptr: PChar; len: short): integer;
556 > function TFB25ClientAPI.DecodeInteger(bufptr: PByte; len: short): integer;
557   begin
558    Result := isc_portable_integer(bufptr,len);
559   end;
560  
561 < procedure TFB25ClientAPI.SQLEncodeDate(aDate: TDateTime; bufptr: PChar);
561 > procedure TFB25ClientAPI.SQLEncodeDate(aDate: TDateTime; bufptr: PByte);
562   var
563    tm_date: TCTimeStructure;
564    Yr, Mn, Dy: Word;
# Line 554 | Line 575 | begin
575    isc_encode_sql_date(@tm_date, PISC_DATE(bufptr));
576   end;
577  
578 < function TFB25ClientAPI.SQLDecodeDate(bufptr: PChar): TDateTime;
578 > function TFB25ClientAPI.SQLDecodeDate(bufptr: PByte): TDateTime;
579   var
580    tm_date: TCTimeStructure;
581   begin
# Line 569 | Line 590 | begin
590    end;
591   end;
592  
593 < procedure TFB25ClientAPI.SQLEncodeTime(aTime: TDateTime; bufptr: PChar);
593 > procedure TFB25ClientAPI.SQLEncodeTime(aTime: TDateTime; bufptr: PByte);
594   var
595    tm_date: TCTimeStructure;
596    Hr, Mt, S, Ms: Word;
# Line 583 | Line 604 | begin
604      tm_mon := 0;
605      tm_year := 0;
606    end;
607 <  with Firebird25ClientAPI do
587 <    isc_encode_sql_time(@tm_date, PISC_TIME(bufptr));
607 >  isc_encode_sql_time(@tm_date, PISC_TIME(bufptr));
608    if Ms > 0 then
609      Inc(PISC_TIME(bufptr)^,Ms*10);
610   end;
611  
612 < function TFB25ClientAPI.SQLDecodeTime(bufptr: PChar): TDateTime;
612 > function TFB25ClientAPI.SQLDecodeTime(bufptr: PByte): TDateTime;
613   var
614    tm_date: TCTimeStructure;
615    msecs: Word;
# Line 606 | Line 626 | begin
626    end;
627   end;
628  
629 < procedure TFB25ClientAPI.SQLEncodeDateTime(aDateTime: TDateTime; bufptr: PChar);
629 > procedure TFB25ClientAPI.SQLEncodeDateTime(aDateTime: TDateTime; bufptr: PByte);
630   var
631    tm_date: TCTimeStructure;
632    Yr, Mn, Dy, Hr, Mt, S, Ms: Word;
# Line 626 | Line 646 | begin
646      Inc(PISC_TIMESTAMP(bufptr)^.timestamp_time,Ms*10);
647   end;
648  
649 < function TFB25ClientAPI.SQLDecodeDateTime(bufptr: PChar): TDateTime;
649 > function TFB25ClientAPI.SQLDecodeDateTime(bufptr: PByte): TDateTime;
650   var
651    tm_date: TCTimeStructure;
652    msecs: Word;
# Line 651 | Line 671 | end;
671  
672   end.
673  
674 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines