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 |
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 = 5; |
139 |
> |
FBIntf_Version = '1.1.5'; |
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} |
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 |
215 |
|
TFBStatusCode = cardinal; |
216 |
|
TByteArray = array of byte; |
217 |
|
|
218 |
+ |
IFirebirdAPI = interface; |
219 |
|
IAttachment = interface; |
220 |
|
ITransaction = interface; |
221 |
|
|
411 |
|
the output of an SQL Statement. |
412 |
|
} |
413 |
|
|
414 |
+ |
TIBDateTimeFormats = (dfTimestamp, {SQL TIMESTAMP} |
415 |
+ |
dfDateTime, {SQL DATETIME} |
416 |
+ |
dfTime); {SQL TIME} |
417 |
+ |
|
418 |
|
{ IColumnMetaData } |
419 |
|
|
420 |
|
IColumnMetaData = interface |
435 |
|
function GetSize: cardinal; |
436 |
|
function GetArrayMetaData: IArrayMetaData; {Valid only for Array SQL Type} |
437 |
|
function GetBlobMetaData: IBlobMetaData; {Valid only for Blob SQL Type} |
438 |
+ |
function GetDateTimeStrLength(DateTimeFormat: TIBDateTimeFormats): integer; |
439 |
|
property Name: AnsiString read GetName; |
440 |
|
property Size: cardinal read GetSize; |
441 |
|
property SQLType: cardinal read GetSQLType; |
643 |
|
function getSQLParam(index: integer): ISQLParam; |
644 |
|
function ByName(Idx: AnsiString): ISQLParam ; |
645 |
|
function GetModified: Boolean; |
646 |
+ |
function GetHasCaseSensitiveParams: Boolean; |
647 |
|
property Modified: Boolean read GetModified; |
648 |
|
property Params[index: integer]: ISQLParam read getSQLParam; default; |
649 |
|
property Count: integer read getCount; |
654 |
|
psRealTime, psUserTime, psBuffers, |
655 |
|
psReads, psWrites, psFetches,psDeltaMemory); |
656 |
|
|
657 |
< |
TPerfCounters = array[TPerfStats] of comp; |
657 |
> |
TPerfCounters = array[TPerfStats] of Int64; |
658 |
|
|
659 |
|
{The IStatement interface provides access to an SQL Statement once it has been |
660 |
|
initially prepared. The interface is returned from the IAttachment interface. |
668 |
|
function GetRowsAffected(var SelectCount, InsertCount, UpdateCount, DeleteCount: integer): boolean; |
669 |
|
function GetSQLStatementType: TIBSQLStatementTypes; |
670 |
|
function GetSQLText: AnsiString; |
671 |
+ |
function GetProcessedSQLText: AnsiString; |
672 |
|
function GetSQLDialect: integer; |
673 |
|
function IsPrepared: boolean; |
674 |
|
procedure Prepare(aTransaction: ITransaction=nil); |
796 |
|
function getAsInteger: integer; |
797 |
|
procedure DecodeIDCluster(var ConnectionType: integer; var DBFileName, DBSiteName: AnsiString); |
798 |
|
function getAsBytes: TByteArray; |
799 |
+ |
function getAsDateTime: TDateTime; |
800 |
|
procedure DecodeVersionString(var Version: byte; var VersionString: AnsiString); |
801 |
|
function getOperationCounts: TDBOperationCounts; |
802 |
|
procedure DecodeUserNames(UserNames: TStrings); |
823 |
|
property Items[index: integer]: IDBInfoItem read getItem; default; |
824 |
|
end; |
825 |
|
|
826 |
+ |
{The Database Information Request Block is used to pass requests for |
827 |
+ |
database information where at least one item requested has a parameter. |
828 |
+ |
At present, this is only fb_info_page_contents which has a single |
829 |
+ |
integer parameter.} |
830 |
+ |
|
831 |
+ |
IDIRBItem = interface(IParameterBlockItem) |
832 |
+ |
['{d34a7511-8435-4a24-81a7-5103d218d234}'] |
833 |
+ |
end; |
834 |
+ |
|
835 |
+ |
IDIRB = interface(IParameterBlock<IDIRBItem>) |
836 |
+ |
['{1010e5ac-0a8f-403b-a302-91625e9d9579}'] |
837 |
+ |
end; |
838 |
+ |
|
839 |
+ |
|
840 |
|
{The Database Parameter Block (DPB). |
841 |
|
|
842 |
|
The DPB provides the parameters used when connecting to a database. It is allocated |
885 |
|
|
886 |
|
IAttachment = interface |
887 |
|
['{466e9b67-9def-4807-b3e7-e08a35e7185c}'] |
888 |
+ |
function getFirebirdAPI: IFirebirdAPI; |
889 |
|
function getDPB: IDPB; |
890 |
|
function AllocateBPB: IBPB; |
891 |
+ |
function AllocateDIRB: IDIRB; |
892 |
|
procedure Connect; |
893 |
|
procedure Disconnect(Force: boolean=false); |
894 |
|
function IsConnected: boolean; |
921 |
|
function Prepare(transaction: ITransaction; sql: AnsiString; aSQLDialect: integer): IStatement; overload; |
922 |
|
function Prepare(transaction: ITransaction; sql: AnsiString): IStatement; overload; |
923 |
|
function PrepareWithNamedParameters(transaction: ITransaction; sql: AnsiString; |
924 |
< |
aSQLDialect: integer; GenerateParamNames: boolean=false): IStatement; overload; |
924 |
> |
aSQLDialect: integer; GenerateParamNames: boolean=false; |
925 |
> |
CaseSensitiveParams: boolean = false): IStatement; overload; |
926 |
|
function PrepareWithNamedParameters(transaction: ITransaction; sql: AnsiString; |
927 |
< |
GenerateParamNames: boolean=false): IStatement; overload; |
927 |
> |
GenerateParamNames: boolean=false; |
928 |
> |
CaseSensitiveParams: boolean = false): IStatement; overload; |
929 |
|
|
930 |
|
{Events} |
931 |
|
function GetEventHandler(Events: TStrings): IEvents; overload; |
953 |
|
function GetArrayMetaData(Transaction: ITransaction; tableName, columnName: AnsiString): IArrayMetaData; |
954 |
|
function GetDBInformation(Requests: array of byte): IDBInformation; overload; |
955 |
|
function GetDBInformation(Request: byte): IDBInformation; overload; |
956 |
+ |
function GetDBInformation(Requests: IDIRB): IDBInformation; overload; |
957 |
|
function GetConnectString: AnsiString; |
958 |
|
function GetRemoteProtocol: AnsiString; |
959 |
+ |
function GetAuthenticationMethod: AnsiString; |
960 |
+ |
function GetSecurityDatabase: AnsiString; |
961 |
|
function GetODSMajorVersion: integer; |
962 |
|
function GetODSMinorVersion: integer; |
963 |
+ |
procedure getFBVersion(version: TStrings); |
964 |
|
function HasActivity: boolean; |
965 |
|
|
966 |
|
{Character Sets} |
975 |
|
AllowReverseLookup:boolean; out CharSetID: integer); |
976 |
|
end; |
977 |
|
|
978 |
< |
TProtocol = (TCP, SPX, NamedPipe, Local); |
978 |
> |
TProtocolAll = (TCP, SPX, NamedPipe, Local, inet, inet4, inet6, wnet, xnet, unknownProtocol); |
979 |
> |
TProtocol = TCP..xnet; |
980 |
|
|
981 |
|
{Service Parameter Block (SPB). |
982 |
|
|
1081 |
|
property Count: integer read getCount; |
1082 |
|
end; |
1083 |
|
|
1084 |
+ |
IFirebirdLibrary = interface; |
1085 |
+ |
|
1086 |
|
{The IServiceManager interface provides access to a service manager. It can |
1087 |
|
used to Detach and re-attach to Service Manager, to start services and to |
1088 |
|
query the service manager. |
1094 |
|
|
1095 |
|
IServiceManager = interface |
1096 |
|
['{905b587d-1e1f-4e40-a3f8-a3519f852e48}'] |
1097 |
+ |
function getFirebirdAPI: IFirebirdAPI; |
1098 |
|
function getSPB: ISPB; |
1099 |
|
function getServerName: AnsiString; |
1100 |
+ |
function getProtocol: TProtocol; |
1101 |
+ |
function getPortNo: AnsiString; |
1102 |
|
procedure Attach; |
1103 |
|
procedure Detach(Force: boolean=false); |
1104 |
|
function IsAttached: boolean; |
1105 |
|
function AllocateSRB: ISRB; |
1106 |
|
function AllocateSQPB: ISQPB; |
1107 |
< |
procedure Start(Request: ISRB); |
1108 |
< |
function Query(SQPB: ISQPB; Request: ISRB) :IServiceQueryResults; overload; |
1109 |
< |
function Query(Request: ISRB) :IServiceQueryResults; overload; |
1107 |
> |
function Start(Request: ISRB; RaiseExceptionOnError: boolean=true): boolean; |
1108 |
> |
function Query(SQPB: ISQPB; Request: ISRB; RaiseExceptionOnError: boolean=true) :IServiceQueryResults; overload; |
1109 |
> |
function Query(Request: ISRB; RaiseExceptionOnError: boolean=true) :IServiceQueryResults; overload; |
1110 |
> |
end; |
1111 |
> |
|
1112 |
> |
{Tbe Firebird Library API used to get information about the Firebird library} |
1113 |
> |
|
1114 |
> |
|
1115 |
> |
IFirebirdLibrary = interface |
1116 |
> |
['{3c04e0a1-12e0-428a-b2e1-bc6fcd97b79b}'] |
1117 |
> |
function GetHandle: TLibHandle; |
1118 |
> |
function GetLibraryName: string; |
1119 |
> |
function GetLibraryFilePath: string; |
1120 |
> |
function GetFirebirdAPI: IFirebirdAPI; |
1121 |
|
end; |
1122 |
|
|
1123 |
|
{The Firebird API. |
1146 |
|
{Service Manager} |
1147 |
|
function HasServiceAPI: boolean; |
1148 |
|
function AllocateSPB: ISPB; |
1149 |
< |
function GetServiceManager(ServerName: AnsiString; Protocol: TProtocol; SPB: ISPB): IServiceManager; |
1149 |
> |
function GetServiceManager(ServerName: AnsiString; Protocol: TProtocol; SPB: ISPB): IServiceManager; overload; |
1150 |
> |
function GetServiceManager(ServerName: AnsiString; Port: AnsiString; Protocol: TProtocol; SPB: ISPB): IServiceManager; overload; |
1151 |
|
|
1152 |
|
{Information} |
1153 |
|
function GetStatus: IStatus; |
1090 |
– |
function GetLibraryName: string; |
1154 |
|
function HasRollbackRetaining: boolean; |
1155 |
|
function IsEmbeddedServer: boolean; |
1156 |
|
function GetImplementationVersion: AnsiString; |
1158 |
|
{Firebird 3 API} |
1159 |
|
function HasMasterIntf: boolean; |
1160 |
|
function GetIMaster: TObject; |
1161 |
+ |
function GetFBLibrary: IFirebirdLibrary; |
1162 |
|
end; |
1163 |
|
|
1164 |
|
type |
1211 |
|
function TryIBLoad: Boolean; |
1212 |
|
procedure CheckIBLoaded; |
1213 |
|
|
1214 |
+ |
{If you want to explicitly load the Firebird library from a |
1215 |
+ |
non-default location then use this function and its GetFirebirdAPI function |
1216 |
+ |
to get the API.} |
1217 |
+ |
|
1218 |
+ |
function LoadFBLibrary(aLibPathName: string): IFirebirdLibrary; |
1219 |
+ |
|
1220 |
|
implementation |
1221 |
|
|
1222 |
|
uses FBClientAPI |
1223 |
|
{$IFDEF USELEGACYFIREBIRDAPI}, FB25ClientAPI {$ENDIF} |
1224 |
|
{$IFDEF USEFIREBIRD3API}, FB30ClientAPI {$ENDIF}; |
1225 |
|
|
1226 |
< |
var FFirebirdAPI: IFirebirdAPI; |
1226 |
> |
var FDefaultFBLibrary: IFirebirdLibrary; |
1227 |
> |
|
1228 |
> |
type |
1229 |
> |
|
1230 |
> |
{ TFBLibrary } |
1231 |
> |
|
1232 |
> |
TFBLibraryImpl = class(TFBLibrary) |
1233 |
> |
protected |
1234 |
> |
function GetFirebird3API: IFirebirdAPI; override; |
1235 |
> |
function GetLegacyFirebirdAPI: IFirebirdAPI; override; |
1236 |
> |
end; |
1237 |
> |
|
1238 |
> |
function TFBLibraryImpl.GetFirebird3API: IFirebirdAPI; |
1239 |
> |
begin |
1240 |
> |
{$IFDEF USEFIREBIRD3API} |
1241 |
> |
Result := TFB30ClientAPI.Create(self); |
1242 |
> |
{$ELSE} |
1243 |
> |
Result := nil; |
1244 |
> |
{$ENDIF} |
1245 |
> |
end; |
1246 |
> |
|
1247 |
> |
function TFBLibraryImpl.GetLegacyFirebirdAPI: IFirebirdAPI; |
1248 |
> |
begin |
1249 |
> |
{$IFDEF USELEGACYFIREBIRDAPI} |
1250 |
> |
Result := TFB25ClientAPI.Create(self); |
1251 |
> |
{$ELSE} |
1252 |
> |
Result := nil; |
1253 |
> |
{$ENDIF} |
1254 |
> |
end; |
1255 |
|
|
1256 |
|
function FirebirdAPI: IFirebirdAPI; |
1257 |
|
begin |
1258 |
< |
if FFirebirdAPI = nil then |
1258 |
> |
if FDefaultFBLibrary = nil then |
1259 |
|
CheckIBLoaded; |
1260 |
< |
Result := FFirebirdAPI; |
1260 |
> |
Result := FDefaultFBLibrary.GetFirebirdAPI; |
1261 |
|
end; |
1262 |
|
|
1263 |
|
function TryIBLoad: Boolean; |
1264 |
+ |
var fblib: IFirebirdLibrary; |
1265 |
|
begin |
1266 |
< |
Result := FFirebirdAPI <> nil; |
1266 |
> |
Result := FDefaultFBLibrary <> nil; |
1267 |
|
try |
1169 |
– |
{$IFDEF USEFIREBIRD3API} |
1268 |
|
if not Result then |
1269 |
|
begin |
1270 |
< |
FFirebirdAPI := TFB30ClientAPI.Create; |
1271 |
< |
Result := FFirebirdAPI.HasMasterIntf; |
1272 |
< |
end; |
1273 |
< |
{$ENDIF} |
1176 |
< |
{$IFDEF USELEGACYFIREBIRDAPI} |
1177 |
< |
if not Result then |
1178 |
< |
begin |
1179 |
< |
FFirebirdAPI := nil; |
1180 |
< |
FFirebirdAPI := TFB25ClientAPI.Create; |
1181 |
< |
Result := true; |
1182 |
< |
end; |
1183 |
< |
{$ENDIF} |
1184 |
< |
if Result and not (FFirebirdAPI as TFBClientAPI).IsLibraryLoaded then |
1185 |
< |
begin |
1186 |
< |
Result := false; |
1187 |
< |
FFirebirdAPI := nil; |
1270 |
> |
fblib := TFBLibraryImpl.Create; |
1271 |
> |
if (fblib <> nil) and (fblib.GetFirebirdAPI <> nil) then |
1272 |
> |
FDefaultFBLibrary := fblib; |
1273 |
> |
Result := FDefaultFBLibrary <> nil; |
1274 |
|
end; |
1275 |
|
except |
1276 |
|
SysUtils.showexception(ExceptObject,ExceptAddr); |
1284 |
|
IBError(ibxeInterBaseMissing, [nil]); |
1285 |
|
end; |
1286 |
|
|
1287 |
+ |
function LoadFBLibrary(aLibPathName: string): IFirebirdLibrary; |
1288 |
+ |
var fblib: IFirebirdLibrary; |
1289 |
+ |
begin |
1290 |
+ |
if trim(aLibPathName) = '' then |
1291 |
+ |
begin |
1292 |
+ |
CheckIBLoaded; |
1293 |
+ |
Result := FDefaultFBLibrary; |
1294 |
+ |
end |
1295 |
+ |
else |
1296 |
+ |
begin |
1297 |
+ |
fblib := TFBLibraryImpl.GetFBLibrary(aLibPathName); |
1298 |
+ |
if (fblib = nil) or (fblib.GetFirebirdAPI = nil) then |
1299 |
+ |
IBError(ibxeInterBaseMissing, [nil]); |
1300 |
+ |
Result := fblib; |
1301 |
+ |
end; |
1302 |
+ |
end; |
1303 |
+ |
|
1304 |
|
{ EIBError } |
1305 |
|
|
1306 |
|
constructor EIBError.Create(ASQLCode: Long; Msg: AnsiString); |
1331 |
|
end; |
1332 |
|
|
1333 |
|
initialization |
1334 |
< |
FFirebirdAPI := nil; |
1334 |
> |
FDefaultFBLibrary := nil; |
1335 |
|
|
1336 |
+ |
finalization |
1337 |
+ |
FDefaultFBLibrary := nil; |
1338 |
|
|
1339 |
|
end. |
1340 |
|
|