122 |
|
interface |
123 |
|
|
124 |
|
uses |
125 |
< |
Classes, SysUtils, DB, FBMessages, IBExternals; |
125 |
> |
Classes, |
126 |
> |
{$IFDEF WINDOWS}Windows, {$ENDIF} |
127 |
> |
{$IFDEF FPC} Dynlibs, {$ENDIF} |
128 |
> |
SysUtils, DB, FBMessages, IBExternals; |
129 |
|
|
130 |
|
const |
131 |
|
{Interface version information} |
132 |
|
FBIntf_Major = 1; |
133 |
< |
FBIntf_Minor = 0; |
134 |
< |
FBIntf_Release = 2; |
135 |
< |
FBIntf_Version = '1.0.2'; |
133 |
> |
FBIntf_Minor = 1; |
134 |
> |
FBIntf_Release = 3; |
135 |
> |
FBIntf_Version = '1.1.3'; |
136 |
|
|
137 |
|
{These include files are converted from the 'C' originals in the Firebird API |
138 |
|
and define the various constants used by the API} |
176 |
|
PISC_QUAD = ^TISC_QUAD; |
177 |
|
|
178 |
|
{$IFNDEF FPC} |
179 |
+ |
{Delphi missing definitions} |
180 |
+ |
type |
181 |
+ |
TLibHandle = THandle; |
182 |
+ |
|
183 |
+ |
const |
184 |
+ |
NilHandle = 0; |
185 |
+ |
DirectorySeparator = '\'; |
186 |
+ |
|
187 |
|
{Delphi only seems to define CP_UTF8 and CP_UTF16} |
188 |
|
const |
189 |
|
CP_ACP = 0; // default to ANSI code page |
211 |
|
TFBStatusCode = cardinal; |
212 |
|
TByteArray = array of byte; |
213 |
|
|
214 |
+ |
IFirebirdAPI = interface; |
215 |
|
IAttachment = interface; |
216 |
|
ITransaction = interface; |
217 |
|
|
364 |
|
['{660822a5-3114-4c16-b6cb-c1a7b2aba70d}'] |
365 |
|
end; |
366 |
|
|
367 |
< |
IBPB = interface(IParameterBlock<IBPBItem>) |
367 |
> |
IBPB = interface (IParameterBlock<IBPBItem>) |
368 |
|
['{e0cb9eb5-17f7-4416-b7d1-3cddd1dfca76}'] |
369 |
|
end; |
370 |
|
|
644 |
|
psRealTime, psUserTime, psBuffers, |
645 |
|
psReads, psWrites, psFetches,psDeltaMemory); |
646 |
|
|
647 |
< |
TPerfCounters = array[TPerfStats] of comp; |
647 |
> |
TPerfCounters = array[TPerfStats] of Int64; |
648 |
|
|
649 |
|
{The IStatement interface provides access to an SQL Statement once it has been |
650 |
|
initially prepared. The interface is returned from the IAttachment interface. |
658 |
|
function GetRowsAffected(var SelectCount, InsertCount, UpdateCount, DeleteCount: integer): boolean; |
659 |
|
function GetSQLStatementType: TIBSQLStatementTypes; |
660 |
|
function GetSQLText: AnsiString; |
661 |
+ |
function GetProcessedSQLText: AnsiString; |
662 |
|
function GetSQLDialect: integer; |
663 |
|
function IsPrepared: boolean; |
664 |
|
procedure Prepare(aTransaction: ITransaction=nil); |
786 |
|
function getAsInteger: integer; |
787 |
|
procedure DecodeIDCluster(var ConnectionType: integer; var DBFileName, DBSiteName: AnsiString); |
788 |
|
function getAsBytes: TByteArray; |
789 |
+ |
function getAsDateTime: TDateTime; |
790 |
|
procedure DecodeVersionString(var Version: byte; var VersionString: AnsiString); |
791 |
|
function getOperationCounts: TDBOperationCounts; |
792 |
|
procedure DecodeUserNames(UserNames: TStrings); |
813 |
|
property Items[index: integer]: IDBInfoItem read getItem; default; |
814 |
|
end; |
815 |
|
|
816 |
+ |
{The Database Information Request Block is used to pass requests for |
817 |
+ |
database information where at least one item requested has a parameter. |
818 |
+ |
At present, this is only fb_info_page_contents which has a single |
819 |
+ |
integer parameter.} |
820 |
+ |
|
821 |
+ |
IDIRBItem = interface(IParameterBlockItem) |
822 |
+ |
['{d34a7511-8435-4a24-81a7-5103d218d234}'] |
823 |
+ |
end; |
824 |
+ |
|
825 |
+ |
IDIRB = interface(IParameterBlock<IDIRBItem>) |
826 |
+ |
['{1010e5ac-0a8f-403b-a302-91625e9d9579}'] |
827 |
+ |
end; |
828 |
+ |
|
829 |
+ |
|
830 |
|
{The Database Parameter Block (DPB). |
831 |
|
|
832 |
|
The DPB provides the parameters used when connecting to a database. It is allocated |
875 |
|
|
876 |
|
IAttachment = interface |
877 |
|
['{466e9b67-9def-4807-b3e7-e08a35e7185c}'] |
878 |
+ |
function getFirebirdAPI: IFirebirdAPI; |
879 |
|
function getDPB: IDPB; |
880 |
|
function AllocateBPB: IBPB; |
881 |
+ |
function AllocateDIRB: IDIRB; |
882 |
|
procedure Connect; |
883 |
|
procedure Disconnect(Force: boolean=false); |
884 |
|
function IsConnected: boolean; |
941 |
|
function GetArrayMetaData(Transaction: ITransaction; tableName, columnName: AnsiString): IArrayMetaData; |
942 |
|
function GetDBInformation(Requests: array of byte): IDBInformation; overload; |
943 |
|
function GetDBInformation(Request: byte): IDBInformation; overload; |
944 |
+ |
function GetDBInformation(Requests: IDIRB): IDBInformation; overload; |
945 |
+ |
function GetConnectString: AnsiString; |
946 |
+ |
function GetRemoteProtocol: AnsiString; |
947 |
+ |
function GetAuthenticationMethod: AnsiString; |
948 |
+ |
function GetSecurityDatabase: AnsiString; |
949 |
+ |
function GetODSMajorVersion: integer; |
950 |
+ |
function GetODSMinorVersion: integer; |
951 |
|
function HasActivity: boolean; |
952 |
+ |
|
953 |
+ |
{Character Sets} |
954 |
+ |
function HasDefaultCharSet: boolean; |
955 |
+ |
function GetDefaultCharSetID: integer; |
956 |
+ |
function GetCharsetName(CharSetID: integer): AnsiString; |
957 |
+ |
function CharSetID2CodePage(CharSetID: integer; var CodePage: TSystemCodePage): boolean; |
958 |
+ |
function CodePage2CharSetID(CodePage: TSystemCodePage; var CharSetID: integer): boolean; |
959 |
+ |
function CharSetName2CharSetID(CharSetName: AnsiString; var CharSetID: integer): boolean; |
960 |
+ |
function CharSetWidth(CharSetID: integer; var Width: integer): boolean; |
961 |
+ |
procedure RegisterCharSet(CharSetName: AnsiString; CodePage: TSystemCodePage; |
962 |
+ |
AllowReverseLookup:boolean; out CharSetID: integer); |
963 |
|
end; |
964 |
|
|
965 |
< |
TProtocol = (TCP, SPX, NamedPipe, Local); |
965 |
> |
TProtocolAll = (TCP, SPX, NamedPipe, Local, inet, inet4, inet6, wnet, xnet, unknownProtocol); |
966 |
> |
TProtocol = TCP..xnet; |
967 |
|
|
968 |
|
{Service Parameter Block (SPB). |
969 |
|
|
1068 |
|
property Count: integer read getCount; |
1069 |
|
end; |
1070 |
|
|
1071 |
+ |
IFirebirdLibrary = interface; |
1072 |
+ |
|
1073 |
|
{The IServiceManager interface provides access to a service manager. It can |
1074 |
|
used to Detach and re-attach to Service Manager, to start services and to |
1075 |
|
query the service manager. |
1081 |
|
|
1082 |
|
IServiceManager = interface |
1083 |
|
['{905b587d-1e1f-4e40-a3f8-a3519f852e48}'] |
1084 |
+ |
function getFirebirdAPI: IFirebirdAPI; |
1085 |
|
function getSPB: ISPB; |
1086 |
|
function getServerName: AnsiString; |
1087 |
+ |
function getProtocol: TProtocol; |
1088 |
+ |
function getPortNo: AnsiString; |
1089 |
|
procedure Attach; |
1090 |
|
procedure Detach(Force: boolean=false); |
1091 |
|
function IsAttached: boolean; |
1092 |
|
function AllocateSRB: ISRB; |
1093 |
|
function AllocateSQPB: ISQPB; |
1094 |
< |
procedure Start(Request: ISRB); |
1095 |
< |
function Query(SQPB: ISQPB; Request: ISRB) :IServiceQueryResults; overload; |
1096 |
< |
function Query(Request: ISRB) :IServiceQueryResults; overload; |
1094 |
> |
function Start(Request: ISRB; RaiseExceptionOnError: boolean=true): boolean; |
1095 |
> |
function Query(SQPB: ISQPB; Request: ISRB; RaiseExceptionOnError: boolean=true) :IServiceQueryResults; overload; |
1096 |
> |
function Query(Request: ISRB; RaiseExceptionOnError: boolean=true) :IServiceQueryResults; overload; |
1097 |
> |
end; |
1098 |
> |
|
1099 |
> |
{Tbe Firebird Library API used to get information about the Firebird library} |
1100 |
> |
|
1101 |
> |
|
1102 |
> |
IFirebirdLibrary = interface |
1103 |
> |
['{3c04e0a1-12e0-428a-b2e1-bc6fcd97b79b}'] |
1104 |
> |
function GetHandle: TLibHandle; |
1105 |
> |
function GetLibraryName: string; |
1106 |
> |
function GetLibraryFilePath: string; |
1107 |
> |
function GetFirebirdAPI: IFirebirdAPI; |
1108 |
|
end; |
1109 |
|
|
1110 |
|
{The Firebird API. |
1133 |
|
{Service Manager} |
1134 |
|
function HasServiceAPI: boolean; |
1135 |
|
function AllocateSPB: ISPB; |
1136 |
< |
function GetServiceManager(ServerName: AnsiString; Protocol: TProtocol; SPB: ISPB): IServiceManager; |
1136 |
> |
function GetServiceManager(ServerName: AnsiString; Protocol: TProtocol; SPB: ISPB): IServiceManager; overload; |
1137 |
> |
function GetServiceManager(ServerName: AnsiString; Port: AnsiString; Protocol: TProtocol; SPB: ISPB): IServiceManager; overload; |
1138 |
|
|
1139 |
|
{Information} |
1140 |
|
function GetStatus: IStatus; |
1075 |
– |
function GetLibraryName: string; |
1141 |
|
function HasRollbackRetaining: boolean; |
1142 |
|
function IsEmbeddedServer: boolean; |
1143 |
|
function GetImplementationVersion: AnsiString; |
1145 |
|
{Firebird 3 API} |
1146 |
|
function HasMasterIntf: boolean; |
1147 |
|
function GetIMaster: TObject; |
1148 |
< |
|
1084 |
< |
{utility} |
1085 |
< |
function GetCharsetName(CharSetID: integer): AnsiString; |
1086 |
< |
function CharSetID2CodePage(CharSetID: integer; var CodePage: TSystemCodePage): boolean; |
1087 |
< |
function CodePage2CharSetID(CodePage: TSystemCodePage; var CharSetID: integer): boolean; |
1088 |
< |
function CharSetName2CharSetID(CharSetName: AnsiString; var CharSetID: integer): boolean; |
1089 |
< |
function CharSetWidth(CharSetID: integer; var Width: integer): boolean; |
1148 |
> |
function GetFBLibrary: IFirebirdLibrary; |
1149 |
|
end; |
1150 |
|
|
1151 |
|
type |
1198 |
|
function TryIBLoad: Boolean; |
1199 |
|
procedure CheckIBLoaded; |
1200 |
|
|
1201 |
+ |
{If you want to explicitly load the Firebird library from a |
1202 |
+ |
non-default location then use this function and its GetFirebirdAPI function |
1203 |
+ |
to get the API.} |
1204 |
+ |
|
1205 |
+ |
function LoadFBLibrary(aLibPathName: string): IFirebirdLibrary; |
1206 |
+ |
|
1207 |
|
implementation |
1208 |
|
|
1209 |
|
uses FBClientAPI |
1210 |
|
{$IFDEF USELEGACYFIREBIRDAPI}, FB25ClientAPI {$ENDIF} |
1211 |
|
{$IFDEF USEFIREBIRD3API}, FB30ClientAPI {$ENDIF}; |
1212 |
|
|
1213 |
< |
var FFirebirdAPI: IFirebirdAPI; |
1213 |
> |
var FDefaultFBLibrary: IFirebirdLibrary; |
1214 |
> |
|
1215 |
> |
type |
1216 |
> |
|
1217 |
> |
{ TFBLibrary } |
1218 |
> |
|
1219 |
> |
TFBLibraryImpl = class(TFBLibrary) |
1220 |
> |
protected |
1221 |
> |
function GetFirebird3API: IFirebirdAPI; override; |
1222 |
> |
function GetLegacyFirebirdAPI: IFirebirdAPI; override; |
1223 |
> |
end; |
1224 |
> |
|
1225 |
> |
function TFBLibraryImpl.GetFirebird3API: IFirebirdAPI; |
1226 |
> |
begin |
1227 |
> |
{$IFDEF USEFIREBIRD3API} |
1228 |
> |
Result := TFB30ClientAPI.Create(self); |
1229 |
> |
{$ELSE} |
1230 |
> |
Result := nil; |
1231 |
> |
{$ENDIF} |
1232 |
> |
end; |
1233 |
> |
|
1234 |
> |
function TFBLibraryImpl.GetLegacyFirebirdAPI: IFirebirdAPI; |
1235 |
> |
begin |
1236 |
> |
{$IFDEF USELEGACYFIREBIRDAPI} |
1237 |
> |
Result := TFB25ClientAPI.Create(self); |
1238 |
> |
{$ELSE} |
1239 |
> |
Result := nil; |
1240 |
> |
{$ENDIF} |
1241 |
> |
end; |
1242 |
|
|
1243 |
|
function FirebirdAPI: IFirebirdAPI; |
1244 |
|
begin |
1245 |
< |
if FFirebirdAPI = nil then |
1245 |
> |
if FDefaultFBLibrary = nil then |
1246 |
|
CheckIBLoaded; |
1247 |
< |
Result := FFirebirdAPI; |
1247 |
> |
Result := FDefaultFBLibrary.GetFirebirdAPI; |
1248 |
|
end; |
1249 |
|
|
1250 |
|
function TryIBLoad: Boolean; |
1251 |
+ |
var fblib: IFirebirdLibrary; |
1252 |
|
begin |
1253 |
< |
Result := FFirebirdAPI <> nil; |
1253 |
> |
Result := FDefaultFBLibrary <> nil; |
1254 |
|
try |
1161 |
– |
{$IFDEF USEFIREBIRD3API} |
1255 |
|
if not Result then |
1256 |
|
begin |
1257 |
< |
FFirebirdAPI := TFB30ClientAPI.Create; |
1258 |
< |
Result := FFirebirdAPI.HasMasterIntf; |
1259 |
< |
end; |
1260 |
< |
{$ENDIF} |
1168 |
< |
{$IFDEF USELEGACYFIREBIRDAPI} |
1169 |
< |
if not Result then |
1170 |
< |
begin |
1171 |
< |
FFirebirdAPI := nil; |
1172 |
< |
FFirebirdAPI := TFB25ClientAPI.Create; |
1173 |
< |
Result := true; |
1174 |
< |
end; |
1175 |
< |
{$ENDIF} |
1176 |
< |
if Result and not (FFirebirdAPI as TFBClientAPI).IsLibraryLoaded then |
1177 |
< |
begin |
1178 |
< |
Result := false; |
1179 |
< |
FFirebirdAPI := nil; |
1257 |
> |
fblib := TFBLibraryImpl.Create; |
1258 |
> |
if (fblib <> nil) and (fblib.GetFirebirdAPI <> nil) then |
1259 |
> |
FDefaultFBLibrary := fblib; |
1260 |
> |
Result := FDefaultFBLibrary <> nil; |
1261 |
|
end; |
1262 |
|
except |
1263 |
|
SysUtils.showexception(ExceptObject,ExceptAddr); |
1271 |
|
IBError(ibxeInterBaseMissing, [nil]); |
1272 |
|
end; |
1273 |
|
|
1274 |
+ |
function LoadFBLibrary(aLibPathName: string): IFirebirdLibrary; |
1275 |
+ |
var fblib: IFirebirdLibrary; |
1276 |
+ |
begin |
1277 |
+ |
if trim(aLibPathName) = '' then |
1278 |
+ |
begin |
1279 |
+ |
CheckIBLoaded; |
1280 |
+ |
Result := FDefaultFBLibrary; |
1281 |
+ |
end |
1282 |
+ |
else |
1283 |
+ |
begin |
1284 |
+ |
fblib := TFBLibraryImpl.GetFBLibrary(aLibPathName); |
1285 |
+ |
if (fblib = nil) or (fblib.GetFirebirdAPI = nil) then |
1286 |
+ |
IBError(ibxeInterBaseMissing, [nil]); |
1287 |
+ |
Result := fblib; |
1288 |
+ |
end; |
1289 |
+ |
end; |
1290 |
+ |
|
1291 |
|
{ EIBError } |
1292 |
|
|
1293 |
|
constructor EIBError.Create(ASQLCode: Long; Msg: AnsiString); |
1318 |
|
end; |
1319 |
|
|
1320 |
|
initialization |
1321 |
< |
FFirebirdAPI := nil; |
1321 |
> |
FDefaultFBLibrary := nil; |
1322 |
|
|
1323 |
+ |
finalization |
1324 |
+ |
FDefaultFBLibrary := nil; |
1325 |
|
|
1326 |
|
end. |
1327 |
|
|