ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/fbintf/IB.pas
(Generate patch)

Comparing ibx/trunk/fbintf/IB.pas (file contents):
Revision 45 by tony, Tue Dec 6 10:33:46 2016 UTC vs.
Revision 270 by tony, Fri Jan 18 11:10:37 2019 UTC

# Line 60 | Line 60
60   {                                                                        }
61   {************************************************************************}
62   unit IB;
63 + {$IFDEF MSWINDOWS}
64 + {$DEFINE WINDOWS}
65 + {$ENDIF}
66  
67   {$IFDEF FPC}
68 < {$mode objfpc}{$H+}
68 > {$mode delphi}
69   {$codepage UTF8}
70   {$interfaces COM}
71 < {$IF FPC_FULLVERSION < 30000 }
71 > {$IF defined(FPC) and (FPC_FULLVERSION < 30000) }
72   {$ERROR FPC Version 3.0.0 or later is required}
73 < {$ENDIF}
73 > {$IFEND}
74   {$ENDIF}
75  
76 + {$IFNDEF LEGACYFIREBIRDAPIONLY}
77   {$DEFINE USEFIREBIRD3API}
78 + {$ENDIF}
79 + {$IFNDEF FIREBIRD3APIONLY}
80   {$DEFINE USELEGACYFIREBIRDAPI}
81 + {$ENDIF}
82  
83   {
84    This unit defines the interfaces used to provide the Pascal Language
# Line 103 | Line 110 | unit IB;
110  
111    5. Straightforward progammatic access to the Firebird API from Pascal programs.
112  
113 +  6. FPC and Delphi Support.
114 +
115    String Types
116    ============
117  
# Line 117 | Line 126 | unit IB;
126   interface
127  
128   uses
129 <  Classes, SysUtils, DB, FBMessages, IBExternals;
129 >  Classes,
130 >  {$IFDEF WINDOWS}Windows, {$ENDIF}
131 >  {$IFDEF FPC} Dynlibs, {$ENDIF}
132 >  SysUtils, DB, FBMessages, IBExternals;
133 >
134 > const
135 >  {Interface version information}
136 >  FBIntf_Major = 1;
137 >  FBIntf_Minor = 1;
138 >  FBIntf_Release = 4;
139 >  FBIntf_Version = '1.1.4';
140  
141   {These include files are converted from the 'C' originals in the Firebird API
142   and define the various constants used by the API}
143  
144 < {$I consts_pub.inc}
145 < {$I inf_pub.inc}
146 < {$I configkeys.inc}
144 > {$I 'include/consts_pub.inc'}
145 > {$I 'include/inf_pub.inc'}
146 > {$I 'include/configkeys.inc'}
147  
148   {The following constants define the values return by calls to the GetSQLType
149   methods provided by several of the interfaces defined below.}
# Line 160 | Line 179 | type
179     PGDS__QUAD           = ^TGDS__QUAD;
180     PISC_QUAD            = ^TISC_QUAD;
181  
182 + {$IFNDEF FPC}
183 + {Delphi missing definitions}
184 + type
185 +  TLibHandle = THandle;
186 +
187 + const
188 +  NilHandle = 0;
189 +  DirectorySeparator = '\';
190 +
191 + {Delphi only seems to define CP_UTF8 and CP_UTF16}
192 + const
193 +  CP_ACP     = 0;     // default to ANSI code page
194 +  CP_OEMCP   = 1;     // default to OEM (console) code page
195 +  CP_UTF16BE = 1201;  // unicodeFFFE
196 +  CP_UTF7    = 65000; // utf-7
197 +  CP_ASCII   = 20127; // us-ascii
198 +  CP_NONE    = $FFFF; // rawbytestring encoding
199 +
200 + {$ENDIF}
201 +
202 + type
203 + {$IF not declared(TSystemCodePage)}
204 +  TSystemCodePage = word; {not defined in Delphi}
205 + {$IFEND}
206 +
207    TIBSQLStatementTypes =
208                   (SQLUnknown, SQLSelect, SQLInsert,
209                    SQLUpdate, SQLDelete, SQLDDL,
# Line 171 | Line 215 | type
215    TFBStatusCode = cardinal;
216    TByteArray = array of byte;
217  
218 +  IFirebirdAPI = interface;
219    IAttachment = interface;
220    ITransaction = interface;
221  
222 <  {The IParameterBlock generic interface provides the template for all parameter
222 >  {The IParameterBlock interface provides the template for all parameter
223     block interfaces}
224  
225 <  generic IParameterBlock<_IItem> = interface
225 >  IParameterBlock<_IItem> = interface
226      function getCount: integer;
227      function Add(ParamType: byte): _IItem;
228      function getItems(index: integer): _IItem;
# Line 191 | Line 236 | type
236     different parameter block items }
237  
238    IParameterBlockItem = interface
239 +    ['{53b23f7b-abda-46a5-9aa5-07bd5e723266}']
240      function getParamType: byte;
241      function getAsInteger: integer;
242 <    function getAsString: string;
242 >    function getAsString: AnsiString;
243      function getAsByte: byte;
244 <    procedure setAsString(aValue: string);
244 >    procedure setAsString(aValue: AnsiString);
245      procedure setAsByte(aValue: byte);
246      procedure SetAsInteger(aValue: integer);
247 <    property AsString: string read getAsString write setAsString;
247 >    property AsString: AnsiString read getAsString write setAsString;
248      property AsByte: byte read getAsByte write setAsByte;
249      property AsInteger: integer read getAsInteger write SetAsInteger;
250    end;
# Line 212 | Line 258 | type
258     }
259  
260    IStatus = interface
261 +    ['{34167722-af38-4831-b08a-93162d58ede3}']
262      function GetIBErrorCode: Long;
263      function Getsqlcode: Long;
264 <    function GetMessage: string;
264 >    function GetMessage: AnsiString;
265      function CheckStatusVector(ErrorCodes: array of TFBStatusCode): Boolean;
266      function GetIBDataBaseErrorMessages: TIBDataBaseErrorMessages;
267      procedure SetIBDataBaseErrorMessages(Value: TIBDataBaseErrorMessages);
# Line 231 | Line 278 | type
278    TArrayBounds = array of TArrayBound;
279  
280    IArrayMetaData = interface
281 +    ['{7dd0aea4-59af-4c2a-b958-565d5025c489}']
282      function GetSQLType: cardinal;
283 <    function GetSQLTypeName: string;
283 >    function GetSQLTypeName: AnsiString;
284      function GetScale: integer;
285      function GetSize: cardinal;
286      function GetCharSetID: cardinal;
287 <    function GetTableName: string;
288 <    function GetColumnName: string;
287 >    function GetTableName: AnsiString;
288 >    function GetColumnName: AnsiString;
289      function GetDimensions: integer;
290      function GetBounds: TArrayBounds;
291    end;
# Line 262 | Line 310 | type
310    TArrayEventHandler = procedure(Sender: IArray; Reason: TArrayEventReason) of object;
311  
312    IArray = interface(IArrayMetaData)
313 +    ['{631c6bb1-fb49-44fb-a64a-c49859632b88}']
314      function GetArrayID: TISC_QUAD;
315      procedure Clear;
316      function IsEmpty: boolean;
# Line 277 | Line 326 | type
326      function GetAsFloat(index: array of integer): Float;
327      function GetAsLong(index: array of integer): Long;
328      function GetAsShort(index: array of integer): Short;
329 <    function GetAsString(index: array of integer): String;
329 >    function GetAsString(index: array of integer): AnsiString;
330      function GetAsVariant(index: array of integer): Variant;
331      procedure SetAsInteger(index: array of integer; AValue: integer);
332      procedure SetAsBoolean(index: array of integer; AValue: boolean);
# Line 290 | Line 339 | type
339      procedure SetAsDouble(index: array of integer; Value: Double);
340      procedure SetAsFloat(index: array of integer; Value: Float);
341      procedure SetAsShort(index: array of integer; Value: Short);
342 <    procedure SetAsString(index: array of integer; Value: String);
342 >    procedure SetAsString(index: array of integer; Value: AnsiString);
343      procedure SetAsVariant(index: array of integer; Value: Variant);
344      procedure SetBounds(dim, UpperBound, LowerBound: integer);
345      function GetAttachment: IAttachment;
# Line 304 | Line 353 | type
353    }
354  
355    IBlobMetaData = interface
356 +    ['{575f3c61-bb33-46a5-8975-bb7d1b6e37cc}']
357      function GetSubType: integer;
358      function GetCharSetID: cardinal;
359      function GetCodePage: TSystemCodePage;
360      function GetSegmentSize: cardinal;
361 <    function GetRelationName: string;
362 <    function GetColumnName: string;
361 >    function GetRelationName: AnsiString;
362 >    function GetColumnName: AnsiString;
363    end;
364  
365    {The Blob Parameter block is used to select a Blob Filter}
366  
367 <  IBPBItem = interface (IParameterBlockItem) end;
367 >  IBPBItem = interface (IParameterBlockItem)
368 >    ['{660822a5-3114-4c16-b6cb-c1a7b2aba70d}']
369 >  end;
370  
371 <  IBPB = specialize IParameterBlock<IBPBItem>;
371 >  IBPB = interface (IParameterBlock<IBPBItem>)
372 >    ['{e0cb9eb5-17f7-4416-b7d1-3cddd1dfca76}']
373 >  end;
374  
375    { The Blob Interface provides access to a blob data item.
376  
# Line 330 | Line 384 | type
384    TBlobType = (btSegmented,btStream);
385  
386    IBlob = interface(IBlobMetaData)
387 +    ['{3090a145-7780-442b-b15b-efd4568b8611}']
388      function GetBPB: IBPB;
389      procedure Cancel;
390      procedure Close;
# Line 340 | Line 395 | type
395                        TotalSize: Int64; var BlobType: TBlobType);
396      function Read(var Buffer; Count: Longint): Longint;
397      function Write(const Buffer; Count: Longint): Longint;
398 <    function LoadFromFile(Filename: string): IBlob;
398 >    function LoadFromFile(Filename: AnsiString): IBlob;
399      function LoadFromStream(S: TStream) : IBlob;
400 <    function SaveToFile(Filename: string): IBlob;
400 >    function SaveToFile(Filename: AnsiString): IBlob;
401      function SaveToStream(S: TStream): IBlob;
402      function GetAsString: rawbytestring;
403      procedure SetAsString(aValue: rawbytestring);
# Line 356 | Line 411 | type
411      the output of an SQL Statement.
412    }
413  
414 +  TIBDateTimeFormats = (dfTimestamp, {SQL TIMESTAMP}
415 +                        dfDateTime,   {SQL DATETIME}
416 +                        dfTime);      {SQL TIME}
417 +
418    { IColumnMetaData }
419  
420    IColumnMetaData = interface
421 +    ['{c222e6c3-53c1-469f-9e05-0a5c3ef232d8}']
422      function GetIndex: integer;
423      function GetSQLType: cardinal;
424 <    function GetSQLTypeName: string;
424 >    function GetSQLTypeName: AnsiString;
425      function getSubtype: integer;
426 <    function getRelationName: string;
427 <    function getOwnerName: string;
428 <    function getSQLName: string;    {Name of the column}
429 <    function getAliasName: string;  {Alias Name of column or Column Name if no alias}
430 <    function getName: string;       {Disambiguated uppercase Field Name}
426 >    function getRelationName: AnsiString;
427 >    function getOwnerName: AnsiString;
428 >    function getSQLName: AnsiString;    {Name of the column}
429 >    function getAliasName: AnsiString;  {Alias Name of column or Column Name if no alias}
430 >    function getName: AnsiString;       {Disambiguated uppercase Field Name}
431      function getScale: integer;
432      function getCharSetID: cardinal;
433      function getCodePage: TSystemCodePage;
# Line 375 | Line 435 | type
435      function GetSize: cardinal;
436      function GetArrayMetaData: IArrayMetaData; {Valid only for Array SQL Type}
437      function GetBlobMetaData: IBlobMetaData; {Valid only for Blob SQL Type}
438 <    property Name: string read GetName;
438 >    function GetDateTimeStrLength(DateTimeFormat: TIBDateTimeFormats): integer;
439 >    property Name: AnsiString read GetName;
440      property Size: cardinal read GetSize;
441      property SQLType: cardinal read GetSQLType;
442      property Scale: integer read getScale;
# Line 391 | Line 452 | type
452    { IMetaData }
453  
454    IMetaData = interface
455 +    ['{4dafdbb6-0d36-4f1f-9c95-8b132804b965}']
456      function getCount: integer;
457      function getColumnMetaData(index: integer): IColumnMetaData;
458 <    function GetUniqueRelationName: string; {Non empty if all columns come from the same table}
459 <    function ByName(Idx: String): IColumnMetaData;
458 >    function GetUniqueRelationName: AnsiString; {Non empty if all columns come from the same table}
459 >    function ByName(Idx: AnsiString): IColumnMetaData;
460      property ColMetaData[index: integer]: IColumnMetaData read getColumnMetaData; default;
461      property Count: integer read getCount;
462    end;
# Line 414 | Line 476 | type
476  
477  
478    ISQLData = interface(IColumnMetaData)
479 +    ['{3f493e31-7e3f-4606-a07c-b210b9e3619d}']
480      function GetAsBoolean: boolean;
481      function GetAsCurrency: Currency;
482      function GetAsInt64: Int64;
# Line 424 | Line 487 | type
487      function GetAsPointer: Pointer;
488      function GetAsQuad: TISC_QUAD;
489      function GetAsShort: short;
490 <    function GetAsString: String;
490 >    function GetAsString: AnsiString;
491      function GetIsNull: Boolean;
492      function GetAsVariant: Variant;
493      function GetAsBlob: IBlob; overload;
# Line 443 | Line 506 | type
506      property AsPointer: Pointer read GetAsPointer;
507      property AsQuad: TISC_QUAD read GetAsQuad;
508      property AsShort: short read GetAsShort;
509 <    property AsString: String read GetAsString;
509 >    property AsString: AnsiString read GetAsString;
510      property AsVariant: Variant read GetAsVariant ;
511      property AsBlob: IBlob read GetAsBlob;
512      property AsArray: IArray read GetAsArray;
# Line 458 | Line 521 | type
521    }
522  
523    IResults = interface
524 +    ['{e836b2bb-93d1-4bbf-a8eb-7ce535de3bb5}']
525     function getCount: integer;
526     function GetTransaction: ITransaction;
527 <   function ByName(Idx: String): ISQLData;
527 >   function ByName(Idx: AnsiString): ISQLData;
528     function getSQLData(index: integer): ISQLData;
529 <   procedure GetData(index: integer; var IsNull:boolean; var len: short; var data: PChar);
529 >   procedure GetData(index: integer; var IsNull:boolean; var len: short; var data: PByte);
530     procedure SetRetainInterfaces(aValue: boolean);
531     property Data[index: integer]: ISQLData read getSQLData; default;
532     property Count: integer read getCount;
# Line 474 | Line 538 | type
538      in turn, used to access the data returned by each field of the current row.
539    }
540    IResultSet = interface(IResults)
541 +    ['{0ae4979b-7857-4e8c-8918-ec6f155b51a0}']
542      function FetchNext: boolean;
543 <    function GetCursorName: string;
543 >    function GetCursorName: AnsiString;
544      function IsEof: boolean;
545      procedure Close;
546    end;
# Line 496 | Line 561 | type
561    }
562  
563    ISQLParam = interface
564 +    ['{b22b4578-6d41-4807-a9a9-d2ec8d1d5a14}']
565      function GetIndex: integer;
566      function GetSQLType: cardinal;
567 <    function GetSQLTypeName: string;
567 >    function GetSQLTypeName: AnsiString;
568      function getSubtype: integer;
569 <    function getName: string;
569 >    function getName: AnsiString;
570      function getScale: integer;
571      function getCharSetID: cardinal;
572      function getCodePage: TSystemCodePage;
# Line 516 | Line 582 | type
582      function GetAsPointer: Pointer;
583      function GetAsQuad: TISC_QUAD;
584      function GetAsShort: short;
585 <    function GetAsString: String;
585 >    function GetAsString: AnsiString;
586      function GetIsNull: boolean;
587      function GetAsVariant: Variant;
588      function GetAsBlob: IBlob;
# Line 534 | Line 600 | type
600      procedure SetAsFloat(aValue: Float);
601      procedure SetAsPointer(aValue: Pointer);
602      procedure SetAsShort(aValue: Short);
603 <    procedure SetAsString(aValue: String);
603 >    procedure SetAsString(aValue: AnsiString);
604      procedure SetAsVariant(aValue: Variant);
605      procedure SetIsNull(aValue: Boolean);
606      procedure SetAsBlob(aValue: IBlob);
# Line 553 | Line 619 | type
619      property AsLong: Long read GetAsLong write SetAsLong;
620      property AsPointer: Pointer read GetAsPointer write SetAsPointer;
621      property AsShort: Short read GetAsShort write SetAsShort;
622 <    property AsString: String read GetAsString write SetAsString;
622 >    property AsString: AnsiString read GetAsString write SetAsString;
623      property AsVariant: Variant read GetAsVariant write SetAsVariant;
624      property AsBlob: IBlob read GetAsBlob write SetAsBlob;
625      property AsArray: IArray read GetAsArray write SetAsArray;
# Line 562 | Line 628 | type
628      property IsNull: Boolean read GetIsNull write SetIsNull;
629      property IsNullable: Boolean read GetIsNullable;
630      property Modified: Boolean read getModified;
631 <    property Name: string read GetName;
631 >    property Name: AnsiString read GetName;
632      property SQLType: cardinal read GetSQLType;
633    end;
634  
# Line 572 | Line 638 | type
638    }
639  
640    ISQLParams = interface
641 +    ['{c6d95ac7-b2b7-461b-b890-afef0acbb077}']
642      function getCount: integer;
643      function getSQLParam(index: integer): ISQLParam;
644 <    function ByName(Idx: String): ISQLParam ;
644 >    function ByName(Idx: AnsiString): ISQLParam ;
645      function GetModified: Boolean;
646      property Modified: Boolean read GetModified;
647      property Params[index: integer]: ISQLParam read getSQLParam; default;
648      property Count: integer read getCount;
649    end;
650  
651 +
652 +  TPerfStats = (psCurrentMemory, psMaxMemory,
653 +                psRealTime, psUserTime, psBuffers,
654 +                psReads, psWrites, psFetches,psDeltaMemory);
655 +
656 +  TPerfCounters = array[TPerfStats] of Int64;
657 +
658    {The IStatement interface provides access to an SQL Statement once it has been
659     initially prepared. The interface is returned from the IAttachment interface.
660     }
661  
662    IStatement = interface
663 +    ['{a260576d-a07d-4a66-b02d-1b72543fd7cf}']
664      function GetMetaData: IMetaData;  {Output Metadata}
665      function GetSQLParams: ISQLParams;{Statement Parameters}
666 <    function GetPlan: String;
666 >    function GetPlan: AnsiString;
667      function GetRowsAffected(var SelectCount, InsertCount, UpdateCount, DeleteCount: integer): boolean;
668      function GetSQLStatementType: TIBSQLStatementTypes;
669 <    function GetSQLText: string;
669 >    function GetSQLText: AnsiString;
670 >    function GetProcessedSQLText: AnsiString;
671      function GetSQLDialect: integer;
672      function IsPrepared: boolean;
673      procedure Prepare(aTransaction: ITransaction=nil);
# Line 600 | Line 676 | type
676      function GetAttachment: IAttachment;
677      function GetTransaction: ITransaction;
678      procedure SetRetainInterfaces(aValue: boolean);
679 +    procedure EnableStatistics(aValue: boolean);
680 +    function GetPerfStatistics(var stats: TPerfCounters): boolean;
681      property MetaData: IMetaData read GetMetaData;
682      property SQLParams: ISQLParams read GetSQLParams;
683      property SQLStatementType: TIBSQLStatementTypes read GetSQLStatementType;
# Line 616 | Line 694 | type
694     found in the Interbase 6.0 API Guide.
695    }
696  
697 <  ITPBItem = interface(IParameterBlockItem) end;
697 >  ITPBItem = interface(IParameterBlockItem)
698 >    ['{544c1f2b-7c12-4a87-a4a5-face7ea72671}']
699 >  end;
700  
701 <  ITPB = specialize IParameterBlock<ITPBItem>;
701 >  ITPB = interface(IParameterBlock<ITPBItem>)
702 >    ['{7369b0ff-defe-437b-81fe-19b211d42d25}']
703 >  end;
704  
705    {The ITransactionAction interface provides access to a Transaction once it
706     has been initially started. After a Commit or Rollback, a transaction
# Line 632 | Line 714 | type
714    TTransactionCompletion = TARollback.. TACommit;
715  
716    ITransaction = interface
717 +    ['{30928d0e-a9d7-4c61-b7cf-14f4f38abe2a}']
718      function getTPB: ITPB;
719      procedure Start(DefaultCompletion: TTransactionCompletion=taCommit);
720      function GetInTransaction: boolean;
# Line 659 | Line 742 | type
742    }
743  
744    TEventInfo = record
745 <    EventName: string;
745 >    EventName: AnsiString;
746      Count: integer;
747    end;
748  
# Line 670 | Line 753 | type
753    { IEvents }
754  
755    IEvents = interface
756 +    ['{6a0be233-ed08-4524-889c-2e45d0c20e5f}']
757      procedure GetEvents(EventNames: TStrings);
758      procedure SetEvents(EventNames: TStrings); overload;
759 <    procedure SetEvents(EventName: string); overload;
759 >    procedure SetEvents(EventName: AnsiString); overload;
760      procedure Cancel;
761      function ExtractEventCounts: TEventCounts;
762      procedure WaitForEvent;
# Line 703 | Line 787 | type
787    TDBOperationCounts = array of TDBOperationCount;
788  
789    IDBInfoItem = interface
790 +    ['{eeb97b51-ec0f-473f-9f75-c1721f055fcb}']
791      function getItemType: byte;
792      function getSize: integer;
793      procedure getRawBytes(var Buffer);
794 <    function getAsString: string;
794 >    function getAsString: AnsiString;
795      function getAsInteger: integer;
796 <    procedure DecodeIDCluster(var ConnectionType: integer; var DBFileName, DBSiteName: string);
796 >    procedure DecodeIDCluster(var ConnectionType: integer; var DBFileName, DBSiteName: AnsiString);
797      function getAsBytes: TByteArray;
798 <    procedure DecodeVersionString(var Version: byte; var VersionString: string);
798 >    function getAsDateTime: TDateTime;
799 >    procedure DecodeVersionString(var Version: byte; var VersionString: AnsiString);
800      function getOperationCounts: TDBOperationCounts;
801      procedure DecodeUserNames(UserNames: TStrings);
802  
# Line 719 | Line 805 | type
805      function GetItem(index: integer): IDBInfoItem;
806      function Find(ItemType: byte): IDBInfoItem;
807      property AsInteger: integer read getAsInteger;
808 <    property AsString: string read GetAsString;
808 >    property AsString: AnsiString read GetAsString;
809      property Count: integer read GetCount;
810      property Items[index: integer]: IDBInfoItem read getItem; default;
811    end;
# Line 727 | Line 813 | type
813    { IDBInformation }
814  
815    IDBInformation = interface
816 +    ['{7ac6777f-f0a9-498a-9f5c-4a57a554df81}']
817      function GetCount: integer;
818      function GetItem(index: integer): IDBInfoItem;
819      function Find(ItemType: byte): IDBInfoItem;
# Line 735 | Line 822 | type
822      property Items[index: integer]: IDBInfoItem read getItem; default;
823    end;
824  
825 +  {The Database Information Request Block is used to pass requests for
826 +   database information where at least one item requested has a parameter.
827 +   At present, this is only fb_info_page_contents which has a single
828 +   integer parameter.}
829 +
830 +  IDIRBItem = interface(IParameterBlockItem)
831 +    ['{d34a7511-8435-4a24-81a7-5103d218d234}']
832 +  end;
833 +
834 +  IDIRB = interface(IParameterBlock<IDIRBItem>)
835 +    ['{1010e5ac-0a8f-403b-a302-91625e9d9579}']
836 +  end;
837 +
838 +
839    {The Database Parameter Block (DPB).
840  
841     The DPB provides the parameters used when connecting to a database. It is allocated
# Line 746 | Line 847 | type
847     found in the Interbase 6.0 API Guide.
848     }
849  
850 <  IDPBItem = interface(IParameterBlockItem) end;
850 >  IDPBItem = interface(IParameterBlockItem)
851 >    ['{123d4ad0-087a-4cd1-a344-1b3d03b30673}']
852 >  end;
853  
854 <  IDPB = specialize IParameterBlock<IDPBItem>;
854 >  IDPB = interface(IParameterBlock<IDPBItem>)
855 >    ['{e676067b-1cf4-4eba-9256-9724f57e0d16}']
856 >  end;
857  
858    {The IAttachment interface provides access to a Database Connection. It may be
859     used to:
# Line 778 | Line 883 | type
883    { IAttachment }
884  
885    IAttachment = interface
886 +    ['{466e9b67-9def-4807-b3e7-e08a35e7185c}']
887 +    function getFirebirdAPI: IFirebirdAPI;
888      function getDPB: IDPB;
889      function AllocateBPB: IBPB;
890 +    function AllocateDIRB: IDIRB;
891      procedure Connect;
892      procedure Disconnect(Force: boolean=false);
893      function IsConnected: boolean;
894      procedure DropDatabase;
895      function StartTransaction(TPB: array of byte; DefaultCompletion: TTransactionCompletion=taCommit): ITransaction; overload;
896      function StartTransaction(TPB: ITPB; DefaultCompletion: TTransactionCompletion=taCommit): ITransaction; overload;
897 <    procedure ExecImmediate(transaction: ITransaction; sql: string; SQLDialect: integer); overload;
898 <    procedure ExecImmediate(TPB: array of byte; sql: string; SQLDialect: integer); overload;
899 <    procedure ExecImmediate(transaction: ITransaction; sql: string); overload;
900 <    procedure ExecImmediate(TPB: array of byte; sql: string); overload;
901 <    function ExecuteSQL(TPB: array of byte; sql: string; SQLDialect: integer; params: array of const): IResults; overload;
902 <    function ExecuteSQL(transaction: ITransaction; sql: string; SQLDialect: integer; params: array of const): IResults; overload;
903 <    function ExecuteSQL(TPB: array of byte; sql: string; params: array of const): IResults; overload;
904 <    function ExecuteSQL(transaction: ITransaction; sql: string; params: array of const): IResults; overload;
905 <    function OpenCursor(transaction: ITransaction; sql: string; aSQLDialect: integer): IResultSet; overload;
906 <    function OpenCursor(transaction: ITransaction; sql: string; aSQLDialect: integer;
897 >    procedure ExecImmediate(transaction: ITransaction; sql: AnsiString; SQLDialect: integer); overload;
898 >    procedure ExecImmediate(TPB: array of byte; sql: AnsiString; SQLDialect: integer); overload;
899 >    procedure ExecImmediate(transaction: ITransaction; sql: AnsiString); overload;
900 >    procedure ExecImmediate(TPB: array of byte; sql: AnsiString); overload;
901 >    function ExecuteSQL(TPB: array of byte; sql: AnsiString; SQLDialect: integer; params: array of const): IResults; overload;
902 >    function ExecuteSQL(transaction: ITransaction; sql: AnsiString; SQLDialect: integer; params: array of const): IResults; overload;
903 >    function ExecuteSQL(TPB: array of byte; sql: AnsiString; params: array of const): IResults; overload;
904 >    function ExecuteSQL(transaction: ITransaction; sql: AnsiString; params: array of const): IResults; overload;
905 >    function OpenCursor(transaction: ITransaction; sql: AnsiString; aSQLDialect: integer): IResultSet; overload;
906 >    function OpenCursor(transaction: ITransaction; sql: AnsiString; aSQLDialect: integer;
907                               params: array of const): IResultSet; overload;
908 <    function OpenCursor(transaction: ITransaction; sql: string): IResultSet; overload;
909 <    function OpenCursor(transaction: ITransaction; sql: string;
908 >    function OpenCursor(transaction: ITransaction; sql: AnsiString): IResultSet; overload;
909 >    function OpenCursor(transaction: ITransaction; sql: AnsiString;
910                               params: array of const): IResultSet; overload;
911 <    function OpenCursorAtStart(transaction: ITransaction; sql: string; aSQLDialect: integer): IResultSet; overload;
912 <    function OpenCursorAtStart(transaction: ITransaction; sql: string; aSQLDialect: integer;
911 >    function OpenCursorAtStart(transaction: ITransaction; sql: AnsiString; aSQLDialect: integer): IResultSet; overload;
912 >    function OpenCursorAtStart(transaction: ITransaction; sql: AnsiString; aSQLDialect: integer;
913                               params: array of const): IResultSet; overload;
914 <    function OpenCursorAtStart(transaction: ITransaction; sql: string): IResultSet; overload;
915 <    function OpenCursorAtStart(transaction: ITransaction; sql: string;
914 >    function OpenCursorAtStart(transaction: ITransaction; sql: AnsiString): IResultSet; overload;
915 >    function OpenCursorAtStart(transaction: ITransaction; sql: AnsiString;
916                               params: array of const): IResultSet; overload;
917 <    function OpenCursorAtStart(sql: string): IResultSet; overload;
918 <    function OpenCursorAtStart(sql: string;
917 >    function OpenCursorAtStart(sql: AnsiString): IResultSet; overload;
918 >    function OpenCursorAtStart(sql: AnsiString;
919                               params: array of const): IResultSet; overload;
920 <    function Prepare(transaction: ITransaction; sql: string; aSQLDialect: integer): IStatement; overload;
921 <    function Prepare(transaction: ITransaction; sql: string): IStatement; overload;
922 <    function PrepareWithNamedParameters(transaction: ITransaction; sql: string;
923 <                       aSQLDialect: integer; GenerateParamNames: boolean=false): IStatement; overload;
924 <    function PrepareWithNamedParameters(transaction: ITransaction; sql: string;
925 <                       GenerateParamNames: boolean=false): IStatement; overload;
920 >    function Prepare(transaction: ITransaction; sql: AnsiString; aSQLDialect: integer): IStatement; overload;
921 >    function Prepare(transaction: ITransaction; sql: AnsiString): IStatement; overload;
922 >    function PrepareWithNamedParameters(transaction: ITransaction; sql: AnsiString;
923 >                       aSQLDialect: integer; GenerateParamNames: boolean=false;
924 >                       CaseSensitiveParams: boolean = false): IStatement; overload;
925 >    function PrepareWithNamedParameters(transaction: ITransaction; sql: AnsiString;
926 >                       GenerateParamNames: boolean=false;
927 >                       CaseSensitiveParams: boolean = false): IStatement; overload;
928  
929      {Events}
930      function GetEventHandler(Events: TStrings): IEvents; overload;
931 <    function GetEventHandler(Event: string): IEvents; overload;
931 >    function GetEventHandler(Event: AnsiString): IEvents; overload;
932  
933      {Blob - may use to open existing Blobs. However, ISQLData.AsBlob is preferred}
934  
935 <    function CreateBlob(transaction: ITransaction; RelationName, ColumnName: string; BPB: IBPB=nil): IBlob; overload;
935 >    function CreateBlob(transaction: ITransaction; RelationName, ColumnName: AnsiString; BPB: IBPB=nil): IBlob; overload;
936      function CreateBlob(transaction: ITransaction; BlobMetaData: IBlobMetaData; BPB: IBPB=nil): IBlob; overload;
937      function CreateBlob(transaction: ITransaction; SubType: integer; CharSetID: cardinal=0; BPB: IBPB=nil): IBlob; overload;
938 <    function OpenBlob(transaction: ITransaction; RelationName, ColumnName: string; BlobID: TISC_QUAD; BPB: IBPB=nil): IBlob;
938 >    function OpenBlob(transaction: ITransaction; RelationName, ColumnName: AnsiString; BlobID: TISC_QUAD; BPB: IBPB=nil): IBlob;
939  
940      {Array - may use to open existing arrays. However, ISQLData.AsArray is preferred}
941  
942 <    function OpenArray(transaction: ITransaction; RelationName, ColumnName: string; ArrayID: TISC_QUAD): IArray;
943 <    function CreateArray(transaction: ITransaction; RelationName, ColumnName: string): IArray; overload;
942 >    function OpenArray(transaction: ITransaction; RelationName, ColumnName: AnsiString; ArrayID: TISC_QUAD): IArray;
943 >    function CreateArray(transaction: ITransaction; RelationName, ColumnName: AnsiString): IArray; overload;
944      function CreateArray(transaction: ITransaction; ArrayMetaData: IArrayMetaData): IArray; overload;
945 +    function CreateArrayMetaData(SQLType: cardinal; tableName: AnsiString; columnName: AnsiString;
946 +                  Scale: integer; size: cardinal; charSetID: cardinal; dimensions: cardinal;
947 +                  bounds: TArrayBounds): IArrayMetaData;
948  
949      {Database Information}
950      function GetSQLDialect: integer;
951 <    function GetBlobMetaData(Transaction: ITransaction; tableName, columnName: string): IBlobMetaData;
952 <    function GetArrayMetaData(Transaction: ITransaction; tableName, columnName: string): IArrayMetaData;
951 >    function GetBlobMetaData(Transaction: ITransaction; tableName, columnName: AnsiString): IBlobMetaData;
952 >    function GetArrayMetaData(Transaction: ITransaction; tableName, columnName: AnsiString): IArrayMetaData;
953      function GetDBInformation(Requests: array of byte): IDBInformation; overload;
954      function GetDBInformation(Request: byte): IDBInformation; overload;
955 +    function GetDBInformation(Requests: IDIRB): IDBInformation; overload;
956 +    function GetConnectString: AnsiString;
957 +    function GetRemoteProtocol: AnsiString;
958 +    function GetAuthenticationMethod: AnsiString;
959 +    function GetSecurityDatabase: AnsiString;
960 +    function GetODSMajorVersion: integer;
961 +    function GetODSMinorVersion: integer;
962 +    procedure getFBVersion(version: TStrings);
963      function HasActivity: boolean;
964 +
965 +    {Character Sets}
966 +    function HasDefaultCharSet: boolean;
967 +    function GetDefaultCharSetID: integer;
968 +    function GetCharsetName(CharSetID: integer): AnsiString;
969 +    function CharSetID2CodePage(CharSetID: integer; var CodePage: TSystemCodePage): boolean;
970 +    function CodePage2CharSetID(CodePage: TSystemCodePage; var CharSetID: integer): boolean;
971 +    function CharSetName2CharSetID(CharSetName: AnsiString; var CharSetID: integer): boolean;
972 +    function CharSetWidth(CharSetID: integer; var Width: integer): boolean;
973 +    procedure RegisterCharSet(CharSetName: AnsiString; CodePage: TSystemCodePage;
974 +      AllowReverseLookup:boolean; out CharSetID: integer);
975    end;
976  
977 <  TProtocol = (TCP, SPX, NamedPipe, Local);
977 >  TProtocolAll = (TCP, SPX, NamedPipe, Local, inet, inet4, inet6, wnet, xnet, unknownProtocol);
978 >  TProtocol = TCP..xnet;
979  
980    {Service Parameter Block (SPB).
981  
# Line 856 | Line 989 | type
989  
990    }
991  
992 <  ISPBItem = interface(IParameterBlockItem) end;
992 >  ISPBItem = interface(IParameterBlockItem)
993 >    ['{5d08ae2b-4519-41bd-8b40-97cd451c3f6a}']
994 >  end;
995  
996 <  ISPB = specialize IParameterBlock<ISPBItem>;
996 >  ISPB = interface(IParameterBlock<ISPBItem>)
997 >    ['{2c5836fd-41ed-4426-9b7d-5af580ec2659}']
998 >  end;
999  
1000    {Service Query Parameter Block (SQPB).
1001  
# Line 867 | Line 1004 | type
1004    }
1005  
1006    ISQPBItem = interface(IParameterBlockItem)
1007 +    ['{b07841a6-33b3-47f0-b5a2-028cbc86dc97}']
1008      function CopyFrom(source: TStream; count: integer): integer;
1009    end;
1010  
1011 <  ISQPB = specialize IParameterBlock<ISQPBItem>;
1011 >  ISQPB = interface(IParameterBlock<ISQPBItem>)
1012 >    ['{8553e66b-ee62-498b-8431-dff030211447}']
1013 >  end;
1014  
1015    {Service Request Block (SRB).
1016  
# Line 884 | Line 1024 | type
1024  
1025    }
1026  
1027 <  ISRBItem = interface(IParameterBlockItem) end;
1027 >  ISRBItem = interface(IParameterBlockItem)
1028 >    ['{47ec790e-f265-4b30-9dcd-261e51677245}']
1029 >   end;
1030  
1031 <  ISRB = specialize IParameterBlock<ISRBItem>;
1031 >  ISRB = interface(IParameterBlock<ISRBItem>)
1032 >    ['{9f2e204f-3c33-4e44-90f9-9135e95dafb9}']
1033 >  end;
1034  
1035    {The Service Query Results Interface.
1036  
# Line 904 | Line 1048 | type
1048    }
1049  
1050    IServiceQueryResultSubItem = interface
1051 +    ['{8a4c381e-9923-4cc9-a96b-553729248640}']
1052      function getItemType: byte;
1053      function getSize: integer;
1054      procedure getRawBytes(var Buffer);
1055 <    function getAsString: string;
1055 >    function getAsString: AnsiString;
1056      function getAsInteger: integer;
1057      function getAsByte: byte;
1058      function CopyTo(stream: TStream; count: integer): integer;
1059 <    property AsString: string read getAsString;
1059 >    property AsString: AnsiString read getAsString;
1060      property AsInteger: integer read getAsInteger;
1061      property AsByte: byte read getAsByte;
1062    end;
1063  
1064    IServiceQueryResultItem = interface(IServiceQueryResultSubItem)
1065 +    ['{b2806886-206c-4024-8df9-5fe0a7630a5e}']
1066      function getCount: integer;
1067      function getItem(index: integer): IServiceQueryResultSubItem;
1068      function find(ItemType: byte): IServiceQueryResultSubItem;
# Line 925 | Line 1071 | type
1071    end;
1072  
1073    IServiceQueryResults = interface
1074 +    ['{8fbbef7d-fe03-4409-828a-a787d34ef531}']
1075      function getCount: integer;
1076      function getItem(index: integer): IServiceQueryResultItem;
1077      function find(ItemType: byte): IServiceQueryResultItem;
# Line 933 | Line 1080 | type
1080      property Count: integer read getCount;
1081    end;
1082  
1083 +  IFirebirdLibrary = interface;
1084 +
1085    {The IServiceManager interface provides access to a service manager. It can
1086     used to Detach and re-attach to Service Manager, to start services and to
1087     query the service manager.
# Line 943 | Line 1092 | type
1092    { IServiceManager }
1093  
1094    IServiceManager = interface
1095 +    ['{905b587d-1e1f-4e40-a3f8-a3519f852e48}']
1096 +    function getFirebirdAPI: IFirebirdAPI;
1097      function getSPB: ISPB;
1098 <    function getServerName: string;
1098 >    function getServerName: AnsiString;
1099 >    function getProtocol: TProtocol;
1100 >    function getPortNo: AnsiString;
1101      procedure Attach;
1102      procedure Detach(Force: boolean=false);
1103      function IsAttached: boolean;
1104      function AllocateSRB: ISRB;
1105      function AllocateSQPB: ISQPB;
1106 <    procedure Start(Request: ISRB);
1107 <    function Query(SQPB: ISQPB; Request: ISRB) :IServiceQueryResults; overload;
1108 <    function Query(Request: ISRB) :IServiceQueryResults; overload;
1106 >    function Start(Request: ISRB; RaiseExceptionOnError: boolean=true): boolean;
1107 >    function Query(SQPB: ISQPB; Request: ISRB; RaiseExceptionOnError: boolean=true) :IServiceQueryResults; overload;
1108 >    function Query(Request: ISRB; RaiseExceptionOnError: boolean=true) :IServiceQueryResults; overload;
1109 >  end;
1110 >
1111 >  {Tbe Firebird Library API used to get information about the Firebird library}
1112 >
1113 >
1114 >  IFirebirdLibrary = interface
1115 >    ['{3c04e0a1-12e0-428a-b2e1-bc6fcd97b79b}']
1116 >    function GetHandle: TLibHandle;
1117 >    function GetLibraryName: string;
1118 >    function GetLibraryFilePath: string;
1119 >    function GetFirebirdAPI: IFirebirdAPI;
1120    end;
1121  
1122    {The Firebird API.
# Line 964 | Line 1128 | type
1128    }
1129  
1130    IFirebirdAPI = interface
1131 +    ['{edeee691-c8d3-4dcf-a780-cd7e432821d5}']
1132      {Database connections}
1133      function AllocateDPB: IDPB;
1134 <    function OpenDatabase(DatabaseName: string; DPB: IDPB; RaiseExceptionOnConnectError: boolean=true): IAttachment;
1135 <    function CreateDatabase(DatabaseName: string; DPB: IDPB; RaiseExceptionOnError: boolean=true): IAttachment;
1134 >    function OpenDatabase(DatabaseName: AnsiString; DPB: IDPB; RaiseExceptionOnConnectError: boolean=true): IAttachment;
1135 >    function CreateDatabase(DatabaseName: AnsiString; DPB: IDPB; RaiseExceptionOnError: boolean=true): IAttachment; overload;
1136 >    function CreateDatabase(sql: AnsiString; aSQLDialect: integer; RaiseExceptionOnError: boolean=true): IAttachment; overload;
1137  
1138      {Start Transaction against multiple databases}
1139      function AllocateTPB: ITPB;
# Line 979 | Line 1145 | type
1145      {Service Manager}
1146      function HasServiceAPI: boolean;
1147      function AllocateSPB: ISPB;
1148 <    function GetServiceManager(ServerName: string; Protocol: TProtocol; SPB: ISPB): IServiceManager;
1148 >    function GetServiceManager(ServerName: AnsiString; Protocol: TProtocol; SPB: ISPB): IServiceManager; overload;
1149 >    function GetServiceManager(ServerName: AnsiString; Port: AnsiString; Protocol: TProtocol; SPB: ISPB): IServiceManager; overload;
1150  
1151      {Information}
1152      function GetStatus: IStatus;
986    function GetLibraryName: string;
1153      function HasRollbackRetaining: boolean;
1154      function IsEmbeddedServer: boolean;
1155 <    function GetImplementationVersion: string;
1155 >    function GetImplementationVersion: AnsiString;
1156  
1157      {Firebird 3 API}
1158      function HasMasterIntf: boolean;
1159      function GetIMaster: TObject;
1160 <
995 <    {utility}
996 <    function GetCharsetName(CharSetID: integer): string;
997 <    function CharSetID2CodePage(CharSetID: integer; var CodePage: TSystemCodePage): boolean;
998 <    function CodePage2CharSetID(CodePage: TSystemCodePage; var CharSetID: integer): boolean;
999 <    function CharSetName2CharSetID(CharSetName: string; var CharSetID: integer): boolean;
1000 <    function CharSetWidth(CharSetID: integer; var Width: integer): boolean;
1160 >    function GetFBLibrary: IFirebirdLibrary;
1161   end;
1162  
1163   type
# Line 1014 | Line 1174 | type
1174     private
1175       FSQLCode: Long;
1176     public
1177 <     constructor Create(ASQLCode: Long; Msg: string);
1177 >     constructor Create(ASQLCode: Long; Msg: AnsiString);
1178       property SQLCode: Long read FSQLCode;
1179     end;
1180  
# Line 1025 | Line 1185 | type
1185       FIBErrorCode: Long;
1186     public
1187       constructor Create(Status: IStatus); overload;
1188 <     constructor Create(ASQLCode: Long; AIBErrorCode: Long; Msg: string); overload;
1188 >     constructor Create(ASQLCode: Long; AIBErrorCode: Long; Msg: AnsiString); overload;
1189       property IBErrorCode: Long read FIBErrorCode;
1190     end;
1191  
# Line 1050 | Line 1210 | function FirebirdAPI: IFirebirdAPI;
1210   function TryIBLoad: Boolean;
1211   procedure CheckIBLoaded;
1212  
1213 + {If you want to explicitly load the Firebird library from a
1214 + non-default location then use this function and its GetFirebirdAPI function
1215 + to get the API.}
1216 +
1217 + function LoadFBLibrary(aLibPathName: string): IFirebirdLibrary;
1218 +
1219   implementation
1220  
1221   uses FBClientAPI
1222    {$IFDEF USELEGACYFIREBIRDAPI}, FB25ClientAPI {$ENDIF}
1223    {$IFDEF USEFIREBIRD3API}, FB30ClientAPI {$ENDIF};
1224  
1225 < var FFirebirdAPI: IFirebirdAPI;
1225 > var FDefaultFBLibrary: IFirebirdLibrary;
1226 >
1227 > type
1228 >
1229 >  { TFBLibrary }
1230 >
1231 >  TFBLibraryImpl = class(TFBLibrary)
1232 >  protected
1233 >    function GetFirebird3API: IFirebirdAPI; override;
1234 >    function GetLegacyFirebirdAPI: IFirebirdAPI; override;
1235 >  end;
1236 >
1237 > function TFBLibraryImpl.GetFirebird3API: IFirebirdAPI;
1238 > begin
1239 > {$IFDEF USEFIREBIRD3API}
1240 > Result := TFB30ClientAPI.Create(self);
1241 > {$ELSE}
1242 > Result := nil;
1243 > {$ENDIF}
1244 > end;
1245 >
1246 > function TFBLibraryImpl.GetLegacyFirebirdAPI: IFirebirdAPI;
1247 > begin
1248 >  {$IFDEF USELEGACYFIREBIRDAPI}
1249 >  Result := TFB25ClientAPI.Create(self);
1250 >  {$ELSE}
1251 >  Result := nil;
1252 >  {$ENDIF}
1253 > end;
1254  
1255   function FirebirdAPI: IFirebirdAPI;
1256   begin
1257 <  if FFirebirdAPI = nil then
1257 >  if FDefaultFBLibrary = nil then
1258      CheckIBLoaded;
1259 <  Result := FFirebirdAPI;
1259 >  Result := FDefaultFBLibrary.GetFirebirdAPI;
1260   end;
1261  
1262   function TryIBLoad: Boolean;
1263 + var fblib: IFirebirdLibrary;
1264   begin
1265 < Result := FFirebirdAPI <> nil;
1265 > Result := FDefaultFBLibrary <> nil;
1266   try
1072  {$IFDEF USEFIREBIRD3API}
1073  if not Result then
1074  begin
1075    FFirebirdAPI := TFB30ClientAPI.Create;
1076    Result := FFirebirdAPI.HasMasterIntf;
1077  end;
1078  {$ENDIF}
1079  {$IFDEF USELEGACYFIREBIRDAPI}
1267    if not Result then
1268    begin
1269 <    FFirebirdAPI := nil;
1270 <    FFirebirdAPI := TFB25ClientAPI.Create;
1271 <    Result := true;
1272 <  end;
1086 <  {$ENDIF}
1087 <  if Result and not (FFirebirdAPI as TFBClientAPI).IsLibraryLoaded then
1088 <  begin
1089 <    Result := false;
1090 <    FFirebirdAPI := nil;
1269 >    fblib := TFBLibraryImpl.Create;
1270 >    if (fblib <> nil) and (fblib.GetFirebirdAPI <> nil) then
1271 >      FDefaultFBLibrary := fblib;
1272 >    Result := FDefaultFBLibrary <> nil;
1273    end;
1274   except
1275     SysUtils.showexception(ExceptObject,ExceptAddr);
# Line 1101 | Line 1283 | begin
1283      IBError(ibxeInterBaseMissing, [nil]);
1284   end;
1285  
1286 + function LoadFBLibrary(aLibPathName: string): IFirebirdLibrary;
1287 + var fblib: IFirebirdLibrary;
1288 + begin
1289 +  if trim(aLibPathName) = '' then
1290 +  begin
1291 +    CheckIBLoaded;
1292 +    Result := FDefaultFBLibrary;
1293 +  end
1294 +  else
1295 +  begin
1296 +    fblib := TFBLibraryImpl.GetFBLibrary(aLibPathName);
1297 +    if (fblib = nil) or (fblib.GetFirebirdAPI = nil) then
1298 +      IBError(ibxeInterBaseMissing, [nil]);
1299 +    Result := fblib;
1300 +  end;
1301 + end;
1302 +
1303   { EIBError }
1304  
1305 < constructor EIBError.Create(ASQLCode: Long; Msg: string);
1305 > constructor EIBError.Create(ASQLCode: Long; Msg: AnsiString);
1306   begin
1307    inherited Create(Msg);
1308    FSQLCode := ASQLCode;
# Line 1118 | Line 1317 | begin
1317   end;
1318  
1319   constructor EIBInterBaseError.Create(ASQLCode: Long; AIBErrorCode: Long;
1320 <  Msg: string);
1320 >  Msg: AnsiString);
1321   begin
1322    inherited Create(ASQLCode,Msg);
1323    FIBErrorCode := AIBErrorCode;
# Line 1131 | Line 1330 | begin
1330   end;
1331  
1332   initialization
1333 <  FFirebirdAPI := nil;
1333 >  FDefaultFBLibrary := nil;
1334  
1335 + finalization
1336 +  FDefaultFBLibrary := nil;
1337  
1338   end.
1339  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines