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

Comparing ibx/trunk/fbintf/IB.pas (file contents):
Revision 109 by tony, Thu Jan 18 14:37:48 2018 UTC vs.
Revision 270 by tony, Fri Jan 18 11:10:37 2019 UTC

# Line 73 | Line 73 | unit IB;
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 122 | 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 = 0;
138 <  FBIntf_Release = 2;
139 <  FBIntf_Version = '1.0.2';
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}
# Line 173 | Line 180 | type
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
# Line 200 | Line 215 | type
215    TFBStatusCode = cardinal;
216    TByteArray = array of byte;
217  
218 +  IFirebirdAPI = interface;
219    IAttachment = interface;
220    ITransaction = interface;
221  
# Line 395 | 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
# Line 415 | 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 +    function GetDateTimeStrLength(DateTimeFormat: TIBDateTimeFormats): integer;
439      property Name: AnsiString read GetName;
440      property Size: cardinal read GetSize;
441      property SQLType: cardinal read GetSQLType;
# Line 632 | Line 653 | type
653                  psRealTime, psUserTime, psBuffers,
654                  psReads, psWrites, psFetches,psDeltaMemory);
655  
656 <  TPerfCounters = array[TPerfStats] of comp;
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.
# Line 646 | Line 667 | type
667      function GetRowsAffected(var SelectCount, InsertCount, UpdateCount, DeleteCount: integer): boolean;
668      function GetSQLStatementType: TIBSQLStatementTypes;
669      function GetSQLText: AnsiString;
670 +    function GetProcessedSQLText: AnsiString;
671      function GetSQLDialect: integer;
672      function IsPrepared: boolean;
673      procedure Prepare(aTransaction: ITransaction=nil);
# Line 773 | Line 795 | type
795      function getAsInteger: integer;
796      procedure DecodeIDCluster(var ConnectionType: integer; var DBFileName, DBSiteName: AnsiString);
797      function getAsBytes: TByteArray;
798 +    function getAsDateTime: TDateTime;
799      procedure DecodeVersionString(var Version: byte; var VersionString: AnsiString);
800      function getOperationCounts: TDBOperationCounts;
801      procedure DecodeUserNames(UserNames: TStrings);
# Line 799 | 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 847 | Line 884 | type
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;
# Line 881 | Line 920 | type
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): IStatement; overload;
923 >                       aSQLDialect: integer; GenerateParamNames: boolean=false;
924 >                       CaseSensitiveParams: boolean = false): IStatement; overload;
925      function PrepareWithNamedParameters(transaction: ITransaction; sql: AnsiString;
926 <                       GenerateParamNames: boolean=false): IStatement; overload;
926 >                       GenerateParamNames: boolean=false;
927 >                       CaseSensitiveParams: boolean = false): IStatement; overload;
928  
929      {Events}
930      function GetEventHandler(Events: TStrings): IEvents; overload;
# Line 911 | Line 952 | type
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}
# Line 925 | Line 974 | type
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 1030 | 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 1041 | Line 1093 | type
1093  
1094    IServiceManager = interface
1095      ['{905b587d-1e1f-4e40-a3f8-a3519f852e48}']
1096 +    function getFirebirdAPI: IFirebirdAPI;
1097      function getSPB: ISPB;
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 1079 | Line 1145 | type
1145      {Service Manager}
1146      function HasServiceAPI: boolean;
1147      function AllocateSPB: ISPB;
1148 <    function GetServiceManager(ServerName: AnsiString; 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;
1086    function GetLibraryName: string;
1153      function HasRollbackRetaining: boolean;
1154      function IsEmbeddedServer: boolean;
1155      function GetImplementationVersion: AnsiString;
# Line 1091 | Line 1157 | type
1157      {Firebird 3 API}
1158      function HasMasterIntf: boolean;
1159      function GetIMaster: TObject;
1160 +    function GetFBLibrary: IFirebirdLibrary;
1161   end;
1162  
1163   type
# Line 1143 | 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
1165  {$IFDEF USEFIREBIRD3API}
1267    if not Result then
1268    begin
1269 <    FFirebirdAPI := TFB30ClientAPI.Create;
1270 <    Result := FFirebirdAPI.HasMasterIntf;
1271 <  end;
1272 <  {$ENDIF}
1172 <  {$IFDEF USELEGACYFIREBIRDAPI}
1173 <  if not Result then
1174 <  begin
1175 <    FFirebirdAPI := nil;
1176 <    FFirebirdAPI := TFB25ClientAPI.Create;
1177 <    Result := true;
1178 <  end;
1179 <  {$ENDIF}
1180 <  if Result and not (FFirebirdAPI as TFBClientAPI).IsLibraryLoaded then
1181 <  begin
1182 <    Result := false;
1183 <    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 1194 | 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: AnsiString);
# Line 1224 | 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