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 241 by tony, Thu Oct 25 13:57:12 2018 UTC vs.
Revision 310 by tony, Tue Jul 21 08:20:03 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 = 1;
138 <  FBIntf_Release = 3;
139 <  FBIntf_Version = '1.1.3';
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 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 411 | Line 440 | type
440      function getScale: integer;
441      function getCharSetID: cardinal;
442      function getCodePage: TSystemCodePage;
443 +    function GetCharSetWidth: integer;
444      function getIsNullable: boolean;
445      function GetSize: cardinal;
446      function GetArrayMetaData: IArrayMetaData; {Valid only for Array SQL Type}
447      function GetBlobMetaData: IBlobMetaData; {Valid only for Blob SQL Type}
448 +    function GetDateTimeStrLength(DateTimeFormat: TIBDateTimeFormats): integer;
449 +    function GetStatement: IStatement;
450 +    function GetTransaction: ITransaction;
451      property Name: AnsiString read GetName;
452      property Size: cardinal read GetSize;
453      property SQLType: cardinal read GetSQLType;
# Line 456 | Line 489 | type
489  
490    ISQLData = interface(IColumnMetaData)
491      ['{3f493e31-7e3f-4606-a07c-b210b9e3619d}']
492 +    function GetStrDataLength: short;
493      function GetAsBoolean: boolean;
494      function GetAsCurrency: Currency;
495      function GetAsInt64: Int64;
# Line 502 | Line 536 | type
536    IResults = interface
537      ['{e836b2bb-93d1-4bbf-a8eb-7ce535de3bb5}']
538     function getCount: integer;
539 +   function GetStatement: IStatement;
540     function GetTransaction: ITransaction;
541     function ByName(Idx: AnsiString): ISQLData;
542     function getSQLData(index: integer): ISQLData;
# Line 622 | Line 657 | type
657      function getSQLParam(index: integer): ISQLParam;
658      function ByName(Idx: AnsiString): ISQLParam ;
659      function GetModified: Boolean;
660 +    function GetHasCaseSensitiveParams: Boolean;
661      property Modified: Boolean read GetModified;
662      property Params[index: integer]: ISQLParam read getSQLParam; default;
663      property Count: integer read getCount;
# Line 646 | Line 682 | type
682      function GetRowsAffected(var SelectCount, InsertCount, UpdateCount, DeleteCount: integer): boolean;
683      function GetSQLStatementType: TIBSQLStatementTypes;
684      function GetSQLText: AnsiString;
685 +    function GetProcessedSQLText: AnsiString;
686      function GetSQLDialect: integer;
687      function IsPrepared: boolean;
688      procedure Prepare(aTransaction: ITransaction=nil);
# Line 862 | Line 899 | type
899  
900    IAttachment = interface
901      ['{466e9b67-9def-4807-b3e7-e08a35e7185c}']
902 +    function getFirebirdAPI: IFirebirdAPI;
903      function getDPB: IDPB;
904      function AllocateBPB: IBPB;
905      function AllocateDIRB: IDIRB;
# Line 897 | Line 935 | type
935      function Prepare(transaction: ITransaction; sql: AnsiString; aSQLDialect: integer): IStatement; overload;
936      function Prepare(transaction: ITransaction; sql: AnsiString): IStatement; overload;
937      function PrepareWithNamedParameters(transaction: ITransaction; sql: AnsiString;
938 <                       aSQLDialect: integer; GenerateParamNames: boolean=false): IStatement; overload;
938 >                       aSQLDialect: integer; GenerateParamNames: boolean=false;
939 >                       CaseSensitiveParams: boolean = false): IStatement; overload;
940      function PrepareWithNamedParameters(transaction: ITransaction; sql: AnsiString;
941 <                       GenerateParamNames: boolean=false): IStatement; overload;
941 >                       GenerateParamNames: boolean=false;
942 >                       CaseSensitiveParams: boolean = false): IStatement; overload;
943  
944      {Events}
945      function GetEventHandler(Events: TStrings): IEvents; overload;
# Line 910 | Line 950 | type
950      function CreateBlob(transaction: ITransaction; RelationName, ColumnName: AnsiString; BPB: IBPB=nil): IBlob; overload;
951      function CreateBlob(transaction: ITransaction; BlobMetaData: IBlobMetaData; BPB: IBPB=nil): IBlob; overload;
952      function CreateBlob(transaction: ITransaction; SubType: integer; CharSetID: cardinal=0; BPB: IBPB=nil): IBlob; overload;
953 <    function OpenBlob(transaction: ITransaction; RelationName, ColumnName: AnsiString; BlobID: TISC_QUAD; BPB: IBPB=nil): IBlob;
953 >    function OpenBlob(transaction: ITransaction; RelationName, ColumnName: AnsiString; BlobID: TISC_QUAD; BPB: IBPB=nil): IBlob; overload;
954 >    function OpenBlob(transaction: ITransaction; BlobMetaData: IBlobMetaData; BlobID: TISC_QUAD; BPB: IBPB=nil): IBlob;  overload;
955  
956      {Array - may use to open existing arrays. However, ISQLData.AsArray is preferred}
957  
958 <    function OpenArray(transaction: ITransaction; RelationName, ColumnName: AnsiString; ArrayID: TISC_QUAD): IArray;
958 >    function OpenArray(transaction: ITransaction; RelationName, ColumnName: AnsiString; ArrayID: TISC_QUAD): IArray; overload;
959 >    function OpenArray(transaction: ITransaction; ArrayMetaData: IArrayMetaData; ArrayID: TISC_QUAD): IArray; overload;
960      function CreateArray(transaction: ITransaction; RelationName, ColumnName: AnsiString): IArray; overload;
961      function CreateArray(transaction: ITransaction; ArrayMetaData: IArrayMetaData): IArray; overload;
962      function CreateArrayMetaData(SQLType: cardinal; tableName: AnsiString; columnName: AnsiString;
# Line 934 | Line 976 | type
976      function GetSecurityDatabase: AnsiString;
977      function GetODSMajorVersion: integer;
978      function GetODSMinorVersion: integer;
979 +    procedure getFBVersion(version: TStrings);
980      function HasActivity: boolean;
981  
982      {Character Sets}
# Line 1054 | Line 1097 | type
1097      property Count: integer read getCount;
1098    end;
1099  
1100 +  IFirebirdLibrary = interface;
1101 +
1102    {The IServiceManager interface provides access to a service manager. It can
1103     used to Detach and re-attach to Service Manager, to start services and to
1104     query the service manager.
# Line 1065 | Line 1110 | type
1110  
1111    IServiceManager = interface
1112      ['{905b587d-1e1f-4e40-a3f8-a3519f852e48}']
1113 +    function getFirebirdAPI: IFirebirdAPI;
1114      function getSPB: ISPB;
1115      function getServerName: AnsiString;
1116      function getProtocol: TProtocol;
# Line 1079 | Line 1125 | type
1125      function Query(Request: ISRB; RaiseExceptionOnError: boolean=true) :IServiceQueryResults; overload;
1126    end;
1127  
1128 +  {Tbe Firebird Library API used to get information about the Firebird library}
1129 +
1130 +
1131 +  IFirebirdLibrary = interface
1132 +    ['{3c04e0a1-12e0-428a-b2e1-bc6fcd97b79b}']
1133 +    function GetHandle: TLibHandle;
1134 +    function GetLibraryName: string;
1135 +    function GetLibraryFilePath: string;
1136 +    function GetFirebirdAPI: IFirebirdAPI;
1137 +  end;
1138 +
1139    {The Firebird API.
1140  
1141     This is the base interface and is used to create/open a database connection, to
# Line 1110 | Line 1167 | type
1167  
1168      {Information}
1169      function GetStatus: IStatus;
1113    function GetLibraryName: string;
1170      function HasRollbackRetaining: boolean;
1171      function IsEmbeddedServer: boolean;
1172      function GetImplementationVersion: AnsiString;
1173 +    function GetClientMajor: integer;
1174 +    function GetClientMinor: integer;
1175  
1176      {Firebird 3 API}
1177      function HasMasterIntf: boolean;
1178      function GetIMaster: TObject;
1179 +    function GetFBLibrary: IFirebirdLibrary;
1180   end;
1181  
1182   type
# Line 1152 | Line 1211 | type
1211     {IB Client Exceptions}
1212     EIBClientError = class(EIBError);
1213  
1155 {IBError is used internally and by IBX to throw an EIBClientError}
1156
1157 procedure IBError(ErrMess: TIBClientError; const Args: array of const);
1158
1214   {The Firebird API function is used to access the IFirebirdAPI interface.
1215  
1216   It will load the Firebird Client Library if this is not already loaded and
# Line 1170 | Line 1225 | function FirebirdAPI: IFirebirdAPI;
1225   function TryIBLoad: Boolean;
1226   procedure CheckIBLoaded;
1227  
1228 + {If you want to explicitly load the Firebird library from a
1229 + non-default location then use this function and its GetFirebirdAPI function
1230 + to get the API.}
1231 +
1232 + function LoadFBLibrary(aLibPathName: string): IFirebirdLibrary;
1233 +
1234   implementation
1235  
1236   uses FBClientAPI
1237    {$IFDEF USELEGACYFIREBIRDAPI}, FB25ClientAPI {$ENDIF}
1238    {$IFDEF USEFIREBIRD3API}, FB30ClientAPI {$ENDIF};
1239  
1240 < var FFirebirdAPI: IFirebirdAPI;
1240 > var FDefaultFBLibrary: IFirebirdLibrary;
1241 >
1242 > type
1243 >
1244 >  { TFBLibrary }
1245 >
1246 >  TFBLibraryImpl = class(TFBLibrary)
1247 >  protected
1248 >    function GetFirebird3API: IFirebirdAPI; override;
1249 >    function GetLegacyFirebirdAPI: IFirebirdAPI; override;
1250 >  end;
1251 >
1252 > function TFBLibraryImpl.GetFirebird3API: IFirebirdAPI;
1253 > begin
1254 > {$IFDEF USEFIREBIRD3API}
1255 > Result := TFB30ClientAPI.Create(self);
1256 > {$ELSE}
1257 > Result := nil;
1258 > {$ENDIF}
1259 > end;
1260 >
1261 > function TFBLibraryImpl.GetLegacyFirebirdAPI: IFirebirdAPI;
1262 > begin
1263 >  {$IFDEF USELEGACYFIREBIRDAPI}
1264 >  Result := TFB25ClientAPI.Create(self);
1265 >  {$ELSE}
1266 >  Result := nil;
1267 >  {$ENDIF}
1268 > end;
1269  
1270   function FirebirdAPI: IFirebirdAPI;
1271   begin
1272 <  if FFirebirdAPI = nil then
1272 >  if FDefaultFBLibrary = nil then
1273      CheckIBLoaded;
1274 <  Result := FFirebirdAPI;
1274 >  Result := FDefaultFBLibrary.GetFirebirdAPI;
1275   end;
1276  
1277   function TryIBLoad: Boolean;
1278 + var fblib: IFirebirdLibrary;
1279   begin
1280 < Result := FFirebirdAPI <> nil;
1280 > Result := FDefaultFBLibrary <> nil;
1281   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}
1282    if not Result then
1283    begin
1284 <    FFirebirdAPI := nil;
1285 <    FFirebirdAPI := TFB25ClientAPI.Create;
1286 <    Result := true;
1287 <  end;
1206 <  {$ENDIF}
1207 <  if Result and not (FFirebirdAPI as TFBClientAPI).IsLibraryLoaded then
1208 <  begin
1209 <    Result := false;
1210 <    FFirebirdAPI := nil;
1284 >    fblib := TFBLibraryImpl.Create;
1285 >    if (fblib <> nil) and (fblib.GetFirebirdAPI <> nil) then
1286 >      FDefaultFBLibrary := fblib;
1287 >    Result := FDefaultFBLibrary <> nil;
1288    end;
1289   except
1290     SysUtils.showexception(ExceptObject,ExceptAddr);
# Line 1221 | Line 1298 | begin
1298      IBError(ibxeInterBaseMissing, [nil]);
1299   end;
1300  
1301 + function LoadFBLibrary(aLibPathName: string): IFirebirdLibrary;
1302 + var fblib: IFirebirdLibrary;
1303 + begin
1304 +  if trim(aLibPathName) = '' then
1305 +  begin
1306 +    CheckIBLoaded;
1307 +    Result := FDefaultFBLibrary;
1308 +  end
1309 +  else
1310 +  begin
1311 +    fblib := TFBLibraryImpl.GetFBLibrary(aLibPathName);
1312 +    if (fblib = nil) or (fblib.GetFirebirdAPI = nil) then
1313 +      IBError(ibxeInterBaseMissing, [nil]);
1314 +    Result := fblib;
1315 +  end;
1316 + end;
1317 +
1318   { EIBError }
1319  
1320   constructor EIBError.Create(ASQLCode: Long; Msg: AnsiString);
# Line 1244 | Line 1338 | begin
1338    FIBErrorCode := AIBErrorCode;
1339   end;
1340  
1247 procedure IBError(ErrMess: TIBClientError; const Args: array of const);
1248 begin
1249  raise EIBClientError.Create(Ord(ErrMess),
1250                              Format(GetErrorMessage(ErrMess), Args));
1251 end;
1341  
1342   initialization
1343 <  FFirebirdAPI := nil;
1343 >  FDefaultFBLibrary := nil;
1344  
1345   finalization
1346 <  FFirebirdAPI := nil;
1346 >  FDefaultFBLibrary := nil;
1347  
1348   end.
1349  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines