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

Comparing ibx/trunk/fbintf/IB.pas (file contents):
Revision 87 by tony, Mon Jan 1 11:31:26 2018 UTC vs.
Revision 266 by tony, Wed Dec 26 18:34:32 2018 UTC

# Line 122 | Line 122 | unit IB;
122   interface
123  
124   uses
125 <  Classes, SysUtils, DB, FBMessages, IBExternals;
125 >  Classes,
126 >  {$IFDEF WINDOWS}Windows, {$ENDIF}
127 >  {$IFDEF FPC} Dynlibs, {$ENDIF}
128 >  SysUtils, DB, FBMessages, IBExternals;
129  
130   const
131    {Interface version information}
132    FBIntf_Major = 1;
133 <  FBIntf_Minor = 0;
134 <  FBIntf_Release = 2;
135 <  FBIntf_Version = '1.0.2';
133 >  FBIntf_Minor = 1;
134 >  FBIntf_Release = 4;
135 >  FBIntf_Version = '1.1.4';
136  
137   {These include files are converted from the 'C' originals in the Firebird API
138   and define the various constants used by the API}
# Line 173 | Line 176 | type
176     PISC_QUAD            = ^TISC_QUAD;
177  
178   {$IFNDEF FPC}
179 + {Delphi missing definitions}
180 + type
181 +  TLibHandle = THandle;
182 +
183 + const
184 +  NilHandle = 0;
185 +  DirectorySeparator = '\';
186 +
187   {Delphi only seems to define CP_UTF8 and CP_UTF16}
188   const
189    CP_ACP     = 0;     // default to ANSI code page
# Line 200 | Line 211 | type
211    TFBStatusCode = cardinal;
212    TByteArray = array of byte;
213  
214 +  IFirebirdAPI = interface;
215    IAttachment = interface;
216    ITransaction = interface;
217  
# Line 632 | Line 644 | type
644                  psRealTime, psUserTime, psBuffers,
645                  psReads, psWrites, psFetches,psDeltaMemory);
646  
647 <  TPerfCounters = array[TPerfStats] of comp;
647 >  TPerfCounters = array[TPerfStats] of Int64;
648  
649    {The IStatement interface provides access to an SQL Statement once it has been
650     initially prepared. The interface is returned from the IAttachment interface.
# Line 646 | Line 658 | type
658      function GetRowsAffected(var SelectCount, InsertCount, UpdateCount, DeleteCount: integer): boolean;
659      function GetSQLStatementType: TIBSQLStatementTypes;
660      function GetSQLText: AnsiString;
661 +    function GetProcessedSQLText: AnsiString;
662      function GetSQLDialect: integer;
663      function IsPrepared: boolean;
664      procedure Prepare(aTransaction: ITransaction=nil);
# Line 773 | Line 786 | type
786      function getAsInteger: integer;
787      procedure DecodeIDCluster(var ConnectionType: integer; var DBFileName, DBSiteName: AnsiString);
788      function getAsBytes: TByteArray;
789 +    function getAsDateTime: TDateTime;
790      procedure DecodeVersionString(var Version: byte; var VersionString: AnsiString);
791      function getOperationCounts: TDBOperationCounts;
792      procedure DecodeUserNames(UserNames: TStrings);
# Line 799 | Line 813 | type
813      property Items[index: integer]: IDBInfoItem read getItem; default;
814    end;
815  
816 +  {The Database Information Request Block is used to pass requests for
817 +   database information where at least one item requested has a parameter.
818 +   At present, this is only fb_info_page_contents which has a single
819 +   integer parameter.}
820 +
821 +  IDIRBItem = interface(IParameterBlockItem)
822 +    ['{d34a7511-8435-4a24-81a7-5103d218d234}']
823 +  end;
824 +
825 +  IDIRB = interface(IParameterBlock<IDIRBItem>)
826 +    ['{1010e5ac-0a8f-403b-a302-91625e9d9579}']
827 +  end;
828 +
829 +
830    {The Database Parameter Block (DPB).
831  
832     The DPB provides the parameters used when connecting to a database. It is allocated
# Line 847 | Line 875 | type
875  
876    IAttachment = interface
877      ['{466e9b67-9def-4807-b3e7-e08a35e7185c}']
878 +    function getFirebirdAPI: IFirebirdAPI;
879      function getDPB: IDPB;
880      function AllocateBPB: IBPB;
881 +    function AllocateDIRB: IDIRB;
882      procedure Connect;
883      procedure Disconnect(Force: boolean=false);
884      function IsConnected: boolean;
# Line 911 | Line 941 | type
941      function GetArrayMetaData(Transaction: ITransaction; tableName, columnName: AnsiString): IArrayMetaData;
942      function GetDBInformation(Requests: array of byte): IDBInformation; overload;
943      function GetDBInformation(Request: byte): IDBInformation; overload;
944 +    function GetDBInformation(Requests: IDIRB): IDBInformation; overload;
945 +    function GetConnectString: AnsiString;
946 +    function GetRemoteProtocol: AnsiString;
947 +    function GetAuthenticationMethod: AnsiString;
948 +    function GetSecurityDatabase: AnsiString;
949 +    function GetODSMajorVersion: integer;
950 +    function GetODSMinorVersion: integer;
951 +    procedure getFBVersion(version: TStrings);
952      function HasActivity: boolean;
953  
954      {Character Sets}
955 +    function HasDefaultCharSet: boolean;
956 +    function GetDefaultCharSetID: integer;
957      function GetCharsetName(CharSetID: integer): AnsiString;
958      function CharSetID2CodePage(CharSetID: integer; var CodePage: TSystemCodePage): boolean;
959      function CodePage2CharSetID(CodePage: TSystemCodePage; var CharSetID: integer): boolean;
# Line 923 | Line 963 | type
963        AllowReverseLookup:boolean; out CharSetID: integer);
964    end;
965  
966 <  TProtocol = (TCP, SPX, NamedPipe, Local);
966 >  TProtocolAll = (TCP, SPX, NamedPipe, Local, inet, inet4, inet6, wnet, xnet, unknownProtocol);
967 >  TProtocol = TCP..xnet;
968  
969    {Service Parameter Block (SPB).
970  
# Line 1028 | Line 1069 | type
1069      property Count: integer read getCount;
1070    end;
1071  
1072 +  IFirebirdLibrary = interface;
1073 +
1074    {The IServiceManager interface provides access to a service manager. It can
1075     used to Detach and re-attach to Service Manager, to start services and to
1076     query the service manager.
# Line 1039 | Line 1082 | type
1082  
1083    IServiceManager = interface
1084      ['{905b587d-1e1f-4e40-a3f8-a3519f852e48}']
1085 +    function getFirebirdAPI: IFirebirdAPI;
1086      function getSPB: ISPB;
1087      function getServerName: AnsiString;
1088 +    function getProtocol: TProtocol;
1089 +    function getPortNo: AnsiString;
1090      procedure Attach;
1091      procedure Detach(Force: boolean=false);
1092      function IsAttached: boolean;
1093      function AllocateSRB: ISRB;
1094      function AllocateSQPB: ISQPB;
1095 <    procedure Start(Request: ISRB);
1096 <    function Query(SQPB: ISQPB; Request: ISRB) :IServiceQueryResults; overload;
1097 <    function Query(Request: ISRB) :IServiceQueryResults; overload;
1095 >    function Start(Request: ISRB; RaiseExceptionOnError: boolean=true): boolean;
1096 >    function Query(SQPB: ISQPB; Request: ISRB; RaiseExceptionOnError: boolean=true) :IServiceQueryResults; overload;
1097 >    function Query(Request: ISRB; RaiseExceptionOnError: boolean=true) :IServiceQueryResults; overload;
1098 >  end;
1099 >
1100 >  {Tbe Firebird Library API used to get information about the Firebird library}
1101 >
1102 >
1103 >  IFirebirdLibrary = interface
1104 >    ['{3c04e0a1-12e0-428a-b2e1-bc6fcd97b79b}']
1105 >    function GetHandle: TLibHandle;
1106 >    function GetLibraryName: string;
1107 >    function GetLibraryFilePath: string;
1108 >    function GetFirebirdAPI: IFirebirdAPI;
1109    end;
1110  
1111    {The Firebird API.
# Line 1077 | Line 1134 | type
1134      {Service Manager}
1135      function HasServiceAPI: boolean;
1136      function AllocateSPB: ISPB;
1137 <    function GetServiceManager(ServerName: AnsiString; Protocol: TProtocol; SPB: ISPB): IServiceManager;
1137 >    function GetServiceManager(ServerName: AnsiString; Protocol: TProtocol; SPB: ISPB): IServiceManager; overload;
1138 >    function GetServiceManager(ServerName: AnsiString; Port: AnsiString; Protocol: TProtocol; SPB: ISPB): IServiceManager; overload;
1139  
1140      {Information}
1141      function GetStatus: IStatus;
1084    function GetLibraryName: string;
1142      function HasRollbackRetaining: boolean;
1143      function IsEmbeddedServer: boolean;
1144      function GetImplementationVersion: AnsiString;
# Line 1089 | Line 1146 | type
1146      {Firebird 3 API}
1147      function HasMasterIntf: boolean;
1148      function GetIMaster: TObject;
1149 +    function GetFBLibrary: IFirebirdLibrary;
1150   end;
1151  
1152   type
# Line 1141 | Line 1199 | function FirebirdAPI: IFirebirdAPI;
1199   function TryIBLoad: Boolean;
1200   procedure CheckIBLoaded;
1201  
1202 + {If you want to explicitly load the Firebird library from a
1203 + non-default location then use this function and its GetFirebirdAPI function
1204 + to get the API.}
1205 +
1206 + function LoadFBLibrary(aLibPathName: string): IFirebirdLibrary;
1207 +
1208   implementation
1209  
1210   uses FBClientAPI
1211    {$IFDEF USELEGACYFIREBIRDAPI}, FB25ClientAPI {$ENDIF}
1212    {$IFDEF USEFIREBIRD3API}, FB30ClientAPI {$ENDIF};
1213  
1214 < var FFirebirdAPI: IFirebirdAPI;
1214 > var FDefaultFBLibrary: IFirebirdLibrary;
1215 >
1216 > type
1217 >
1218 >  { TFBLibrary }
1219 >
1220 >  TFBLibraryImpl = class(TFBLibrary)
1221 >  protected
1222 >    function GetFirebird3API: IFirebirdAPI; override;
1223 >    function GetLegacyFirebirdAPI: IFirebirdAPI; override;
1224 >  end;
1225 >
1226 > function TFBLibraryImpl.GetFirebird3API: IFirebirdAPI;
1227 > begin
1228 > {$IFDEF USEFIREBIRD3API}
1229 > Result := TFB30ClientAPI.Create(self);
1230 > {$ELSE}
1231 > Result := nil;
1232 > {$ENDIF}
1233 > end;
1234 >
1235 > function TFBLibraryImpl.GetLegacyFirebirdAPI: IFirebirdAPI;
1236 > begin
1237 >  {$IFDEF USELEGACYFIREBIRDAPI}
1238 >  Result := TFB25ClientAPI.Create(self);
1239 >  {$ELSE}
1240 >  Result := nil;
1241 >  {$ENDIF}
1242 > end;
1243  
1244   function FirebirdAPI: IFirebirdAPI;
1245   begin
1246 <  if FFirebirdAPI = nil then
1246 >  if FDefaultFBLibrary = nil then
1247      CheckIBLoaded;
1248 <  Result := FFirebirdAPI;
1248 >  Result := FDefaultFBLibrary.GetFirebirdAPI;
1249   end;
1250  
1251   function TryIBLoad: Boolean;
1252 + var fblib: IFirebirdLibrary;
1253   begin
1254 < Result := FFirebirdAPI <> nil;
1254 > Result := FDefaultFBLibrary <> nil;
1255   try
1163  {$IFDEF USEFIREBIRD3API}
1256    if not Result then
1257    begin
1258 <    FFirebirdAPI := TFB30ClientAPI.Create;
1259 <    Result := FFirebirdAPI.HasMasterIntf;
1260 <  end;
1261 <  {$ENDIF}
1170 <  {$IFDEF USELEGACYFIREBIRDAPI}
1171 <  if not Result then
1172 <  begin
1173 <    FFirebirdAPI := nil;
1174 <    FFirebirdAPI := TFB25ClientAPI.Create;
1175 <    Result := true;
1176 <  end;
1177 <  {$ENDIF}
1178 <  if Result and not (FFirebirdAPI as TFBClientAPI).IsLibraryLoaded then
1179 <  begin
1180 <    Result := false;
1181 <    FFirebirdAPI := nil;
1258 >    fblib := TFBLibraryImpl.Create;
1259 >    if (fblib <> nil) and (fblib.GetFirebirdAPI <> nil) then
1260 >      FDefaultFBLibrary := fblib;
1261 >    Result := FDefaultFBLibrary <> nil;
1262    end;
1263   except
1264     SysUtils.showexception(ExceptObject,ExceptAddr);
# Line 1192 | Line 1272 | begin
1272      IBError(ibxeInterBaseMissing, [nil]);
1273   end;
1274  
1275 + function LoadFBLibrary(aLibPathName: string): IFirebirdLibrary;
1276 + var fblib: IFirebirdLibrary;
1277 + begin
1278 +  if trim(aLibPathName) = '' then
1279 +  begin
1280 +    CheckIBLoaded;
1281 +    Result := FDefaultFBLibrary;
1282 +  end
1283 +  else
1284 +  begin
1285 +    fblib := TFBLibraryImpl.GetFBLibrary(aLibPathName);
1286 +    if (fblib = nil) or (fblib.GetFirebirdAPI = nil) then
1287 +      IBError(ibxeInterBaseMissing, [nil]);
1288 +    Result := fblib;
1289 +  end;
1290 + end;
1291 +
1292   { EIBError }
1293  
1294   constructor EIBError.Create(ASQLCode: Long; Msg: AnsiString);
# Line 1222 | Line 1319 | begin
1319   end;
1320  
1321   initialization
1322 <  FFirebirdAPI := nil;
1322 >  FDefaultFBLibrary := nil;
1323  
1324 + finalization
1325 +  FDefaultFBLibrary := nil;
1326  
1327   end.
1328  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines