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 60 by tony, Mon Mar 27 15:21:02 2017 UTC vs.
Revision 287 by tony, Thu Apr 11 08:51:23 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 = 5;
139 >  FBIntf_Version = '1.1.5';
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 352 | Line 368 | type
368      ['{660822a5-3114-4c16-b6cb-c1a7b2aba70d}']
369    end;
370  
371 <  IBPB = interface(IParameterBlock<IBPBItem>)
371 >  IBPB = interface (IParameterBlock<IBPBItem>)
372      ['{e0cb9eb5-17f7-4416-b7d1-3cddd1dfca76}']
373    end;
374  
# 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 622 | Line 643 | type
643      function getSQLParam(index: integer): ISQLParam;
644      function ByName(Idx: AnsiString): ISQLParam ;
645      function GetModified: Boolean;
646 +    function GetHasCaseSensitiveParams: Boolean;
647      property Modified: Boolean read GetModified;
648      property Params[index: integer]: ISQLParam read getSQLParam; default;
649      property Count: integer read getCount;
# Line 632 | Line 654 | type
654                  psRealTime, psUserTime, psBuffers,
655                  psReads, psWrites, psFetches,psDeltaMemory);
656  
657 <  TPerfCounters = array[TPerfStats] of comp;
657 >  TPerfCounters = array[TPerfStats] of Int64;
658  
659    {The IStatement interface provides access to an SQL Statement once it has been
660     initially prepared. The interface is returned from the IAttachment interface.
# Line 646 | Line 668 | type
668      function GetRowsAffected(var SelectCount, InsertCount, UpdateCount, DeleteCount: integer): boolean;
669      function GetSQLStatementType: TIBSQLStatementTypes;
670      function GetSQLText: AnsiString;
671 +    function GetProcessedSQLText: AnsiString;
672      function GetSQLDialect: integer;
673      function IsPrepared: boolean;
674      procedure Prepare(aTransaction: ITransaction=nil);
# Line 773 | Line 796 | type
796      function getAsInteger: integer;
797      procedure DecodeIDCluster(var ConnectionType: integer; var DBFileName, DBSiteName: AnsiString);
798      function getAsBytes: TByteArray;
799 +    function getAsDateTime: TDateTime;
800      procedure DecodeVersionString(var Version: byte; var VersionString: AnsiString);
801      function getOperationCounts: TDBOperationCounts;
802      procedure DecodeUserNames(UserNames: TStrings);
# Line 799 | Line 823 | type
823      property Items[index: integer]: IDBInfoItem read getItem; default;
824    end;
825  
826 +  {The Database Information Request Block is used to pass requests for
827 +   database information where at least one item requested has a parameter.
828 +   At present, this is only fb_info_page_contents which has a single
829 +   integer parameter.}
830 +
831 +  IDIRBItem = interface(IParameterBlockItem)
832 +    ['{d34a7511-8435-4a24-81a7-5103d218d234}']
833 +  end;
834 +
835 +  IDIRB = interface(IParameterBlock<IDIRBItem>)
836 +    ['{1010e5ac-0a8f-403b-a302-91625e9d9579}']
837 +  end;
838 +
839 +
840    {The Database Parameter Block (DPB).
841  
842     The DPB provides the parameters used when connecting to a database. It is allocated
# Line 847 | Line 885 | type
885  
886    IAttachment = interface
887      ['{466e9b67-9def-4807-b3e7-e08a35e7185c}']
888 +    function getFirebirdAPI: IFirebirdAPI;
889      function getDPB: IDPB;
890      function AllocateBPB: IBPB;
891 +    function AllocateDIRB: IDIRB;
892      procedure Connect;
893      procedure Disconnect(Force: boolean=false);
894      function IsConnected: boolean;
# Line 881 | Line 921 | type
921      function Prepare(transaction: ITransaction; sql: AnsiString; aSQLDialect: integer): IStatement; overload;
922      function Prepare(transaction: ITransaction; sql: AnsiString): IStatement; overload;
923      function PrepareWithNamedParameters(transaction: ITransaction; sql: AnsiString;
924 <                       aSQLDialect: integer; GenerateParamNames: boolean=false): IStatement; overload;
924 >                       aSQLDialect: integer; GenerateParamNames: boolean=false;
925 >                       CaseSensitiveParams: boolean = false): IStatement; overload;
926      function PrepareWithNamedParameters(transaction: ITransaction; sql: AnsiString;
927 <                       GenerateParamNames: boolean=false): IStatement; overload;
927 >                       GenerateParamNames: boolean=false;
928 >                       CaseSensitiveParams: boolean = false): IStatement; overload;
929  
930      {Events}
931      function GetEventHandler(Events: TStrings): IEvents; overload;
# Line 911 | Line 953 | type
953      function GetArrayMetaData(Transaction: ITransaction; tableName, columnName: AnsiString): IArrayMetaData;
954      function GetDBInformation(Requests: array of byte): IDBInformation; overload;
955      function GetDBInformation(Request: byte): IDBInformation; overload;
956 +    function GetDBInformation(Requests: IDIRB): IDBInformation; overload;
957 +    function GetConnectString: AnsiString;
958 +    function GetRemoteProtocol: AnsiString;
959 +    function GetAuthenticationMethod: AnsiString;
960 +    function GetSecurityDatabase: AnsiString;
961 +    function GetODSMajorVersion: integer;
962 +    function GetODSMinorVersion: integer;
963 +    procedure getFBVersion(version: TStrings);
964      function HasActivity: boolean;
965  
966      {Character Sets}
967 +    function HasDefaultCharSet: boolean;
968 +    function GetDefaultCharSetID: integer;
969      function GetCharsetName(CharSetID: integer): AnsiString;
970      function CharSetID2CodePage(CharSetID: integer; var CodePage: TSystemCodePage): boolean;
971      function CodePage2CharSetID(CodePage: TSystemCodePage; var CharSetID: integer): boolean;
# Line 923 | Line 975 | type
975        AllowReverseLookup:boolean; out CharSetID: integer);
976    end;
977  
978 <  TProtocol = (TCP, SPX, NamedPipe, Local);
978 >  TProtocolAll = (TCP, SPX, NamedPipe, Local, inet, inet4, inet6, wnet, xnet, unknownProtocol);
979 >  TProtocol = TCP..xnet;
980  
981    {Service Parameter Block (SPB).
982  
# Line 1028 | Line 1081 | type
1081      property Count: integer read getCount;
1082    end;
1083  
1084 +  IFirebirdLibrary = interface;
1085 +
1086    {The IServiceManager interface provides access to a service manager. It can
1087     used to Detach and re-attach to Service Manager, to start services and to
1088     query the service manager.
# Line 1039 | Line 1094 | type
1094  
1095    IServiceManager = interface
1096      ['{905b587d-1e1f-4e40-a3f8-a3519f852e48}']
1097 +    function getFirebirdAPI: IFirebirdAPI;
1098      function getSPB: ISPB;
1099      function getServerName: AnsiString;
1100 +    function getProtocol: TProtocol;
1101 +    function getPortNo: AnsiString;
1102      procedure Attach;
1103      procedure Detach(Force: boolean=false);
1104      function IsAttached: boolean;
1105      function AllocateSRB: ISRB;
1106      function AllocateSQPB: ISQPB;
1107 <    procedure Start(Request: ISRB);
1108 <    function Query(SQPB: ISQPB; Request: ISRB) :IServiceQueryResults; overload;
1109 <    function Query(Request: ISRB) :IServiceQueryResults; overload;
1107 >    function Start(Request: ISRB; RaiseExceptionOnError: boolean=true): boolean;
1108 >    function Query(SQPB: ISQPB; Request: ISRB; RaiseExceptionOnError: boolean=true) :IServiceQueryResults; overload;
1109 >    function Query(Request: ISRB; RaiseExceptionOnError: boolean=true) :IServiceQueryResults; overload;
1110 >  end;
1111 >
1112 >  {Tbe Firebird Library API used to get information about the Firebird library}
1113 >
1114 >
1115 >  IFirebirdLibrary = interface
1116 >    ['{3c04e0a1-12e0-428a-b2e1-bc6fcd97b79b}']
1117 >    function GetHandle: TLibHandle;
1118 >    function GetLibraryName: string;
1119 >    function GetLibraryFilePath: string;
1120 >    function GetFirebirdAPI: IFirebirdAPI;
1121    end;
1122  
1123    {The Firebird API.
# Line 1077 | Line 1146 | type
1146      {Service Manager}
1147      function HasServiceAPI: boolean;
1148      function AllocateSPB: ISPB;
1149 <    function GetServiceManager(ServerName: AnsiString; Protocol: TProtocol; SPB: ISPB): IServiceManager;
1149 >    function GetServiceManager(ServerName: AnsiString; Protocol: TProtocol; SPB: ISPB): IServiceManager; overload;
1150 >    function GetServiceManager(ServerName: AnsiString; Port: AnsiString; Protocol: TProtocol; SPB: ISPB): IServiceManager; overload;
1151  
1152      {Information}
1153      function GetStatus: IStatus;
1084    function GetLibraryName: string;
1154      function HasRollbackRetaining: boolean;
1155      function IsEmbeddedServer: boolean;
1156      function GetImplementationVersion: AnsiString;
# Line 1089 | Line 1158 | type
1158      {Firebird 3 API}
1159      function HasMasterIntf: boolean;
1160      function GetIMaster: TObject;
1161 +    function GetFBLibrary: IFirebirdLibrary;
1162   end;
1163  
1164   type
# Line 1141 | Line 1211 | function FirebirdAPI: IFirebirdAPI;
1211   function TryIBLoad: Boolean;
1212   procedure CheckIBLoaded;
1213  
1214 + {If you want to explicitly load the Firebird library from a
1215 + non-default location then use this function and its GetFirebirdAPI function
1216 + to get the API.}
1217 +
1218 + function LoadFBLibrary(aLibPathName: string): IFirebirdLibrary;
1219 +
1220   implementation
1221  
1222   uses FBClientAPI
1223    {$IFDEF USELEGACYFIREBIRDAPI}, FB25ClientAPI {$ENDIF}
1224    {$IFDEF USEFIREBIRD3API}, FB30ClientAPI {$ENDIF};
1225  
1226 < var FFirebirdAPI: IFirebirdAPI;
1226 > var FDefaultFBLibrary: IFirebirdLibrary;
1227 >
1228 > type
1229 >
1230 >  { TFBLibrary }
1231 >
1232 >  TFBLibraryImpl = class(TFBLibrary)
1233 >  protected
1234 >    function GetFirebird3API: IFirebirdAPI; override;
1235 >    function GetLegacyFirebirdAPI: IFirebirdAPI; override;
1236 >  end;
1237 >
1238 > function TFBLibraryImpl.GetFirebird3API: IFirebirdAPI;
1239 > begin
1240 > {$IFDEF USEFIREBIRD3API}
1241 > Result := TFB30ClientAPI.Create(self);
1242 > {$ELSE}
1243 > Result := nil;
1244 > {$ENDIF}
1245 > end;
1246 >
1247 > function TFBLibraryImpl.GetLegacyFirebirdAPI: IFirebirdAPI;
1248 > begin
1249 >  {$IFDEF USELEGACYFIREBIRDAPI}
1250 >  Result := TFB25ClientAPI.Create(self);
1251 >  {$ELSE}
1252 >  Result := nil;
1253 >  {$ENDIF}
1254 > end;
1255  
1256   function FirebirdAPI: IFirebirdAPI;
1257   begin
1258 <  if FFirebirdAPI = nil then
1258 >  if FDefaultFBLibrary = nil then
1259      CheckIBLoaded;
1260 <  Result := FFirebirdAPI;
1260 >  Result := FDefaultFBLibrary.GetFirebirdAPI;
1261   end;
1262  
1263   function TryIBLoad: Boolean;
1264 + var fblib: IFirebirdLibrary;
1265   begin
1266 < Result := FFirebirdAPI <> nil;
1266 > Result := FDefaultFBLibrary <> nil;
1267   try
1163  {$IFDEF USEFIREBIRD3API}
1268    if not Result then
1269    begin
1270 <    FFirebirdAPI := TFB30ClientAPI.Create;
1271 <    Result := FFirebirdAPI.HasMasterIntf;
1272 <  end;
1273 <  {$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;
1270 >    fblib := TFBLibraryImpl.Create;
1271 >    if (fblib <> nil) and (fblib.GetFirebirdAPI <> nil) then
1272 >      FDefaultFBLibrary := fblib;
1273 >    Result := FDefaultFBLibrary <> nil;
1274    end;
1275   except
1276     SysUtils.showexception(ExceptObject,ExceptAddr);
# Line 1192 | Line 1284 | begin
1284      IBError(ibxeInterBaseMissing, [nil]);
1285   end;
1286  
1287 + function LoadFBLibrary(aLibPathName: string): IFirebirdLibrary;
1288 + var fblib: IFirebirdLibrary;
1289 + begin
1290 +  if trim(aLibPathName) = '' then
1291 +  begin
1292 +    CheckIBLoaded;
1293 +    Result := FDefaultFBLibrary;
1294 +  end
1295 +  else
1296 +  begin
1297 +    fblib := TFBLibraryImpl.GetFBLibrary(aLibPathName);
1298 +    if (fblib = nil) or (fblib.GetFirebirdAPI = nil) then
1299 +      IBError(ibxeInterBaseMissing, [nil]);
1300 +    Result := fblib;
1301 +  end;
1302 + end;
1303 +
1304   { EIBError }
1305  
1306   constructor EIBError.Create(ASQLCode: Long; Msg: AnsiString);
# Line 1222 | Line 1331 | begin
1331   end;
1332  
1333   initialization
1334 <  FFirebirdAPI := nil;
1334 >  FDefaultFBLibrary := nil;
1335  
1336 + finalization
1337 +  FDefaultFBLibrary := nil;
1338  
1339   end.
1340  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines