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 = 1; |
138 |
< |
FBIntf_Release = 1; |
139 |
< |
FBIntf_Version = '1.1.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; |
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); |
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; |
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; |
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 |
< |
TProtocolAll = (TCP, SPX, NamedPipe, Local, inet, wnet, xnet, unknownProtocol); |
978 |
> |
TProtocolAll = (TCP, SPX, NamedPipe, Local, inet, inet4, inet6, wnet, xnet, unknownProtocol); |
979 |
|
TProtocol = TCP..xnet; |
980 |
|
|
981 |
|
{Service Parameter Block (SPB). |
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; |
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. |
1124 |
|
|
1125 |
|
This is the base interface and is used to create/open a database connection, to |
1151 |
|
|
1152 |
|
{Information} |
1153 |
|
function GetStatus: IStatus; |
1113 |
– |
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 |
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} |
1268 |
|
if not Result then |
1269 |
|
begin |
1270 |
< |
FFirebirdAPI := nil; |
1271 |
< |
FFirebirdAPI := TFB25ClientAPI.Create; |
1272 |
< |
Result := true; |
1273 |
< |
end; |
1206 |
< |
{$ENDIF} |
1207 |
< |
if Result and not (FFirebirdAPI as TFBClientAPI).IsLibraryLoaded then |
1208 |
< |
begin |
1209 |
< |
Result := false; |
1210 |
< |
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 |
< |
FFirebirdAPI := nil; |
1337 |
> |
FDefaultFBLibrary := nil; |
1338 |
|
|
1339 |
|
end. |
1340 |
|
|