ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/fbintf/IB.pas
Revision: 263
Committed: Thu Dec 6 15:55:01 2018 UTC (5 years, 4 months ago) by tony
Content type: text/x-pascal
File size: 52172 byte(s)
Log Message:
Release 2.3.2 committed

File Contents

# Content
1 (*
2 * Firebird Interface (fbintf). The fbintf components provide a set of
3 * Pascal language bindings for the Firebird API. Although predominantly
4 * a new development they include source code taken from IBX and may be
5 * considered a derived product. This software thus also includes the copyright
6 * notice and license conditions from IBX.
7 *
8 * Except for those parts dervied from IBX, contents of this file are subject
9 * to the Initial Developer's Public License Version 1.0 (the "License"); you
10 * may not use this file except in compliance with the License. You may obtain a
11 * copy of the License here:
12 *
13 * http://www.firebirdsql.org/index.php?op=doc&id=idpl
14 *
15 * Software distributed under the License is distributed on an "AS
16 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
17 * implied. See the License for the specific language governing rights
18 * and limitations under the License.
19 *
20 * The Initial Developer of the Original Code is Tony Whyman.
21 *
22 * The Original Code is (C) 2016 Tony Whyman, MWA Software
23 * (http://www.mwasoftware.co.uk).
24 *
25 * All Rights Reserved.
26 *
27 * Contributor(s): ______________________________________.
28 *
29 *)
30 {************************************************************************}
31 { }
32 { Borland Delphi Visual Component Library }
33 { InterBase Express core components }
34 { }
35 { Copyright (c) 1998-2000 Inprise Corporation }
36 { }
37 { InterBase Express is based in part on the product }
38 { Free IB Components, written by Gregory H. Deatz for }
39 { Hoagland, Longo, Moran, Dunst & Doukas Company. }
40 { Free IB Components is used under license. }
41 { }
42 { The contents of this file are subject to the InterBase }
43 { Public License Version 1.0 (the "License"); you may not }
44 { use this file except in compliance with the License. You }
45 { may obtain a copy of the License at http://www.Inprise.com/IPL.html }
46 { Software distributed under the License is distributed on }
47 { an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either }
48 { express or implied. See the License for the specific language }
49 { governing rights and limitations under the License. }
50 { The Original Code was created by InterBase Software Corporation }
51 { and its successors. }
52 { Portions created by Inprise Corporation are Copyright (C) Inprise }
53 { Corporation. All Rights Reserved. }
54 { Contributor(s): Jeff Overcash }
55 { }
56 { IBX For Lazarus (Firebird Express) }
57 { Contributor: Tony Whyman, MWA Software http://www.mwasoftware.co.uk }
58 { Portions created by MWA Software are copyright McCallum Whyman }
59 { Associates Ltd 2011 - 2015 }
60 { }
61 {************************************************************************}
62 unit IB;
63 {$IFDEF MSWINDOWS}
64 {$DEFINE WINDOWS}
65 {$ENDIF}
66
67 {$IFDEF FPC}
68 {$mode delphi}
69 {$codepage UTF8}
70 {$interfaces COM}
71 {$IF defined(FPC) and (FPC_FULLVERSION < 30000) }
72 {$ERROR FPC Version 3.0.0 or later is required}
73 {$IFEND}
74 {$ENDIF}
75
76 {$DEFINE USEFIREBIRD3API}
77 {$DEFINE USELEGACYFIREBIRDAPI}
78
79 {
80 This unit defines the interfaces used to provide the Pascal Language
81 bindings for the Firebird API. These are COM style references counted interfaces
82 and are automatically freed when they go out of scope.
83
84 The interface definition is independent of the Firebird API version and two
85 implementations are provided. One is for the legacy API (2.5 and earlier) and the
86 other is for the new object orientated API (3.0 and later). By default, both are
87 available with the 3.0 API used if it is available. Otherwise the 2.5 API is used.
88 The above two defines can be used to force only one implementation by undefining
89 the symbol for the unwanted API.
90
91 Note that the FirebirdAPI function defined below is used for initial access to
92 the language bindings.
93
94 The goals of these Pascal Langauge bindings are to provide:
95
96 1. A set of reference counted interfaces providing complete access to the Firebird API.
97
98 2. Application Independence from the Firebird API version.
99
100 3. All data access through strongly typed variables and functions with no need for
101 the end user to manipulate untyped data in buffers such as the legacy API SQLDA
102 or the Firebird 3.0 message buffer.
103
104 4. A stable platform for LCL Packages (e.g. IBX) that implement the TDataSet model
105 with independence from the Firebird API version.
106
107 5. Straightforward progammatic access to the Firebird API from Pascal programs.
108
109 6. FPC and Delphi Support.
110
111 String Types
112 ============
113
114 From FPC 3.0 onwards, ANSISTRINGs include the codepage in their definition. All
115 strings used by the interface are sensitive to the codepage in that the codepage
116 for all strings returned by an interface is consistent with the SQL Character set
117 used for the database connection. Input strings will be transliterated, where possible
118 and if necessary, to the codepage consistent with the character set used for
119 the database connection.
120 }
121
122 interface
123
124 uses
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 = 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}
139
140 {$I 'include/consts_pub.inc'}
141 {$I 'include/inf_pub.inc'}
142 {$I 'include/configkeys.inc'}
143
144 {The following constants define the values return by calls to the GetSQLType
145 methods provided by several of the interfaces defined below.}
146
147 (*********************)
148 (** SQL definitions **)
149 (*********************)
150 SQL_VARYING = 448;
151 SQL_TEXT = 452;
152 SQL_DOUBLE = 480;
153 SQL_FLOAT = 482;
154 SQL_LONG = 496;
155 SQL_SHORT = 500;
156 SQL_TIMESTAMP = 510;
157 SQL_BLOB = 520;
158 SQL_D_FLOAT = 530;
159 SQL_ARRAY = 540;
160 SQL_QUAD = 550;
161 SQL_TYPE_TIME = 560;
162 SQL_TYPE_DATE = 570;
163 SQL_INT64 = 580;
164 SQL_BOOLEAN = 32764;
165 SQL_DATE = SQL_TIMESTAMP;
166
167 type
168 TGDS_QUAD = record
169 gds_quad_high : ISC_LONG;
170 gds_quad_low : UISC_LONG;
171 end;
172 TGDS__QUAD = TGDS_QUAD;
173 TISC_QUAD = TGDS_QUAD;
174 PGDS_QUAD = ^TGDS_QUAD;
175 PGDS__QUAD = ^TGDS__QUAD;
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
190 CP_OEMCP = 1; // default to OEM (console) code page
191 CP_UTF16BE = 1201; // unicodeFFFE
192 CP_UTF7 = 65000; // utf-7
193 CP_ASCII = 20127; // us-ascii
194 CP_NONE = $FFFF; // rawbytestring encoding
195
196 {$ENDIF}
197
198 type
199 {$IF not declared(TSystemCodePage)}
200 TSystemCodePage = word; {not defined in Delphi}
201 {$IFEND}
202
203 TIBSQLStatementTypes =
204 (SQLUnknown, SQLSelect, SQLInsert,
205 SQLUpdate, SQLDelete, SQLDDL,
206 SQLGetSegment, SQLPutSegment,
207 SQLExecProcedure, SQLStartTransaction,
208 SQLCommit, SQLRollback,
209 SQLSelectForUpdate, SQLSetGenerator);
210
211 TFBStatusCode = cardinal;
212 TByteArray = array of byte;
213
214 IFirebirdAPI = interface;
215 IAttachment = interface;
216 ITransaction = interface;
217
218 {The IParameterBlock interface provides the template for all parameter
219 block interfaces}
220
221 IParameterBlock<_IItem> = interface
222 function getCount: integer;
223 function Add(ParamType: byte): _IItem;
224 function getItems(index: integer): _IItem;
225 function Find(ParamType: byte): _IItem;
226 procedure PrintBuf; {can be used to print buffer in hex for debugging}
227 property Count: integer read getCount;
228 property Items[index: integer]: _IItem read getItems; default;
229 end;
230
231 {IParameterBlockItem is not used on its own but instead provides a base type for
232 different parameter block items }
233
234 IParameterBlockItem = interface
235 ['{53b23f7b-abda-46a5-9aa5-07bd5e723266}']
236 function getParamType: byte;
237 function getAsInteger: integer;
238 function getAsString: AnsiString;
239 function getAsByte: byte;
240 procedure setAsString(aValue: AnsiString);
241 procedure setAsByte(aValue: byte);
242 procedure SetAsInteger(aValue: integer);
243 property AsString: AnsiString read getAsString write setAsString;
244 property AsByte: byte read getAsByte write setAsByte;
245 property AsInteger: integer read getAsInteger write SetAsInteger;
246 end;
247
248
249 {The IStatus interface provides access to error information, if any, returned
250 by the last API call. It can also be used to customise the error message
251 returned by a database engine exception - see EIBInterbaseError.
252
253 This interface can be accessed from IFirebirdAPI.
254 }
255
256 IStatus = interface
257 ['{34167722-af38-4831-b08a-93162d58ede3}']
258 function GetIBErrorCode: Long;
259 function Getsqlcode: Long;
260 function GetMessage: AnsiString;
261 function CheckStatusVector(ErrorCodes: array of TFBStatusCode): Boolean;
262 function GetIBDataBaseErrorMessages: TIBDataBaseErrorMessages;
263 procedure SetIBDataBaseErrorMessages(Value: TIBDataBaseErrorMessages);
264 end;
265
266 { The array metadata interface provides access to the metadata used to describe
267 an array column in a Firebird table.
268 }
269
270 TArrayBound = record
271 UpperBound: short;
272 LowerBound: short;
273 end;
274 TArrayBounds = array of TArrayBound;
275
276 IArrayMetaData = interface
277 ['{7dd0aea4-59af-4c2a-b958-565d5025c489}']
278 function GetSQLType: cardinal;
279 function GetSQLTypeName: AnsiString;
280 function GetScale: integer;
281 function GetSize: cardinal;
282 function GetCharSetID: cardinal;
283 function GetTableName: AnsiString;
284 function GetColumnName: AnsiString;
285 function GetDimensions: integer;
286 function GetBounds: TArrayBounds;
287 end;
288
289 {The array interface provides access to and modification of the array data
290 contained in an array field of a Firebird Table. The array element is
291 selected by specifying its co-ordinates using an integer array. The
292 getter and setter methods used should be appropriate for the type of data
293 contained in the array. Automatic conversion is provided to and from strings.
294 That is GetAsString and SetAsString are safe to use for sql types other than
295 boolean.
296
297 The interface is returned by a GetAsArray getter method (see ISQLData). A new array
298 can be obtained from the IAttachment interface. The SetAsArray setter method
299 (See ISQLParam) is used to apply an updated or new array to the database using
300 an UPDATE or INSERT statement.
301
302 }
303
304 TArrayEventReason = (arChanging,arChanged);
305 IArray = interface;
306 TArrayEventHandler = procedure(Sender: IArray; Reason: TArrayEventReason) of object;
307
308 IArray = interface(IArrayMetaData)
309 ['{631c6bb1-fb49-44fb-a64a-c49859632b88}']
310 function GetArrayID: TISC_QUAD;
311 procedure Clear;
312 function IsEmpty: boolean;
313 procedure PreLoad;
314 procedure CancelChanges;
315 procedure SaveChanges;
316 function GetAsInteger(index: array of integer): integer;
317 function GetAsBoolean(index: array of integer): boolean;
318 function GetAsCurrency(index: array of integer): Currency;
319 function GetAsInt64(index: array of integer): Int64;
320 function GetAsDateTime(index: array of integer): TDateTime;
321 function GetAsDouble(index: array of integer): Double;
322 function GetAsFloat(index: array of integer): Float;
323 function GetAsLong(index: array of integer): Long;
324 function GetAsShort(index: array of integer): Short;
325 function GetAsString(index: array of integer): AnsiString;
326 function GetAsVariant(index: array of integer): Variant;
327 procedure SetAsInteger(index: array of integer; AValue: integer);
328 procedure SetAsBoolean(index: array of integer; AValue: boolean);
329 procedure SetAsCurrency(index: array of integer; Value: Currency);
330 procedure SetAsInt64(index: array of integer; Value: Int64);
331 procedure SetAsDate(index: array of integer; Value: TDateTime);
332 procedure SetAsLong(index: array of integer; Value: Long);
333 procedure SetAsTime(index: array of integer; Value: TDateTime);
334 procedure SetAsDateTime(index: array of integer; Value: TDateTime);
335 procedure SetAsDouble(index: array of integer; Value: Double);
336 procedure SetAsFloat(index: array of integer; Value: Float);
337 procedure SetAsShort(index: array of integer; Value: Short);
338 procedure SetAsString(index: array of integer; Value: AnsiString);
339 procedure SetAsVariant(index: array of integer; Value: Variant);
340 procedure SetBounds(dim, UpperBound, LowerBound: integer);
341 function GetAttachment: IAttachment;
342 function GetTransaction: ITransaction;
343 procedure AddEventHandler(Handler: TArrayEventHandler);
344 procedure RemoveEventHandler(Handler: TArrayEventHandler);
345 end;
346
347 { The Blob metadata interface provides access to the metadata used to describe
348 a blob column in a Firebird table.
349 }
350
351 IBlobMetaData = interface
352 ['{575f3c61-bb33-46a5-8975-bb7d1b6e37cc}']
353 function GetSubType: integer;
354 function GetCharSetID: cardinal;
355 function GetCodePage: TSystemCodePage;
356 function GetSegmentSize: cardinal;
357 function GetRelationName: AnsiString;
358 function GetColumnName: AnsiString;
359 end;
360
361 {The Blob Parameter block is used to select a Blob Filter}
362
363 IBPBItem = interface (IParameterBlockItem)
364 ['{660822a5-3114-4c16-b6cb-c1a7b2aba70d}']
365 end;
366
367 IBPB = interface (IParameterBlock<IBPBItem>)
368 ['{e0cb9eb5-17f7-4416-b7d1-3cddd1dfca76}']
369 end;
370
371 { The Blob Interface provides access to a blob data item.
372
373 The interface is returned by a GetAsBlob getter method (see ISQLData). A new Blob
374 can be obtained from the IAttachment interface. The SetAsBlob setter method
375 (See ISQLParam) is used to apply an updated or new array to the database using
376 an UPDATE or INSERT statement.
377 }
378
379 TFBBlobMode = (fbmRead,fbmWrite);
380 TBlobType = (btSegmented,btStream);
381
382 IBlob = interface(IBlobMetaData)
383 ['{3090a145-7780-442b-b15b-efd4568b8611}']
384 function GetBPB: IBPB;
385 procedure Cancel;
386 procedure Close;
387 function GetBlobID: TISC_QUAD;
388 function GetBlobMode: TFBBlobMode;
389 function GetBlobSize: Int64;
390 procedure GetInfo(var NumSegments: Int64; var MaxSegmentSize,
391 TotalSize: Int64; var BlobType: TBlobType);
392 function Read(var Buffer; Count: Longint): Longint;
393 function Write(const Buffer; Count: Longint): Longint;
394 function LoadFromFile(Filename: AnsiString): IBlob;
395 function LoadFromStream(S: TStream) : IBlob;
396 function SaveToFile(Filename: AnsiString): IBlob;
397 function SaveToStream(S: TStream): IBlob;
398 function GetAsString: rawbytestring;
399 procedure SetAsString(aValue: rawbytestring);
400 function SetString(aValue: rawbytestring): IBlob;
401 function GetAttachment: IAttachment;
402 function GetTransaction: ITransaction;
403 property AsString: rawbytestring read GetAsString write SetAsString;
404 end;
405
406 { The IColumnMetaData interface provides access to the per column metadata for
407 the output of an SQL Statement.
408 }
409
410 { IColumnMetaData }
411
412 IColumnMetaData = interface
413 ['{c222e6c3-53c1-469f-9e05-0a5c3ef232d8}']
414 function GetIndex: integer;
415 function GetSQLType: cardinal;
416 function GetSQLTypeName: AnsiString;
417 function getSubtype: integer;
418 function getRelationName: AnsiString;
419 function getOwnerName: AnsiString;
420 function getSQLName: AnsiString; {Name of the column}
421 function getAliasName: AnsiString; {Alias Name of column or Column Name if no alias}
422 function getName: AnsiString; {Disambiguated uppercase Field Name}
423 function getScale: integer;
424 function getCharSetID: cardinal;
425 function getCodePage: TSystemCodePage;
426 function getIsNullable: boolean;
427 function GetSize: cardinal;
428 function GetArrayMetaData: IArrayMetaData; {Valid only for Array SQL Type}
429 function GetBlobMetaData: IBlobMetaData; {Valid only for Blob SQL Type}
430 property Name: AnsiString read GetName;
431 property Size: cardinal read GetSize;
432 property SQLType: cardinal read GetSQLType;
433 property Scale: integer read getScale;
434 property SQLSubtype: integer read getSubtype;
435 property IsNullable: Boolean read GetIsNullable;
436 end;
437
438 {
439 The IMetaData interface provides access to the set of column metadata
440 for the output of an SQL Statement
441 }
442
443 { IMetaData }
444
445 IMetaData = interface
446 ['{4dafdbb6-0d36-4f1f-9c95-8b132804b965}']
447 function getCount: integer;
448 function getColumnMetaData(index: integer): IColumnMetaData;
449 function GetUniqueRelationName: AnsiString; {Non empty if all columns come from the same table}
450 function ByName(Idx: AnsiString): IColumnMetaData;
451 property ColMetaData[index: integer]: IColumnMetaData read getColumnMetaData; default;
452 property Count: integer read getCount;
453 end;
454
455 {
456 The ISQLData interface provides access to the data returned in a field in the
457 current row returned from a query or the result of an SQL Execute statement.
458
459 It subclasses IColumnMetaData and so also provides access to the metadata
460 associated with the column.
461
462 The getter and setter methods, and the corresponding properties, provide typed
463 access to the field data. The method/property used should be consistent
464 with the SQL Type. Automatic conversion is provided from strings.
465 That is GetAsString is safe to use for sql types other than boolean.
466 }
467
468
469 ISQLData = interface(IColumnMetaData)
470 ['{3f493e31-7e3f-4606-a07c-b210b9e3619d}']
471 function GetAsBoolean: boolean;
472 function GetAsCurrency: Currency;
473 function GetAsInt64: Int64;
474 function GetAsDateTime: TDateTime;
475 function GetAsDouble: Double;
476 function GetAsFloat: Float;
477 function GetAsLong: Long;
478 function GetAsPointer: Pointer;
479 function GetAsQuad: TISC_QUAD;
480 function GetAsShort: short;
481 function GetAsString: AnsiString;
482 function GetIsNull: Boolean;
483 function GetAsVariant: Variant;
484 function GetAsBlob: IBlob; overload;
485 function GetAsBlob(BPB: IBPB): IBlob; overload;
486 function GetAsArray: IArray;
487 property AsDate: TDateTime read GetAsDateTime;
488 property AsBoolean:boolean read GetAsBoolean;
489 property AsTime: TDateTime read GetAsDateTime;
490 property AsDateTime: TDateTime read GetAsDateTime ;
491 property AsDouble: Double read GetAsDouble;
492 property AsFloat: Float read GetAsFloat;
493 property AsCurrency: Currency read GetAsCurrency;
494 property AsInt64: Int64 read GetAsInt64 ;
495 property AsInteger: Integer read GetAsLong;
496 property AsLong: Long read GetAsLong;
497 property AsPointer: Pointer read GetAsPointer;
498 property AsQuad: TISC_QUAD read GetAsQuad;
499 property AsShort: short read GetAsShort;
500 property AsString: AnsiString read GetAsString;
501 property AsVariant: Variant read GetAsVariant ;
502 property AsBlob: IBlob read GetAsBlob;
503 property AsArray: IArray read GetAsArray;
504 property IsNull: Boolean read GetIsNull;
505 property Value: Variant read GetAsVariant;
506 end;
507
508 { An IResults interface is returned as the result of an SQL Execute statement
509 and provides access to the fields returned, if any. It is a collection of
510 ISQLData interfaces which are, in turn, used to access the data returned by
511 each field of the result set.
512 }
513
514 IResults = interface
515 ['{e836b2bb-93d1-4bbf-a8eb-7ce535de3bb5}']
516 function getCount: integer;
517 function GetTransaction: ITransaction;
518 function ByName(Idx: AnsiString): ISQLData;
519 function getSQLData(index: integer): ISQLData;
520 procedure GetData(index: integer; var IsNull:boolean; var len: short; var data: PByte);
521 procedure SetRetainInterfaces(aValue: boolean);
522 property Data[index: integer]: ISQLData read getSQLData; default;
523 property Count: integer read getCount;
524 end;
525
526 { An IResultSet interface is returned as the result of an SQL Open Cursor statement
527 (e.g. Select Statement) and provides access to the fields returned, if any
528 for the current row. It is a collection of ISQLData interfaces which are,
529 in turn, used to access the data returned by each field of the current row.
530 }
531 IResultSet = interface(IResults)
532 ['{0ae4979b-7857-4e8c-8918-ec6f155b51a0}']
533 function FetchNext: boolean;
534 function GetCursorName: AnsiString;
535 function IsEof: boolean;
536 procedure Close;
537 end;
538
539 {The ISQLParam interface is used to provide access to each parameter in a
540 parametised SQL Statement. It subclasses IColumnMetaData and this part of
541 the interface may be used to access information on the expected SQL Type, etc.
542
543 It also subclasses ISQLData and this part of the interface may be used to access
544 current values for each parameter.
545
546 Otherwise, the interface comprises the Setter Methods and properties used to
547 set the value of each parameter.
548
549 Automatic conversion is provided to and from strings. That is GetAsString and
550 SetAsString are safe to use for sql types other than boolean - provided automatic
551 conversion is possible.
552 }
553
554 ISQLParam = interface
555 ['{b22b4578-6d41-4807-a9a9-d2ec8d1d5a14}']
556 function GetIndex: integer;
557 function GetSQLType: cardinal;
558 function GetSQLTypeName: AnsiString;
559 function getSubtype: integer;
560 function getName: AnsiString;
561 function getScale: integer;
562 function getCharSetID: cardinal;
563 function getCodePage: TSystemCodePage;
564 function getIsNullable: boolean;
565 function GetSize: cardinal;
566 function GetAsBoolean: boolean;
567 function GetAsCurrency: Currency;
568 function GetAsInt64: Int64;
569 function GetAsDateTime: TDateTime;
570 function GetAsDouble: Double;
571 function GetAsFloat: Float;
572 function GetAsLong: Long;
573 function GetAsPointer: Pointer;
574 function GetAsQuad: TISC_QUAD;
575 function GetAsShort: short;
576 function GetAsString: AnsiString;
577 function GetIsNull: boolean;
578 function GetAsVariant: Variant;
579 function GetAsBlob: IBlob;
580 function GetAsArray: IArray;
581 procedure Clear;
582 function GetModified: boolean;
583 procedure SetAsBoolean(AValue: boolean);
584 procedure SetAsCurrency(aValue: Currency);
585 procedure SetAsInt64(aValue: Int64);
586 procedure SetAsDate(aValue: TDateTime);
587 procedure SetAsLong(aValue: Long);
588 procedure SetAsTime(aValue: TDateTime);
589 procedure SetAsDateTime(aValue: TDateTime);
590 procedure SetAsDouble(aValue: Double);
591 procedure SetAsFloat(aValue: Float);
592 procedure SetAsPointer(aValue: Pointer);
593 procedure SetAsShort(aValue: Short);
594 procedure SetAsString(aValue: AnsiString);
595 procedure SetAsVariant(aValue: Variant);
596 procedure SetIsNull(aValue: Boolean);
597 procedure SetAsBlob(aValue: IBlob);
598 procedure SetAsArray(anArray: IArray);
599 procedure SetAsQuad(aValue: TISC_QUAD);
600 procedure SetCharSetID(aValue: cardinal);
601 property AsDate: TDateTime read GetAsDateTime write SetAsDate;
602 property AsBoolean:boolean read GetAsBoolean write SetAsBoolean;
603 property AsTime: TDateTime read GetAsDateTime write SetAsTime;
604 property AsDateTime: TDateTime read GetAsDateTime write SetAsDateTime;
605 property AsDouble: Double read GetAsDouble write SetAsDouble;
606 property AsFloat: Float read GetAsFloat write SetAsFloat;
607 property AsCurrency: Currency read GetAsCurrency write SetAsCurrency;
608 property AsInt64: Int64 read GetAsInt64 write SetAsInt64;
609 property AsInteger: Integer read GetAsLong write SetAsLong;
610 property AsLong: Long read GetAsLong write SetAsLong;
611 property AsPointer: Pointer read GetAsPointer write SetAsPointer;
612 property AsShort: Short read GetAsShort write SetAsShort;
613 property AsString: AnsiString read GetAsString write SetAsString;
614 property AsVariant: Variant read GetAsVariant write SetAsVariant;
615 property AsBlob: IBlob read GetAsBlob write SetAsBlob;
616 property AsArray: IArray read GetAsArray write SetAsArray;
617 property AsQuad: TISC_QUAD read GetAsQuad write SetAsQuad;
618 property Value: Variant read GetAsVariant write SetAsVariant;
619 property IsNull: Boolean read GetIsNull write SetIsNull;
620 property IsNullable: Boolean read GetIsNullable;
621 property Modified: Boolean read getModified;
622 property Name: AnsiString read GetName;
623 property SQLType: cardinal read GetSQLType;
624 end;
625
626 {
627 The ISQLParams interface provides access to the collection of parameters used
628 for the input to an SQL Statement
629 }
630
631 ISQLParams = interface
632 ['{c6d95ac7-b2b7-461b-b890-afef0acbb077}']
633 function getCount: integer;
634 function getSQLParam(index: integer): ISQLParam;
635 function ByName(Idx: AnsiString): ISQLParam ;
636 function GetModified: Boolean;
637 property Modified: Boolean read GetModified;
638 property Params[index: integer]: ISQLParam read getSQLParam; default;
639 property Count: integer read getCount;
640 end;
641
642
643 TPerfStats = (psCurrentMemory, psMaxMemory,
644 psRealTime, psUserTime, psBuffers,
645 psReads, psWrites, psFetches,psDeltaMemory);
646
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.
651 }
652
653 IStatement = interface
654 ['{a260576d-a07d-4a66-b02d-1b72543fd7cf}']
655 function GetMetaData: IMetaData; {Output Metadata}
656 function GetSQLParams: ISQLParams;{Statement Parameters}
657 function GetPlan: AnsiString;
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);
665 function Execute(aTransaction: ITransaction=nil): IResults;
666 function OpenCursor(aTransaction: ITransaction=nil): IResultSet;
667 function GetAttachment: IAttachment;
668 function GetTransaction: ITransaction;
669 procedure SetRetainInterfaces(aValue: boolean);
670 procedure EnableStatistics(aValue: boolean);
671 function GetPerfStatistics(var stats: TPerfCounters): boolean;
672 property MetaData: IMetaData read GetMetaData;
673 property SQLParams: ISQLParams read GetSQLParams;
674 property SQLStatementType: TIBSQLStatementTypes read GetSQLStatementType;
675 end;
676
677 {Transaction Parameter Block: (TPB)
678
679 The TPB provides the parameters used when starting a transaction. It is allocated
680 empty by the FirebirdAPI and the parameters are then added to it. Each individual
681 parameter may be accessed by the ITPBItem interface which can be used to set the
682 value, if any, of the parameter.
683
684 The TPB parameters, and the associated symbolic codes and parameter values may be
685 found in the Interbase 6.0 API Guide.
686 }
687
688 ITPBItem = interface(IParameterBlockItem)
689 ['{544c1f2b-7c12-4a87-a4a5-face7ea72671}']
690 end;
691
692 ITPB = interface(IParameterBlock<ITPBItem>)
693 ['{7369b0ff-defe-437b-81fe-19b211d42d25}']
694 end;
695
696 {The ITransactionAction interface provides access to a Transaction once it
697 has been initially started. After a Commit or Rollback, a transaction
698 may be restarted, optinally with a new TPB.
699
700 A multi-database transaction is started from the FirebirdAPI. A single database
701 transaction is started from the IAttachment interface.
702 }
703
704 TTransactionAction = (TARollback, TACommit, TACommitRetaining, TARollbackRetaining);
705 TTransactionCompletion = TARollback.. TACommit;
706
707 ITransaction = interface
708 ['{30928d0e-a9d7-4c61-b7cf-14f4f38abe2a}']
709 function getTPB: ITPB;
710 procedure Start(DefaultCompletion: TTransactionCompletion=taCommit);
711 function GetInTransaction: boolean;
712 procedure PrepareForCommit; {Two phase commit - stage 1}
713 procedure Commit(Force: boolean=false);
714 procedure CommitRetaining;
715 function HasActivity: boolean;
716 procedure Rollback(Force: boolean=false);
717 procedure RollbackRetaining;
718 function GetAttachmentCount: integer;
719 function GetAttachment(index: integer): IAttachment;
720 property InTransaction: boolean read GetInTransaction;
721 end;
722
723 { The IEvents Interface is used to handle events from a single database. The
724 interface is allocated from the IAttachment Interface.
725
726 Note that the EventHandler called when an event occurs following AsynWaitForEvent
727 is called in a different thread to the calling program and TThread.Synchronize
728 may be needed to pass the event back to the main thread.
729
730 Neither AsyncWaitForEvent nor WaitForEvent is intended to be thread safe
731 in a multi-threaded environment and should always be called from the main
732 thread.
733 }
734
735 TEventInfo = record
736 EventName: AnsiString;
737 Count: integer;
738 end;
739
740 TEventCounts = array of TEventInfo;
741 IEvents = interface;
742 TEventHandler = procedure(Sender: IEvents) of object;
743
744 { IEvents }
745
746 IEvents = interface
747 ['{6a0be233-ed08-4524-889c-2e45d0c20e5f}']
748 procedure GetEvents(EventNames: TStrings);
749 procedure SetEvents(EventNames: TStrings); overload;
750 procedure SetEvents(EventName: AnsiString); overload;
751 procedure Cancel;
752 function ExtractEventCounts: TEventCounts;
753 procedure WaitForEvent;
754 procedure AsyncWaitForEvent(EventHandler: TEventHandler);
755 function GetAttachment: IAttachment;
756 end;
757
758 {The IDBInformation Interface.
759
760 An IDBInformation interface is returned by the IAttachment GetDBInformation
761 method. The interface provides access to the information requested and
762 returned by the method.
763
764 IDBInformation itself gives access to a collection of IDBInfoItems. Each one
765 provides information requested, as indicated by the ItemType and the actual
766 value of the information. In some cases, the returned item is itself a
767 colletion of IDBInfoItems.
768
769 The IDBInformation items, and the associated symbolic codes and parameter values may be
770 found in the Interbase 6.0 API Guide.
771 }
772
773 TDBOperationCount = record
774 TableID: UShort;
775 Count: cardinal;
776 end;
777
778 TDBOperationCounts = array of TDBOperationCount;
779
780 IDBInfoItem = interface
781 ['{eeb97b51-ec0f-473f-9f75-c1721f055fcb}']
782 function getItemType: byte;
783 function getSize: integer;
784 procedure getRawBytes(var Buffer);
785 function getAsString: AnsiString;
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);
793
794 {user names only}
795 function GetCount: integer;
796 function GetItem(index: integer): IDBInfoItem;
797 function Find(ItemType: byte): IDBInfoItem;
798 property AsInteger: integer read getAsInteger;
799 property AsString: AnsiString read GetAsString;
800 property Count: integer read GetCount;
801 property Items[index: integer]: IDBInfoItem read getItem; default;
802 end;
803
804 { IDBInformation }
805
806 IDBInformation = interface
807 ['{7ac6777f-f0a9-498a-9f5c-4a57a554df81}']
808 function GetCount: integer;
809 function GetItem(index: integer): IDBInfoItem;
810 function Find(ItemType: byte): IDBInfoItem;
811 procedure PrintBuf; {can be used to print buffer in hex for debugging}
812 property Count: integer read GetCount;
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
833 empty by the FirebirdAPI and the parameters are then added to it. Each individual
834 parameter may be accessed by the IDPBItem interface which can be used to set the
835 value, if any, of the parameter.
836
837 The DPB parameters, and the associated symbolic codes and parameter values may be
838 found in the Interbase 6.0 API Guide.
839 }
840
841 IDPBItem = interface(IParameterBlockItem)
842 ['{123d4ad0-087a-4cd1-a344-1b3d03b30673}']
843 end;
844
845 IDPB = interface(IParameterBlock<IDPBItem>)
846 ['{e676067b-1cf4-4eba-9256-9724f57e0d16}']
847 end;
848
849 {The IAttachment interface provides access to a Database Connection. It may be
850 used to:
851
852 a. Disconnect and reconnect to the database.
853
854 b. Start a Transaction on the database
855
856 c. Execute directly SQL DDL Statements and others that return no information.
857
858 d. OpenCursors (i.e. execute SQL Select statements and return the results)
859
860 e. Prepare SQL Statements, returning an IStatement interface for further processing.
861
862 f. Provide access to an SQL Event Handler.
863
864 g. Access Database Information.
865
866 h. Support the handling of Array and Blob data.
867
868 Note that SQL statements can be prepared with named parameters (PSQL style).
869 This then allows the parameters to be accessed by name. The same name can
870 be used for more than one parameter, allowing a single operation to be used
871 to set all parameters with the same name.
872 }
873
874 { IAttachment }
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;
885 procedure DropDatabase;
886 function StartTransaction(TPB: array of byte; DefaultCompletion: TTransactionCompletion=taCommit): ITransaction; overload;
887 function StartTransaction(TPB: ITPB; DefaultCompletion: TTransactionCompletion=taCommit): ITransaction; overload;
888 procedure ExecImmediate(transaction: ITransaction; sql: AnsiString; SQLDialect: integer); overload;
889 procedure ExecImmediate(TPB: array of byte; sql: AnsiString; SQLDialect: integer); overload;
890 procedure ExecImmediate(transaction: ITransaction; sql: AnsiString); overload;
891 procedure ExecImmediate(TPB: array of byte; sql: AnsiString); overload;
892 function ExecuteSQL(TPB: array of byte; sql: AnsiString; SQLDialect: integer; params: array of const): IResults; overload;
893 function ExecuteSQL(transaction: ITransaction; sql: AnsiString; SQLDialect: integer; params: array of const): IResults; overload;
894 function ExecuteSQL(TPB: array of byte; sql: AnsiString; params: array of const): IResults; overload;
895 function ExecuteSQL(transaction: ITransaction; sql: AnsiString; params: array of const): IResults; overload;
896 function OpenCursor(transaction: ITransaction; sql: AnsiString; aSQLDialect: integer): IResultSet; overload;
897 function OpenCursor(transaction: ITransaction; sql: AnsiString; aSQLDialect: integer;
898 params: array of const): IResultSet; overload;
899 function OpenCursor(transaction: ITransaction; sql: AnsiString): IResultSet; overload;
900 function OpenCursor(transaction: ITransaction; sql: AnsiString;
901 params: array of const): IResultSet; overload;
902 function OpenCursorAtStart(transaction: ITransaction; sql: AnsiString; aSQLDialect: integer): IResultSet; overload;
903 function OpenCursorAtStart(transaction: ITransaction; sql: AnsiString; aSQLDialect: integer;
904 params: array of const): IResultSet; overload;
905 function OpenCursorAtStart(transaction: ITransaction; sql: AnsiString): IResultSet; overload;
906 function OpenCursorAtStart(transaction: ITransaction; sql: AnsiString;
907 params: array of const): IResultSet; overload;
908 function OpenCursorAtStart(sql: AnsiString): IResultSet; overload;
909 function OpenCursorAtStart(sql: AnsiString;
910 params: array of const): IResultSet; overload;
911 function Prepare(transaction: ITransaction; sql: AnsiString; aSQLDialect: integer): IStatement; overload;
912 function Prepare(transaction: ITransaction; sql: AnsiString): IStatement; overload;
913 function PrepareWithNamedParameters(transaction: ITransaction; sql: AnsiString;
914 aSQLDialect: integer; GenerateParamNames: boolean=false): IStatement; overload;
915 function PrepareWithNamedParameters(transaction: ITransaction; sql: AnsiString;
916 GenerateParamNames: boolean=false): IStatement; overload;
917
918 {Events}
919 function GetEventHandler(Events: TStrings): IEvents; overload;
920 function GetEventHandler(Event: AnsiString): IEvents; overload;
921
922 {Blob - may use to open existing Blobs. However, ISQLData.AsBlob is preferred}
923
924 function CreateBlob(transaction: ITransaction; RelationName, ColumnName: AnsiString; BPB: IBPB=nil): IBlob; overload;
925 function CreateBlob(transaction: ITransaction; BlobMetaData: IBlobMetaData; BPB: IBPB=nil): IBlob; overload;
926 function CreateBlob(transaction: ITransaction; SubType: integer; CharSetID: cardinal=0; BPB: IBPB=nil): IBlob; overload;
927 function OpenBlob(transaction: ITransaction; RelationName, ColumnName: AnsiString; BlobID: TISC_QUAD; BPB: IBPB=nil): IBlob;
928
929 {Array - may use to open existing arrays. However, ISQLData.AsArray is preferred}
930
931 function OpenArray(transaction: ITransaction; RelationName, ColumnName: AnsiString; ArrayID: TISC_QUAD): IArray;
932 function CreateArray(transaction: ITransaction; RelationName, ColumnName: AnsiString): IArray; overload;
933 function CreateArray(transaction: ITransaction; ArrayMetaData: IArrayMetaData): IArray; overload;
934 function CreateArrayMetaData(SQLType: cardinal; tableName: AnsiString; columnName: AnsiString;
935 Scale: integer; size: cardinal; charSetID: cardinal; dimensions: cardinal;
936 bounds: TArrayBounds): IArrayMetaData;
937
938 {Database Information}
939 function GetSQLDialect: integer;
940 function GetBlobMetaData(Transaction: ITransaction; tableName, columnName: AnsiString): IBlobMetaData;
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 TProtocolAll = (TCP, SPX, NamedPipe, Local, inet, inet4, inet6, wnet, xnet, unknownProtocol);
966 TProtocol = TCP..xnet;
967
968 {Service Parameter Block (SPB).
969
970 The SPB provides the parameters used when connecting to a Service Manager. It is
971 allocated empty by the FirebirdAPI and the parameters are then added to it. Each
972 individual parameter may be accessed by the ISPBItem interface which can be used
973 to set the value, if any, of the parameter.
974
975 The SPB parameters, and the associated symbolic codes and parameter values may be
976 found in the Interbase 6.0 API Guide.
977
978 }
979
980 ISPBItem = interface(IParameterBlockItem)
981 ['{5d08ae2b-4519-41bd-8b40-97cd451c3f6a}']
982 end;
983
984 ISPB = interface(IParameterBlock<ISPBItem>)
985 ['{2c5836fd-41ed-4426-9b7d-5af580ec2659}']
986 end;
987
988 {Service Query Parameter Block (SQPB).
989
990 This is a specialised parameter block used to send data to a service manager
991 in a Query Request.
992 }
993
994 ISQPBItem = interface(IParameterBlockItem)
995 ['{b07841a6-33b3-47f0-b5a2-028cbc86dc97}']
996 function CopyFrom(source: TStream; count: integer): integer;
997 end;
998
999 ISQPB = interface(IParameterBlock<ISQPBItem>)
1000 ['{8553e66b-ee62-498b-8431-dff030211447}']
1001 end;
1002
1003 {Service Request Block (SRB).
1004
1005 The SRB specifies what is requested from the Service Manager when starting a
1006 service or querying a service. It is allocated empty by the ServiceManager API and
1007 the parameters are then added to it. Each individual parameter may be accessed
1008 by the ISRBItem interface which can be used to set the value, if any, of the parameter.
1009
1010 The SRB parameters, and the associated symbolic codes and parameter values may be
1011 found in the Interbase 6.0 API Guide.
1012
1013 }
1014
1015 ISRBItem = interface(IParameterBlockItem)
1016 ['{47ec790e-f265-4b30-9dcd-261e51677245}']
1017 end;
1018
1019 ISRB = interface(IParameterBlock<ISRBItem>)
1020 ['{9f2e204f-3c33-4e44-90f9-9135e95dafb9}']
1021 end;
1022
1023 {The Service Query Results Interface.
1024
1025 An IServiceQueryResults interface is returned by the IServiceManager Query
1026 method. The interface provides access to the information requested and
1027 returned by the method.
1028
1029 IServiceQueryResults itself gives access to a collection of IServiceQueryResultItem.
1030 Each one provides information requested, as indicated by the ItemType and the actual
1031 value of the information. In some cases, the returned item is itself a
1032 collection of IServiceQueryResultSubItem.
1033
1034 The IServiceQueryResultItem items, and the associated symbolic codes and parameter values may be
1035 found in the Interbase 6.0 API Guide.
1036 }
1037
1038 IServiceQueryResultSubItem = interface
1039 ['{8a4c381e-9923-4cc9-a96b-553729248640}']
1040 function getItemType: byte;
1041 function getSize: integer;
1042 procedure getRawBytes(var Buffer);
1043 function getAsString: AnsiString;
1044 function getAsInteger: integer;
1045 function getAsByte: byte;
1046 function CopyTo(stream: TStream; count: integer): integer;
1047 property AsString: AnsiString read getAsString;
1048 property AsInteger: integer read getAsInteger;
1049 property AsByte: byte read getAsByte;
1050 end;
1051
1052 IServiceQueryResultItem = interface(IServiceQueryResultSubItem)
1053 ['{b2806886-206c-4024-8df9-5fe0a7630a5e}']
1054 function getCount: integer;
1055 function getItem(index: integer): IServiceQueryResultSubItem;
1056 function find(ItemType: byte): IServiceQueryResultSubItem;
1057 property Items[index: integer]: IServiceQueryResultSubItem read getItem; default;
1058 property Count: integer read getCount;
1059 end;
1060
1061 IServiceQueryResults = interface
1062 ['{8fbbef7d-fe03-4409-828a-a787d34ef531}']
1063 function getCount: integer;
1064 function getItem(index: integer): IServiceQueryResultItem;
1065 function find(ItemType: byte): IServiceQueryResultItem;
1066 procedure PrintBuf; {can be used to print buffer in hex for debugging}
1067 property Items[index: integer]: IServiceQueryResultItem read getItem; default;
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.
1076
1077 The interface is returned by the FirebirdAPI GetService Manager method.
1078 }
1079
1080 { IServiceManager }
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 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.
1111
1112 This is the base interface and is used to create/open a database connection, to
1113 start a transaction on multiple databases and the access the service manager.
1114
1115 The interface is returned by the FirebirdAPI function.
1116 }
1117
1118 IFirebirdAPI = interface
1119 ['{edeee691-c8d3-4dcf-a780-cd7e432821d5}']
1120 {Database connections}
1121 function AllocateDPB: IDPB;
1122 function OpenDatabase(DatabaseName: AnsiString; DPB: IDPB; RaiseExceptionOnConnectError: boolean=true): IAttachment;
1123 function CreateDatabase(DatabaseName: AnsiString; DPB: IDPB; RaiseExceptionOnError: boolean=true): IAttachment; overload;
1124 function CreateDatabase(sql: AnsiString; aSQLDialect: integer; RaiseExceptionOnError: boolean=true): IAttachment; overload;
1125
1126 {Start Transaction against multiple databases}
1127 function AllocateTPB: ITPB;
1128 function StartTransaction(Attachments: array of IAttachment;
1129 TPB: array of byte; DefaultCompletion: TTransactionCompletion=taCommit): ITransaction; overload;
1130 function StartTransaction(Attachments: array of IAttachment;
1131 TPB: ITPB; DefaultCompletion: TTransactionCompletion=taCommit): ITransaction; overload;
1132
1133 {Service Manager}
1134 function HasServiceAPI: boolean;
1135 function AllocateSPB: ISPB;
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;
1141 function HasRollbackRetaining: boolean;
1142 function IsEmbeddedServer: boolean;
1143 function GetImplementationVersion: AnsiString;
1144
1145 {Firebird 3 API}
1146 function HasMasterIntf: boolean;
1147 function GetIMaster: TObject;
1148 function GetFBLibrary: IFirebirdLibrary;
1149 end;
1150
1151 type
1152 TOnGetLibraryName = procedure(var libname: string);
1153
1154 const
1155 OnGetLibraryName: TOnGetLibraryName = nil;
1156 AllowUseOfFBLIB: boolean = false;
1157
1158 type
1159 { EIBError }
1160
1161 EIBError = class(EDatabaseError)
1162 private
1163 FSQLCode: Long;
1164 public
1165 constructor Create(ASQLCode: Long; Msg: AnsiString);
1166 property SQLCode: Long read FSQLCode;
1167 end;
1168
1169 { EIBInterBaseError - Firebird Engine errors}
1170
1171 EIBInterBaseError = class(EIBError)
1172 private
1173 FIBErrorCode: Long;
1174 public
1175 constructor Create(Status: IStatus); overload;
1176 constructor Create(ASQLCode: Long; AIBErrorCode: Long; Msg: AnsiString); overload;
1177 property IBErrorCode: Long read FIBErrorCode;
1178 end;
1179
1180 {IB Client Exceptions}
1181 EIBClientError = class(EIBError);
1182
1183 {IBError is used internally and by IBX to throw an EIBClientError}
1184
1185 procedure IBError(ErrMess: TIBClientError; const Args: array of const);
1186
1187 {The Firebird API function is used to access the IFirebirdAPI interface.
1188
1189 It will load the Firebird Client Library if this is not already loaded and
1190 select an implementation of the Firebird API (legacy 2.5 or 3.0.
1191 }
1192
1193 function FirebirdAPI: IFirebirdAPI;
1194
1195 {IBX support functions. Probably best ignored i.e. always used the FirebirdAPI
1196 functino to load the library and check if it's loaded.}
1197
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 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 FDefaultFBLibrary = nil then
1246 CheckIBLoaded;
1247 Result := FDefaultFBLibrary.GetFirebirdAPI;
1248 end;
1249
1250 function TryIBLoad: Boolean;
1251 var fblib: IFirebirdLibrary;
1252 begin
1253 Result := FDefaultFBLibrary <> nil;
1254 try
1255 if not Result then
1256 begin
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);
1264 Result := false;
1265 end;
1266 end;
1267
1268 procedure CheckIBLoaded;
1269 begin
1270 if not TryIBLoad then
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);
1294 begin
1295 inherited Create(Msg);
1296 FSQLCode := ASQLCode;
1297 end;
1298
1299 { EIBInterBaseError }
1300
1301 constructor EIBInterBaseError.Create(Status: IStatus);
1302 begin
1303 inherited Create(Status.Getsqlcode,Status.GetMessage);
1304 FIBErrorCode := Status.GetIBErrorCode;
1305 end;
1306
1307 constructor EIBInterBaseError.Create(ASQLCode: Long; AIBErrorCode: Long;
1308 Msg: AnsiString);
1309 begin
1310 inherited Create(ASQLCode,Msg);
1311 FIBErrorCode := AIBErrorCode;
1312 end;
1313
1314 procedure IBError(ErrMess: TIBClientError; const Args: array of const);
1315 begin
1316 raise EIBClientError.Create(Ord(ErrMess),
1317 Format(GetErrorMessage(ErrMess), Args));
1318 end;
1319
1320 initialization
1321 FDefaultFBLibrary := nil;
1322
1323 finalization
1324 FDefaultFBLibrary := nil;
1325
1326 end.
1327