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 309 by tony, Tue Jul 21 08:00:42 2020 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 = 6;
139 >  FBIntf_Version = '1.1.6';
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 195 | Line 210 | type
210                    SQLGetSegment, SQLPutSegment,
211                    SQLExecProcedure, SQLStartTransaction,
212                    SQLCommit, SQLRollback,
213 <                  SQLSelectForUpdate, SQLSetGenerator);
213 >                  SQLSelectForUpdate, SQLSetGenerator,
214 >                  SQLSavePoint);
215  
216    TFBStatusCode = cardinal;
217    TByteArray = array of byte;
218  
219 +  IFirebirdAPI = interface;
220    IAttachment = interface;
221    ITransaction = interface;
222 +  IStatement = interface;
223  
224    {The IParameterBlock interface provides the template for all parameter
225     block interfaces}
# Line 241 | Line 259 | type
259     This interface can be accessed from IFirebirdAPI.
260     }
261  
262 +   TIBDataBaseErrorMessage    = (ShowSQLCode,
263 +                                   ShowIBMessage,
264 +                                   ShowSQLMessage);
265 +
266 +   TIBDataBaseErrorMessages   = set of TIBDataBaseErrorMessage;
267 +
268    IStatus = interface
269      ['{34167722-af38-4831-b08a-93162d58ede3}']
270      function GetIBErrorCode: Long;
# Line 267 | Line 291 | type
291      function GetSQLTypeName: AnsiString;
292      function GetScale: integer;
293      function GetSize: cardinal;
294 +    function GetCharSetWidth: integer;
295      function GetCharSetID: cardinal;
296      function GetTableName: AnsiString;
297      function GetColumnName: AnsiString;
# Line 352 | Line 377 | type
377      ['{660822a5-3114-4c16-b6cb-c1a7b2aba70d}']
378    end;
379  
380 <  IBPB = interface(IParameterBlock<IBPBItem>)
380 >  IBPB = interface (IParameterBlock<IBPBItem>)
381      ['{e0cb9eb5-17f7-4416-b7d1-3cddd1dfca76}']
382    end;
383  
# Line 395 | Line 420 | type
420      the output of an SQL Statement.
421    }
422  
423 +  TIBDateTimeFormats = (dfTimestamp, {SQL TIMESTAMP}
424 +                        dfDateTime,   {SQL DATETIME}
425 +                        dfTime);      {SQL TIME}
426 +
427    { IColumnMetaData }
428  
429    IColumnMetaData = interface
# Line 415 | Line 444 | type
444      function GetSize: cardinal;
445      function GetArrayMetaData: IArrayMetaData; {Valid only for Array SQL Type}
446      function GetBlobMetaData: IBlobMetaData; {Valid only for Blob SQL Type}
447 +    function GetDateTimeStrLength(DateTimeFormat: TIBDateTimeFormats): integer;
448 +    function GetStatement: IStatement;
449 +    function GetTransaction: ITransaction;
450      property Name: AnsiString read GetName;
451      property Size: cardinal read GetSize;
452      property SQLType: cardinal read GetSQLType;
# Line 456 | Line 488 | type
488  
489    ISQLData = interface(IColumnMetaData)
490      ['{3f493e31-7e3f-4606-a07c-b210b9e3619d}']
491 +    function GetStrDataLength: short;
492      function GetAsBoolean: boolean;
493      function GetAsCurrency: Currency;
494      function GetAsInt64: Int64;
# Line 502 | Line 535 | type
535    IResults = interface
536      ['{e836b2bb-93d1-4bbf-a8eb-7ce535de3bb5}']
537     function getCount: integer;
538 +   function GetStatement: IStatement;
539     function GetTransaction: ITransaction;
540     function ByName(Idx: AnsiString): ISQLData;
541     function getSQLData(index: integer): ISQLData;
# Line 622 | Line 656 | type
656      function getSQLParam(index: integer): ISQLParam;
657      function ByName(Idx: AnsiString): ISQLParam ;
658      function GetModified: Boolean;
659 +    function GetHasCaseSensitiveParams: Boolean;
660      property Modified: Boolean read GetModified;
661      property Params[index: integer]: ISQLParam read getSQLParam; default;
662      property Count: integer read getCount;
# Line 632 | Line 667 | type
667                  psRealTime, psUserTime, psBuffers,
668                  psReads, psWrites, psFetches,psDeltaMemory);
669  
670 <  TPerfCounters = array[TPerfStats] of comp;
670 >  TPerfCounters = array[TPerfStats] of Int64;
671  
672    {The IStatement interface provides access to an SQL Statement once it has been
673     initially prepared. The interface is returned from the IAttachment interface.
# Line 646 | Line 681 | type
681      function GetRowsAffected(var SelectCount, InsertCount, UpdateCount, DeleteCount: integer): boolean;
682      function GetSQLStatementType: TIBSQLStatementTypes;
683      function GetSQLText: AnsiString;
684 +    function GetProcessedSQLText: AnsiString;
685      function GetSQLDialect: integer;
686      function IsPrepared: boolean;
687      procedure Prepare(aTransaction: ITransaction=nil);
# Line 773 | Line 809 | type
809      function getAsInteger: integer;
810      procedure DecodeIDCluster(var ConnectionType: integer; var DBFileName, DBSiteName: AnsiString);
811      function getAsBytes: TByteArray;
812 +    function getAsDateTime: TDateTime;
813      procedure DecodeVersionString(var Version: byte; var VersionString: AnsiString);
814      function getOperationCounts: TDBOperationCounts;
815      procedure DecodeUserNames(UserNames: TStrings);
# Line 799 | Line 836 | type
836      property Items[index: integer]: IDBInfoItem read getItem; default;
837    end;
838  
839 +  {The Database Information Request Block is used to pass requests for
840 +   database information where at least one item requested has a parameter.
841 +   At present, this is only fb_info_page_contents which has a single
842 +   integer parameter.}
843 +
844 +  IDIRBItem = interface(IParameterBlockItem)
845 +    ['{d34a7511-8435-4a24-81a7-5103d218d234}']
846 +  end;
847 +
848 +  IDIRB = interface(IParameterBlock<IDIRBItem>)
849 +    ['{1010e5ac-0a8f-403b-a302-91625e9d9579}']
850 +  end;
851 +
852 +
853    {The Database Parameter Block (DPB).
854  
855     The DPB provides the parameters used when connecting to a database. It is allocated
# Line 847 | Line 898 | type
898  
899    IAttachment = interface
900      ['{466e9b67-9def-4807-b3e7-e08a35e7185c}']
901 +    function getFirebirdAPI: IFirebirdAPI;
902      function getDPB: IDPB;
903      function AllocateBPB: IBPB;
904 +    function AllocateDIRB: IDIRB;
905      procedure Connect;
906      procedure Disconnect(Force: boolean=false);
907      function IsConnected: boolean;
# Line 881 | Line 934 | type
934      function Prepare(transaction: ITransaction; sql: AnsiString; aSQLDialect: integer): IStatement; overload;
935      function Prepare(transaction: ITransaction; sql: AnsiString): IStatement; overload;
936      function PrepareWithNamedParameters(transaction: ITransaction; sql: AnsiString;
937 <                       aSQLDialect: integer; GenerateParamNames: boolean=false): IStatement; overload;
937 >                       aSQLDialect: integer; GenerateParamNames: boolean=false;
938 >                       CaseSensitiveParams: boolean = false): IStatement; overload;
939      function PrepareWithNamedParameters(transaction: ITransaction; sql: AnsiString;
940 <                       GenerateParamNames: boolean=false): IStatement; overload;
940 >                       GenerateParamNames: boolean=false;
941 >                       CaseSensitiveParams: boolean = false): IStatement; overload;
942  
943      {Events}
944      function GetEventHandler(Events: TStrings): IEvents; overload;
# Line 894 | Line 949 | type
949      function CreateBlob(transaction: ITransaction; RelationName, ColumnName: AnsiString; BPB: IBPB=nil): IBlob; overload;
950      function CreateBlob(transaction: ITransaction; BlobMetaData: IBlobMetaData; BPB: IBPB=nil): IBlob; overload;
951      function CreateBlob(transaction: ITransaction; SubType: integer; CharSetID: cardinal=0; BPB: IBPB=nil): IBlob; overload;
952 <    function OpenBlob(transaction: ITransaction; RelationName, ColumnName: AnsiString; BlobID: TISC_QUAD; BPB: IBPB=nil): IBlob;
952 >    function OpenBlob(transaction: ITransaction; RelationName, ColumnName: AnsiString; BlobID: TISC_QUAD; BPB: IBPB=nil): IBlob; overload;
953 >    function OpenBlob(transaction: ITransaction; BlobMetaData: IBlobMetaData; BlobID: TISC_QUAD; BPB: IBPB=nil): IBlob;  overload;
954  
955      {Array - may use to open existing arrays. However, ISQLData.AsArray is preferred}
956  
957 <    function OpenArray(transaction: ITransaction; RelationName, ColumnName: AnsiString; ArrayID: TISC_QUAD): IArray;
957 >    function OpenArray(transaction: ITransaction; RelationName, ColumnName: AnsiString; ArrayID: TISC_QUAD): IArray; overload;
958 >    function OpenArray(transaction: ITransaction; ArrayMetaData: IArrayMetaData; ArrayID: TISC_QUAD): IArray; overload;
959      function CreateArray(transaction: ITransaction; RelationName, ColumnName: AnsiString): IArray; overload;
960      function CreateArray(transaction: ITransaction; ArrayMetaData: IArrayMetaData): IArray; overload;
961      function CreateArrayMetaData(SQLType: cardinal; tableName: AnsiString; columnName: AnsiString;
# Line 911 | Line 968 | type
968      function GetArrayMetaData(Transaction: ITransaction; tableName, columnName: AnsiString): IArrayMetaData;
969      function GetDBInformation(Requests: array of byte): IDBInformation; overload;
970      function GetDBInformation(Request: byte): IDBInformation; overload;
971 +    function GetDBInformation(Requests: IDIRB): IDBInformation; overload;
972 +    function GetConnectString: AnsiString;
973 +    function GetRemoteProtocol: AnsiString;
974 +    function GetAuthenticationMethod: AnsiString;
975 +    function GetSecurityDatabase: AnsiString;
976 +    function GetODSMajorVersion: integer;
977 +    function GetODSMinorVersion: integer;
978 +    procedure getFBVersion(version: TStrings);
979      function HasActivity: boolean;
980  
981      {Character Sets}
982 +    function HasDefaultCharSet: boolean;
983 +    function GetDefaultCharSetID: integer;
984      function GetCharsetName(CharSetID: integer): AnsiString;
985      function CharSetID2CodePage(CharSetID: integer; var CodePage: TSystemCodePage): boolean;
986      function CodePage2CharSetID(CodePage: TSystemCodePage; var CharSetID: integer): boolean;
# Line 923 | Line 990 | type
990        AllowReverseLookup:boolean; out CharSetID: integer);
991    end;
992  
993 <  TProtocol = (TCP, SPX, NamedPipe, Local);
993 >  TProtocolAll = (TCP, SPX, NamedPipe, Local, inet, inet4, inet6, wnet, xnet, unknownProtocol);
994 >  TProtocol = TCP..xnet;
995  
996    {Service Parameter Block (SPB).
997  
# Line 1028 | Line 1096 | type
1096      property Count: integer read getCount;
1097    end;
1098  
1099 +  IFirebirdLibrary = interface;
1100 +
1101    {The IServiceManager interface provides access to a service manager. It can
1102     used to Detach and re-attach to Service Manager, to start services and to
1103     query the service manager.
# Line 1039 | Line 1109 | type
1109  
1110    IServiceManager = interface
1111      ['{905b587d-1e1f-4e40-a3f8-a3519f852e48}']
1112 +    function getFirebirdAPI: IFirebirdAPI;
1113      function getSPB: ISPB;
1114      function getServerName: AnsiString;
1115 +    function getProtocol: TProtocol;
1116 +    function getPortNo: AnsiString;
1117      procedure Attach;
1118      procedure Detach(Force: boolean=false);
1119      function IsAttached: boolean;
1120      function AllocateSRB: ISRB;
1121      function AllocateSQPB: ISQPB;
1122 <    procedure Start(Request: ISRB);
1123 <    function Query(SQPB: ISQPB; Request: ISRB) :IServiceQueryResults; overload;
1124 <    function Query(Request: ISRB) :IServiceQueryResults; overload;
1122 >    function Start(Request: ISRB; RaiseExceptionOnError: boolean=true): boolean;
1123 >    function Query(SQPB: ISQPB; Request: ISRB; RaiseExceptionOnError: boolean=true) :IServiceQueryResults; overload;
1124 >    function Query(Request: ISRB; RaiseExceptionOnError: boolean=true) :IServiceQueryResults; overload;
1125 >  end;
1126 >
1127 >  {Tbe Firebird Library API used to get information about the Firebird library}
1128 >
1129 >
1130 >  IFirebirdLibrary = interface
1131 >    ['{3c04e0a1-12e0-428a-b2e1-bc6fcd97b79b}']
1132 >    function GetHandle: TLibHandle;
1133 >    function GetLibraryName: string;
1134 >    function GetLibraryFilePath: string;
1135 >    function GetFirebirdAPI: IFirebirdAPI;
1136    end;
1137  
1138    {The Firebird API.
# Line 1077 | Line 1161 | type
1161      {Service Manager}
1162      function HasServiceAPI: boolean;
1163      function AllocateSPB: ISPB;
1164 <    function GetServiceManager(ServerName: AnsiString; Protocol: TProtocol; SPB: ISPB): IServiceManager;
1164 >    function GetServiceManager(ServerName: AnsiString; Protocol: TProtocol; SPB: ISPB): IServiceManager; overload;
1165 >    function GetServiceManager(ServerName: AnsiString; Port: AnsiString; Protocol: TProtocol; SPB: ISPB): IServiceManager; overload;
1166  
1167      {Information}
1168      function GetStatus: IStatus;
1084    function GetLibraryName: string;
1169      function HasRollbackRetaining: boolean;
1170      function IsEmbeddedServer: boolean;
1171      function GetImplementationVersion: AnsiString;
1172 +    function GetClientMajor: integer;
1173 +    function GetClientMinor: integer;
1174  
1175      {Firebird 3 API}
1176      function HasMasterIntf: boolean;
1177      function GetIMaster: TObject;
1178 +    function GetFBLibrary: IFirebirdLibrary;
1179   end;
1180  
1181   type
# Line 1123 | Line 1210 | type
1210     {IB Client Exceptions}
1211     EIBClientError = class(EIBError);
1212  
1126 {IBError is used internally and by IBX to throw an EIBClientError}
1127
1128 procedure IBError(ErrMess: TIBClientError; const Args: array of const);
1129
1213   {The Firebird API function is used to access the IFirebirdAPI interface.
1214  
1215   It will load the Firebird Client Library if this is not already loaded and
# Line 1141 | Line 1224 | function FirebirdAPI: IFirebirdAPI;
1224   function TryIBLoad: Boolean;
1225   procedure CheckIBLoaded;
1226  
1227 + {If you want to explicitly load the Firebird library from a
1228 + non-default location then use this function and its GetFirebirdAPI function
1229 + to get the API.}
1230 +
1231 + function LoadFBLibrary(aLibPathName: string): IFirebirdLibrary;
1232 +
1233   implementation
1234  
1235   uses FBClientAPI
1236    {$IFDEF USELEGACYFIREBIRDAPI}, FB25ClientAPI {$ENDIF}
1237    {$IFDEF USEFIREBIRD3API}, FB30ClientAPI {$ENDIF};
1238  
1239 < var FFirebirdAPI: IFirebirdAPI;
1239 > var FDefaultFBLibrary: IFirebirdLibrary;
1240 >
1241 > type
1242 >
1243 >  { TFBLibrary }
1244 >
1245 >  TFBLibraryImpl = class(TFBLibrary)
1246 >  protected
1247 >    function GetFirebird3API: IFirebirdAPI; override;
1248 >    function GetLegacyFirebirdAPI: IFirebirdAPI; override;
1249 >  end;
1250 >
1251 > function TFBLibraryImpl.GetFirebird3API: IFirebirdAPI;
1252 > begin
1253 > {$IFDEF USEFIREBIRD3API}
1254 > Result := TFB30ClientAPI.Create(self);
1255 > {$ELSE}
1256 > Result := nil;
1257 > {$ENDIF}
1258 > end;
1259 >
1260 > function TFBLibraryImpl.GetLegacyFirebirdAPI: IFirebirdAPI;
1261 > begin
1262 >  {$IFDEF USELEGACYFIREBIRDAPI}
1263 >  Result := TFB25ClientAPI.Create(self);
1264 >  {$ELSE}
1265 >  Result := nil;
1266 >  {$ENDIF}
1267 > end;
1268  
1269   function FirebirdAPI: IFirebirdAPI;
1270   begin
1271 <  if FFirebirdAPI = nil then
1271 >  if FDefaultFBLibrary = nil then
1272      CheckIBLoaded;
1273 <  Result := FFirebirdAPI;
1273 >  Result := FDefaultFBLibrary.GetFirebirdAPI;
1274   end;
1275  
1276   function TryIBLoad: Boolean;
1277 + var fblib: IFirebirdLibrary;
1278   begin
1279 < Result := FFirebirdAPI <> nil;
1279 > Result := FDefaultFBLibrary <> nil;
1280   try
1163  {$IFDEF USEFIREBIRD3API}
1164  if not Result then
1165  begin
1166    FFirebirdAPI := TFB30ClientAPI.Create;
1167    Result := FFirebirdAPI.HasMasterIntf;
1168  end;
1169  {$ENDIF}
1170  {$IFDEF USELEGACYFIREBIRDAPI}
1281    if not Result then
1282    begin
1283 <    FFirebirdAPI := nil;
1284 <    FFirebirdAPI := TFB25ClientAPI.Create;
1285 <    Result := true;
1286 <  end;
1177 <  {$ENDIF}
1178 <  if Result and not (FFirebirdAPI as TFBClientAPI).IsLibraryLoaded then
1179 <  begin
1180 <    Result := false;
1181 <    FFirebirdAPI := nil;
1283 >    fblib := TFBLibraryImpl.Create;
1284 >    if (fblib <> nil) and (fblib.GetFirebirdAPI <> nil) then
1285 >      FDefaultFBLibrary := fblib;
1286 >    Result := FDefaultFBLibrary <> nil;
1287    end;
1288   except
1289     SysUtils.showexception(ExceptObject,ExceptAddr);
# Line 1192 | Line 1297 | begin
1297      IBError(ibxeInterBaseMissing, [nil]);
1298   end;
1299  
1300 + function LoadFBLibrary(aLibPathName: string): IFirebirdLibrary;
1301 + var fblib: IFirebirdLibrary;
1302 + begin
1303 +  if trim(aLibPathName) = '' then
1304 +  begin
1305 +    CheckIBLoaded;
1306 +    Result := FDefaultFBLibrary;
1307 +  end
1308 +  else
1309 +  begin
1310 +    fblib := TFBLibraryImpl.GetFBLibrary(aLibPathName);
1311 +    if (fblib = nil) or (fblib.GetFirebirdAPI = nil) then
1312 +      IBError(ibxeInterBaseMissing, [nil]);
1313 +    Result := fblib;
1314 +  end;
1315 + end;
1316 +
1317   { EIBError }
1318  
1319   constructor EIBError.Create(ASQLCode: Long; Msg: AnsiString);
# Line 1215 | Line 1337 | begin
1337    FIBErrorCode := AIBErrorCode;
1338   end;
1339  
1218 procedure IBError(ErrMess: TIBClientError; const Args: array of const);
1219 begin
1220  raise EIBClientError.Create(Ord(ErrMess),
1221                              Format(GetErrorMessage(ErrMess), Args));
1222 end;
1340  
1341   initialization
1342 <  FFirebirdAPI := nil;
1342 >  FDefaultFBLibrary := nil;
1343  
1344 + finalization
1345 +  FDefaultFBLibrary := nil;
1346  
1347   end.
1348  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines