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 |
|
|
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); |
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; |
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; |
962 |
|
AllowReverseLookup:boolean; out CharSetID: integer); |
963 |
|
end; |
964 |
|
|
965 |
< |
TProtocolAll = (TCP, SPX, NamedPipe, Local, inet, wnet, xnet, unknownProtocol); |
965 |
> |
TProtocolAll = (TCP, SPX, NamedPipe, Local, inet, inet4, inet6, wnet, xnet, unknownProtocol); |
966 |
|
TProtocol = TCP..xnet; |
967 |
|
|
968 |
|
{Service Parameter Block (SPB). |
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. |
1138 |
|
|
1139 |
|
{Information} |
1140 |
|
function GetStatus: IStatus; |
1110 |
– |
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 |
+ |
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 |
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} |
1255 |
|
if not Result then |
1256 |
|
begin |
1257 |
< |
FFirebirdAPI := nil; |
1258 |
< |
FFirebirdAPI := TFB25ClientAPI.Create; |
1259 |
< |
Result := true; |
1260 |
< |
end; |
1203 |
< |
{$ENDIF} |
1204 |
< |
if Result and not (FFirebirdAPI as TFBClientAPI).IsLibraryLoaded then |
1205 |
< |
begin |
1206 |
< |
Result := false; |
1207 |
< |
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 |
|
|