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 221 by tony, Mon Mar 19 09:48:37 2018 UTC vs.
Revision 263 by tony, Thu Dec 6 15:55:01 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 = 1;
134 <  FBIntf_Release = 2;
135 <  FBIntf_Version = '1.1.2';
134 >  FBIntf_Release = 3;
135 >  FBIntf_Version = '1.1.3';
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 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 862 | 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;
# Line 948 | Line 962 | type
962        AllowReverseLookup:boolean; out CharSetID: integer);
963    end;
964  
965 <  TProtocolAll = (TCP, SPX, NamedPipe, Local, inet, wnet, xnet, unknownProtocol);
965 >  TProtocolAll = (TCP, SPX, NamedPipe, Local, inet, inet4, inet6, wnet, xnet, unknownProtocol);
966    TProtocol = TCP..xnet;
967  
968    {Service Parameter Block (SPB).
# Line 1054 | Line 1068 | type
1068      property Count: integer read getCount;
1069    end;
1070  
1071 +  IFirebirdLibrary = interface;
1072 +
1073    {The IServiceManager interface provides access to a service manager. It can
1074     used to Detach and re-attach to Service Manager, to start services and to
1075     query the service manager.
# Line 1065 | Line 1081 | type
1081  
1082    IServiceManager = interface
1083      ['{905b587d-1e1f-4e40-a3f8-a3519f852e48}']
1084 +    function getFirebirdAPI: IFirebirdAPI;
1085      function getSPB: ISPB;
1086      function getServerName: AnsiString;
1087      function getProtocol: TProtocol;
# Line 1079 | Line 1096 | type
1096      function Query(Request: ISRB; RaiseExceptionOnError: boolean=true) :IServiceQueryResults; overload;
1097    end;
1098  
1099 +  {Tbe Firebird Library API used to get information about the Firebird library}
1100 +
1101 +
1102 +  IFirebirdLibrary = interface
1103 +    ['{3c04e0a1-12e0-428a-b2e1-bc6fcd97b79b}']
1104 +    function GetHandle: TLibHandle;
1105 +    function GetLibraryName: string;
1106 +    function GetLibraryFilePath: string;
1107 +    function GetFirebirdAPI: IFirebirdAPI;
1108 +  end;
1109 +
1110    {The Firebird API.
1111  
1112     This is the base interface and is used to create/open a database connection, to
# Line 1110 | Line 1138 | type
1138  
1139      {Information}
1140      function GetStatus: IStatus;
1113    function GetLibraryName: string;
1141      function HasRollbackRetaining: boolean;
1142      function IsEmbeddedServer: boolean;
1143      function GetImplementationVersion: AnsiString;
# Line 1118 | Line 1145 | type
1145      {Firebird 3 API}
1146      function HasMasterIntf: boolean;
1147      function GetIMaster: TObject;
1148 +    function GetFBLibrary: IFirebirdLibrary;
1149   end;
1150  
1151   type
# Line 1170 | Line 1198 | function FirebirdAPI: IFirebirdAPI;
1198   function TryIBLoad: Boolean;
1199   procedure CheckIBLoaded;
1200  
1201 + {If you want to explicitly load the Firebird library from a
1202 + non-default location then use this function and its GetFirebirdAPI function
1203 + to get the API.}
1204 +
1205 + function LoadFBLibrary(aLibPathName: string): IFirebirdLibrary;
1206 +
1207   implementation
1208  
1209   uses FBClientAPI
1210    {$IFDEF USELEGACYFIREBIRDAPI}, FB25ClientAPI {$ENDIF}
1211    {$IFDEF USEFIREBIRD3API}, FB30ClientAPI {$ENDIF};
1212  
1213 < var FFirebirdAPI: IFirebirdAPI;
1213 > var FDefaultFBLibrary: IFirebirdLibrary;
1214 >
1215 > type
1216 >
1217 >  { TFBLibrary }
1218 >
1219 >  TFBLibraryImpl = class(TFBLibrary)
1220 >  protected
1221 >    function GetFirebird3API: IFirebirdAPI; override;
1222 >    function GetLegacyFirebirdAPI: IFirebirdAPI; override;
1223 >  end;
1224 >
1225 > function TFBLibraryImpl.GetFirebird3API: IFirebirdAPI;
1226 > begin
1227 > {$IFDEF USEFIREBIRD3API}
1228 > Result := TFB30ClientAPI.Create(self);
1229 > {$ELSE}
1230 > Result := nil;
1231 > {$ENDIF}
1232 > end;
1233 >
1234 > function TFBLibraryImpl.GetLegacyFirebirdAPI: IFirebirdAPI;
1235 > begin
1236 >  {$IFDEF USELEGACYFIREBIRDAPI}
1237 >  Result := TFB25ClientAPI.Create(self);
1238 >  {$ELSE}
1239 >  Result := nil;
1240 >  {$ENDIF}
1241 > end;
1242  
1243   function FirebirdAPI: IFirebirdAPI;
1244   begin
1245 <  if FFirebirdAPI = nil then
1245 >  if FDefaultFBLibrary = nil then
1246      CheckIBLoaded;
1247 <  Result := FFirebirdAPI;
1247 >  Result := FDefaultFBLibrary.GetFirebirdAPI;
1248   end;
1249  
1250   function TryIBLoad: Boolean;
1251 + var fblib: IFirebirdLibrary;
1252   begin
1253 < Result := FFirebirdAPI <> nil;
1253 > Result := FDefaultFBLibrary <> nil;
1254   try
1192  {$IFDEF USEFIREBIRD3API}
1193  if not Result then
1194  begin
1195    FFirebirdAPI := TFB30ClientAPI.Create;
1196    Result := FFirebirdAPI.HasMasterIntf;
1197  end;
1198  {$ENDIF}
1199  {$IFDEF USELEGACYFIREBIRDAPI}
1255    if not Result then
1256    begin
1257 <    FFirebirdAPI := nil;
1258 <    FFirebirdAPI := TFB25ClientAPI.Create;
1259 <    Result := true;
1260 <  end;
1206 <  {$ENDIF}
1207 <  if Result and not (FFirebirdAPI as TFBClientAPI).IsLibraryLoaded then
1208 <  begin
1209 <    Result := false;
1210 <    FFirebirdAPI := nil;
1257 >    fblib := TFBLibraryImpl.Create;
1258 >    if (fblib <> nil) and (fblib.GetFirebirdAPI <> nil) then
1259 >      FDefaultFBLibrary := fblib;
1260 >    Result := FDefaultFBLibrary <> nil;
1261    end;
1262   except
1263     SysUtils.showexception(ExceptObject,ExceptAddr);
# Line 1221 | Line 1271 | begin
1271      IBError(ibxeInterBaseMissing, [nil]);
1272   end;
1273  
1274 + function LoadFBLibrary(aLibPathName: string): IFirebirdLibrary;
1275 + var fblib: IFirebirdLibrary;
1276 + begin
1277 +  if trim(aLibPathName) = '' then
1278 +  begin
1279 +    CheckIBLoaded;
1280 +    Result := FDefaultFBLibrary;
1281 +  end
1282 +  else
1283 +  begin
1284 +    fblib := TFBLibraryImpl.GetFBLibrary(aLibPathName);
1285 +    if (fblib = nil) or (fblib.GetFirebirdAPI = nil) then
1286 +      IBError(ibxeInterBaseMissing, [nil]);
1287 +    Result := fblib;
1288 +  end;
1289 + end;
1290 +
1291   { EIBError }
1292  
1293   constructor EIBError.Create(ASQLCode: Long; Msg: AnsiString);
# Line 1251 | Line 1318 | begin
1318   end;
1319  
1320   initialization
1321 <  FFirebirdAPI := nil;
1321 >  FDefaultFBLibrary := nil;
1322  
1323   finalization
1324 <  FFirebirdAPI := nil;
1324 >  FDefaultFBLibrary := nil;
1325  
1326   end.
1327  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines