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 143 by tony, Fri Feb 23 12:11:21 2018 UTC vs.
Revision 308 by tony, Sat Jul 18 10:26:30 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 395 | Line 419 | type
419      the output of an SQL Statement.
420    }
421  
422 +  TIBDateTimeFormats = (dfTimestamp, {SQL TIMESTAMP}
423 +                        dfDateTime,   {SQL DATETIME}
424 +                        dfTime);      {SQL TIME}
425 +
426    { IColumnMetaData }
427  
428    IColumnMetaData = interface
# Line 415 | Line 443 | type
443      function GetSize: cardinal;
444      function GetArrayMetaData: IArrayMetaData; {Valid only for Array SQL Type}
445      function GetBlobMetaData: IBlobMetaData; {Valid only for Blob SQL Type}
446 +    function GetDateTimeStrLength(DateTimeFormat: TIBDateTimeFormats): integer;
447 +    function GetStatement: IStatement;
448 +    function GetTransaction: ITransaction;
449      property Name: AnsiString read GetName;
450      property Size: cardinal read GetSize;
451      property SQLType: cardinal read GetSQLType;
# Line 456 | Line 487 | type
487  
488    ISQLData = interface(IColumnMetaData)
489      ['{3f493e31-7e3f-4606-a07c-b210b9e3619d}']
490 +    function GetStrDataLength: short;
491      function GetAsBoolean: boolean;
492      function GetAsCurrency: Currency;
493      function GetAsInt64: Int64;
# Line 502 | Line 534 | type
534    IResults = interface
535      ['{e836b2bb-93d1-4bbf-a8eb-7ce535de3bb5}']
536     function getCount: integer;
537 +   function GetStatement: IStatement;
538     function GetTransaction: ITransaction;
539     function ByName(Idx: AnsiString): ISQLData;
540     function getSQLData(index: integer): ISQLData;
# Line 622 | Line 655 | type
655      function getSQLParam(index: integer): ISQLParam;
656      function ByName(Idx: AnsiString): ISQLParam ;
657      function GetModified: Boolean;
658 +    function GetHasCaseSensitiveParams: Boolean;
659      property Modified: Boolean read GetModified;
660      property Params[index: integer]: ISQLParam read getSQLParam; default;
661      property Count: integer read getCount;
# Line 632 | Line 666 | type
666                  psRealTime, psUserTime, psBuffers,
667                  psReads, psWrites, psFetches,psDeltaMemory);
668  
669 <  TPerfCounters = array[TPerfStats] of comp;
669 >  TPerfCounters = array[TPerfStats] of Int64;
670  
671    {The IStatement interface provides access to an SQL Statement once it has been
672     initially prepared. The interface is returned from the IAttachment interface.
# Line 646 | Line 680 | type
680      function GetRowsAffected(var SelectCount, InsertCount, UpdateCount, DeleteCount: integer): boolean;
681      function GetSQLStatementType: TIBSQLStatementTypes;
682      function GetSQLText: AnsiString;
683 +    function GetProcessedSQLText: AnsiString;
684      function GetSQLDialect: integer;
685      function IsPrepared: boolean;
686      procedure Prepare(aTransaction: ITransaction=nil);
# Line 862 | Line 897 | type
897  
898    IAttachment = interface
899      ['{466e9b67-9def-4807-b3e7-e08a35e7185c}']
900 +    function getFirebirdAPI: IFirebirdAPI;
901      function getDPB: IDPB;
902      function AllocateBPB: IBPB;
903      function AllocateDIRB: IDIRB;
# Line 897 | Line 933 | type
933      function Prepare(transaction: ITransaction; sql: AnsiString; aSQLDialect: integer): IStatement; overload;
934      function Prepare(transaction: ITransaction; sql: AnsiString): IStatement; overload;
935      function PrepareWithNamedParameters(transaction: ITransaction; sql: AnsiString;
936 <                       aSQLDialect: integer; GenerateParamNames: boolean=false): IStatement; overload;
936 >                       aSQLDialect: integer; GenerateParamNames: boolean=false;
937 >                       CaseSensitiveParams: boolean = false): IStatement; overload;
938      function PrepareWithNamedParameters(transaction: ITransaction; sql: AnsiString;
939 <                       GenerateParamNames: boolean=false): IStatement; overload;
939 >                       GenerateParamNames: boolean=false;
940 >                       CaseSensitiveParams: boolean = false): IStatement; overload;
941  
942      {Events}
943      function GetEventHandler(Events: TStrings): IEvents; overload;
# Line 910 | Line 948 | type
948      function CreateBlob(transaction: ITransaction; RelationName, ColumnName: AnsiString; BPB: IBPB=nil): IBlob; overload;
949      function CreateBlob(transaction: ITransaction; BlobMetaData: IBlobMetaData; BPB: IBPB=nil): IBlob; overload;
950      function CreateBlob(transaction: ITransaction; SubType: integer; CharSetID: cardinal=0; BPB: IBPB=nil): IBlob; overload;
951 <    function OpenBlob(transaction: ITransaction; RelationName, ColumnName: AnsiString; BlobID: TISC_QUAD; BPB: IBPB=nil): IBlob;
951 >    function OpenBlob(transaction: ITransaction; RelationName, ColumnName: AnsiString; BlobID: TISC_QUAD; BPB: IBPB=nil): IBlob; overload;
952 >    function OpenBlob(transaction: ITransaction; BlobMetaData: IBlobMetaData; BlobID: TISC_QUAD; BPB: IBPB=nil): IBlob;  overload;
953  
954      {Array - may use to open existing arrays. However, ISQLData.AsArray is preferred}
955  
956 <    function OpenArray(transaction: ITransaction; RelationName, ColumnName: AnsiString; ArrayID: TISC_QUAD): IArray;
956 >    function OpenArray(transaction: ITransaction; RelationName, ColumnName: AnsiString; ArrayID: TISC_QUAD): IArray; overload;
957 >    function OpenArray(transaction: ITransaction; ArrayMetaData: IArrayMetaData; ArrayID: TISC_QUAD): IArray; overload;
958      function CreateArray(transaction: ITransaction; RelationName, ColumnName: AnsiString): IArray; overload;
959      function CreateArray(transaction: ITransaction; ArrayMetaData: IArrayMetaData): IArray; overload;
960      function CreateArrayMetaData(SQLType: cardinal; tableName: AnsiString; columnName: AnsiString;
# Line 931 | Line 971 | type
971      function GetConnectString: AnsiString;
972      function GetRemoteProtocol: AnsiString;
973      function GetAuthenticationMethod: AnsiString;
974 +    function GetSecurityDatabase: AnsiString;
975      function GetODSMajorVersion: integer;
976      function GetODSMinorVersion: integer;
977 +    procedure getFBVersion(version: TStrings);
978      function HasActivity: boolean;
979  
980      {Character Sets}
# Line 947 | Line 989 | type
989        AllowReverseLookup:boolean; out CharSetID: integer);
990    end;
991  
992 <  TProtocolAll = (TCP, SPX, NamedPipe, Local, inet, wnet, xnet, unknownProtocol);
992 >  TProtocolAll = (TCP, SPX, NamedPipe, Local, inet, inet4, inet6, wnet, xnet, unknownProtocol);
993    TProtocol = TCP..xnet;
994  
995    {Service Parameter Block (SPB).
# Line 1053 | Line 1095 | type
1095      property Count: integer read getCount;
1096    end;
1097  
1098 +  IFirebirdLibrary = interface;
1099 +
1100    {The IServiceManager interface provides access to a service manager. It can
1101     used to Detach and re-attach to Service Manager, to start services and to
1102     query the service manager.
# Line 1064 | Line 1108 | type
1108  
1109    IServiceManager = interface
1110      ['{905b587d-1e1f-4e40-a3f8-a3519f852e48}']
1111 +    function getFirebirdAPI: IFirebirdAPI;
1112      function getSPB: ISPB;
1113      function getServerName: AnsiString;
1114 +    function getProtocol: TProtocol;
1115 +    function getPortNo: AnsiString;
1116      procedure Attach;
1117      procedure Detach(Force: boolean=false);
1118      function IsAttached: boolean;
1119      function AllocateSRB: ISRB;
1120      function AllocateSQPB: ISQPB;
1121 <    procedure Start(Request: ISRB);
1122 <    function Query(SQPB: ISQPB; Request: ISRB) :IServiceQueryResults; overload;
1123 <    function Query(Request: ISRB) :IServiceQueryResults; overload;
1121 >    function Start(Request: ISRB; RaiseExceptionOnError: boolean=true): boolean;
1122 >    function Query(SQPB: ISQPB; Request: ISRB; RaiseExceptionOnError: boolean=true) :IServiceQueryResults; overload;
1123 >    function Query(Request: ISRB; RaiseExceptionOnError: boolean=true) :IServiceQueryResults; overload;
1124 >  end;
1125 >
1126 >  {Tbe Firebird Library API used to get information about the Firebird library}
1127 >
1128 >
1129 >  IFirebirdLibrary = interface
1130 >    ['{3c04e0a1-12e0-428a-b2e1-bc6fcd97b79b}']
1131 >    function GetHandle: TLibHandle;
1132 >    function GetLibraryName: string;
1133 >    function GetLibraryFilePath: string;
1134 >    function GetFirebirdAPI: IFirebirdAPI;
1135    end;
1136  
1137    {The Firebird API.
# Line 1107 | Line 1165 | type
1165  
1166      {Information}
1167      function GetStatus: IStatus;
1110    function GetLibraryName: string;
1168      function HasRollbackRetaining: boolean;
1169      function IsEmbeddedServer: boolean;
1170      function GetImplementationVersion: AnsiString;
1171 +    function GetClientMajor: integer;
1172 +    function GetClientMinor: integer;
1173  
1174      {Firebird 3 API}
1175      function HasMasterIntf: boolean;
1176      function GetIMaster: TObject;
1177 +    function GetFBLibrary: IFirebirdLibrary;
1178   end;
1179  
1180   type
# Line 1149 | Line 1209 | type
1209     {IB Client Exceptions}
1210     EIBClientError = class(EIBError);
1211  
1152 {IBError is used internally and by IBX to throw an EIBClientError}
1153
1154 procedure IBError(ErrMess: TIBClientError; const Args: array of const);
1155
1212   {The Firebird API function is used to access the IFirebirdAPI interface.
1213  
1214   It will load the Firebird Client Library if this is not already loaded and
# Line 1167 | Line 1223 | function FirebirdAPI: IFirebirdAPI;
1223   function TryIBLoad: Boolean;
1224   procedure CheckIBLoaded;
1225  
1226 + {If you want to explicitly load the Firebird library from a
1227 + non-default location then use this function and its GetFirebirdAPI function
1228 + to get the API.}
1229 +
1230 + function LoadFBLibrary(aLibPathName: string): IFirebirdLibrary;
1231 +
1232   implementation
1233  
1234   uses FBClientAPI
1235    {$IFDEF USELEGACYFIREBIRDAPI}, FB25ClientAPI {$ENDIF}
1236    {$IFDEF USEFIREBIRD3API}, FB30ClientAPI {$ENDIF};
1237  
1238 < var FFirebirdAPI: IFirebirdAPI;
1238 > var FDefaultFBLibrary: IFirebirdLibrary;
1239 >
1240 > type
1241 >
1242 >  { TFBLibrary }
1243 >
1244 >  TFBLibraryImpl = class(TFBLibrary)
1245 >  protected
1246 >    function GetFirebird3API: IFirebirdAPI; override;
1247 >    function GetLegacyFirebirdAPI: IFirebirdAPI; override;
1248 >  end;
1249 >
1250 > function TFBLibraryImpl.GetFirebird3API: IFirebirdAPI;
1251 > begin
1252 > {$IFDEF USEFIREBIRD3API}
1253 > Result := TFB30ClientAPI.Create(self);
1254 > {$ELSE}
1255 > Result := nil;
1256 > {$ENDIF}
1257 > end;
1258 >
1259 > function TFBLibraryImpl.GetLegacyFirebirdAPI: IFirebirdAPI;
1260 > begin
1261 >  {$IFDEF USELEGACYFIREBIRDAPI}
1262 >  Result := TFB25ClientAPI.Create(self);
1263 >  {$ELSE}
1264 >  Result := nil;
1265 >  {$ENDIF}
1266 > end;
1267  
1268   function FirebirdAPI: IFirebirdAPI;
1269   begin
1270 <  if FFirebirdAPI = nil then
1270 >  if FDefaultFBLibrary = nil then
1271      CheckIBLoaded;
1272 <  Result := FFirebirdAPI;
1272 >  Result := FDefaultFBLibrary.GetFirebirdAPI;
1273   end;
1274  
1275   function TryIBLoad: Boolean;
1276 + var fblib: IFirebirdLibrary;
1277   begin
1278 < Result := FFirebirdAPI <> nil;
1278 > Result := FDefaultFBLibrary <> nil;
1279   try
1189  {$IFDEF USEFIREBIRD3API}
1190  if not Result then
1191  begin
1192    FFirebirdAPI := TFB30ClientAPI.Create;
1193    Result := FFirebirdAPI.HasMasterIntf;
1194  end;
1195  {$ENDIF}
1196  {$IFDEF USELEGACYFIREBIRDAPI}
1280    if not Result then
1281    begin
1282 <    FFirebirdAPI := nil;
1283 <    FFirebirdAPI := TFB25ClientAPI.Create;
1284 <    Result := true;
1285 <  end;
1203 <  {$ENDIF}
1204 <  if Result and not (FFirebirdAPI as TFBClientAPI).IsLibraryLoaded then
1205 <  begin
1206 <    Result := false;
1207 <    FFirebirdAPI := nil;
1282 >    fblib := TFBLibraryImpl.Create;
1283 >    if (fblib <> nil) and (fblib.GetFirebirdAPI <> nil) then
1284 >      FDefaultFBLibrary := fblib;
1285 >    Result := FDefaultFBLibrary <> nil;
1286    end;
1287   except
1288     SysUtils.showexception(ExceptObject,ExceptAddr);
# Line 1218 | Line 1296 | begin
1296      IBError(ibxeInterBaseMissing, [nil]);
1297   end;
1298  
1299 + function LoadFBLibrary(aLibPathName: string): IFirebirdLibrary;
1300 + var fblib: IFirebirdLibrary;
1301 + begin
1302 +  if trim(aLibPathName) = '' then
1303 +  begin
1304 +    CheckIBLoaded;
1305 +    Result := FDefaultFBLibrary;
1306 +  end
1307 +  else
1308 +  begin
1309 +    fblib := TFBLibraryImpl.GetFBLibrary(aLibPathName);
1310 +    if (fblib = nil) or (fblib.GetFirebirdAPI = nil) then
1311 +      IBError(ibxeInterBaseMissing, [nil]);
1312 +    Result := fblib;
1313 +  end;
1314 + end;
1315 +
1316   { EIBError }
1317  
1318   constructor EIBError.Create(ASQLCode: Long; Msg: AnsiString);
# Line 1241 | Line 1336 | begin
1336    FIBErrorCode := AIBErrorCode;
1337   end;
1338  
1244 procedure IBError(ErrMess: TIBClientError; const Args: array of const);
1245 begin
1246  raise EIBClientError.Create(Ord(ErrMess),
1247                              Format(GetErrorMessage(ErrMess), Args));
1248 end;
1339  
1340   initialization
1341 <  FFirebirdAPI := nil;
1341 >  FDefaultFBLibrary := nil;
1342  
1343 + finalization
1344 +  FDefaultFBLibrary := nil;
1345  
1346   end.
1347  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines