ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/fbintf/IB.pas
Revision: 266
Committed: Wed Dec 26 18:34:32 2018 UTC (5 years, 10 months ago) by tony
Content type: text/x-pascal
File size: 52219 byte(s)
Log Message:
Fixes Merged

File Contents

# User Rev Content
1 tony 45 (*
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 tony 56 {$IFDEF MSWINDOWS}
64     {$DEFINE WINDOWS}
65     {$ENDIF}
66 tony 45
67     {$IFDEF FPC}
68 tony 56 {$mode delphi}
69 tony 45 {$codepage UTF8}
70     {$interfaces COM}
71 tony 56 {$IF defined(FPC) and (FPC_FULLVERSION < 30000) }
72 tony 45 {$ERROR FPC Version 3.0.0 or later is required}
73 tony 56 {$IFEND}
74 tony 45 {$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 tony 56 6. FPC and Delphi Support.
110    
111 tony 45 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 tony 263 Classes,
126     {$IFDEF WINDOWS}Windows, {$ENDIF}
127     {$IFDEF FPC} Dynlibs, {$ENDIF}
128     SysUtils, DB, FBMessages, IBExternals;
129 tony 45
130 tony 47 const
131     {Interface version information}
132     FBIntf_Major = 1;
133 tony 154 FBIntf_Minor = 1;
134 tony 266 FBIntf_Release = 4;
135     FBIntf_Version = '1.1.4';
136 tony 47
137 tony 45 {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 tony 56 {$I 'include/consts_pub.inc'}
141     {$I 'include/inf_pub.inc'}
142     {$I 'include/configkeys.inc'}
143 tony 45
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 tony 56 {$IFNDEF FPC}
179 tony 263 {Delphi missing definitions}
180     type
181     TLibHandle = THandle;
182    
183     const
184     NilHandle = 0;
185     DirectorySeparator = '\';
186    
187 tony 56 {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 tony 45 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 tony 263 IFirebirdAPI = interface;
215 tony 45 IAttachment = interface;
216     ITransaction = interface;
217    
218 tony 56 {The IParameterBlock interface provides the template for all parameter
219 tony 45 block interfaces}
220    
221 tony 56 IParameterBlock<_IItem> = interface
222 tony 45 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 tony 56 ['{53b23f7b-abda-46a5-9aa5-07bd5e723266}']
236 tony 45 function getParamType: byte;
237     function getAsInteger: integer;
238 tony 56 function getAsString: AnsiString;
239 tony 45 function getAsByte: byte;
240 tony 56 procedure setAsString(aValue: AnsiString);
241 tony 45 procedure setAsByte(aValue: byte);
242     procedure SetAsInteger(aValue: integer);
243 tony 56 property AsString: AnsiString read getAsString write setAsString;
244 tony 45 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 tony 56 ['{34167722-af38-4831-b08a-93162d58ede3}']
258 tony 45 function GetIBErrorCode: Long;
259     function Getsqlcode: Long;
260 tony 56 function GetMessage: AnsiString;
261 tony 45 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 tony 56 ['{7dd0aea4-59af-4c2a-b958-565d5025c489}']
278 tony 45 function GetSQLType: cardinal;
279 tony 56 function GetSQLTypeName: AnsiString;
280 tony 45 function GetScale: integer;
281     function GetSize: cardinal;
282     function GetCharSetID: cardinal;
283 tony 56 function GetTableName: AnsiString;
284     function GetColumnName: AnsiString;
285 tony 45 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 tony 56 ['{631c6bb1-fb49-44fb-a64a-c49859632b88}']
310 tony 45 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 tony 56 function GetAsString(index: array of integer): AnsiString;
326 tony 45 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 tony 56 procedure SetAsString(index: array of integer; Value: AnsiString);
339 tony 45 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 tony 56 ['{575f3c61-bb33-46a5-8975-bb7d1b6e37cc}']
353 tony 45 function GetSubType: integer;
354     function GetCharSetID: cardinal;
355     function GetCodePage: TSystemCodePage;
356     function GetSegmentSize: cardinal;
357 tony 56 function GetRelationName: AnsiString;
358     function GetColumnName: AnsiString;
359 tony 45 end;
360    
361     {The Blob Parameter block is used to select a Blob Filter}
362    
363 tony 56 IBPBItem = interface (IParameterBlockItem)
364     ['{660822a5-3114-4c16-b6cb-c1a7b2aba70d}']
365     end;
366 tony 45
367 tony 87 IBPB = interface (IParameterBlock<IBPBItem>)
368 tony 56 ['{e0cb9eb5-17f7-4416-b7d1-3cddd1dfca76}']
369     end;
370 tony 45
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 tony 56 ['{3090a145-7780-442b-b15b-efd4568b8611}']
384 tony 45 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 tony 56 function LoadFromFile(Filename: AnsiString): IBlob;
395 tony 45 function LoadFromStream(S: TStream) : IBlob;
396 tony 56 function SaveToFile(Filename: AnsiString): IBlob;
397 tony 45 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 tony 56 ['{c222e6c3-53c1-469f-9e05-0a5c3ef232d8}']
414 tony 45 function GetIndex: integer;
415     function GetSQLType: cardinal;
416 tony 56 function GetSQLTypeName: AnsiString;
417 tony 45 function getSubtype: integer;
418 tony 56 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 tony 45 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 tony 56 property Name: AnsiString read GetName;
431 tony 45 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 tony 56 ['{4dafdbb6-0d36-4f1f-9c95-8b132804b965}']
447 tony 45 function getCount: integer;
448     function getColumnMetaData(index: integer): IColumnMetaData;
449 tony 56 function GetUniqueRelationName: AnsiString; {Non empty if all columns come from the same table}
450     function ByName(Idx: AnsiString): IColumnMetaData;
451 tony 45 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 tony 56 ['{3f493e31-7e3f-4606-a07c-b210b9e3619d}']
471 tony 45 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 tony 56 function GetAsString: AnsiString;
482 tony 45 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 tony 56 property AsString: AnsiString read GetAsString;
501 tony 45 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 tony 56 ['{e836b2bb-93d1-4bbf-a8eb-7ce535de3bb5}']
516 tony 45 function getCount: integer;
517     function GetTransaction: ITransaction;
518 tony 56 function ByName(Idx: AnsiString): ISQLData;
519 tony 45 function getSQLData(index: integer): ISQLData;
520 tony 56 procedure GetData(index: integer; var IsNull:boolean; var len: short; var data: PByte);
521 tony 45 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 tony 56 ['{0ae4979b-7857-4e8c-8918-ec6f155b51a0}']
533 tony 45 function FetchNext: boolean;
534 tony 56 function GetCursorName: AnsiString;
535 tony 45 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 tony 56 ['{b22b4578-6d41-4807-a9a9-d2ec8d1d5a14}']
556 tony 45 function GetIndex: integer;
557     function GetSQLType: cardinal;
558 tony 56 function GetSQLTypeName: AnsiString;
559 tony 45 function getSubtype: integer;
560 tony 56 function getName: AnsiString;
561 tony 45 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 tony 56 function GetAsString: AnsiString;
577 tony 45 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 tony 56 procedure SetAsString(aValue: AnsiString);
595 tony 45 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 tony 56 property AsString: AnsiString read GetAsString write SetAsString;
614 tony 45 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 tony 56 property Name: AnsiString read GetName;
623 tony 45 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 tony 56 ['{c6d95ac7-b2b7-461b-b890-afef0acbb077}']
633 tony 45 function getCount: integer;
634     function getSQLParam(index: integer): ISQLParam;
635 tony 56 function ByName(Idx: AnsiString): ISQLParam ;
636 tony 45 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 tony 47
643     TPerfStats = (psCurrentMemory, psMaxMemory,
644     psRealTime, psUserTime, psBuffers,
645     psReads, psWrites, psFetches,psDeltaMemory);
646    
647 tony 209 TPerfCounters = array[TPerfStats] of Int64;
648 tony 47
649 tony 45 {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 tony 56 ['{a260576d-a07d-4a66-b02d-1b72543fd7cf}']
655 tony 45 function GetMetaData: IMetaData; {Output Metadata}
656     function GetSQLParams: ISQLParams;{Statement Parameters}
657 tony 56 function GetPlan: AnsiString;
658 tony 45 function GetRowsAffected(var SelectCount, InsertCount, UpdateCount, DeleteCount: integer): boolean;
659     function GetSQLStatementType: TIBSQLStatementTypes;
660 tony 56 function GetSQLText: AnsiString;
661 tony 263 function GetProcessedSQLText: AnsiString;
662 tony 45 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 tony 47 procedure EnableStatistics(aValue: boolean);
671     function GetPerfStatistics(var stats: TPerfCounters): boolean;
672 tony 45 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 tony 56 ITPBItem = interface(IParameterBlockItem)
689     ['{544c1f2b-7c12-4a87-a4a5-face7ea72671}']
690     end;
691 tony 45
692 tony 56 ITPB = interface(IParameterBlock<ITPBItem>)
693     ['{7369b0ff-defe-437b-81fe-19b211d42d25}']
694     end;
695 tony 45
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 tony 56 ['{30928d0e-a9d7-4c61-b7cf-14f4f38abe2a}']
709 tony 45 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 tony 56 EventName: AnsiString;
737 tony 45 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 tony 56 ['{6a0be233-ed08-4524-889c-2e45d0c20e5f}']
748 tony 45 procedure GetEvents(EventNames: TStrings);
749     procedure SetEvents(EventNames: TStrings); overload;
750 tony 56 procedure SetEvents(EventName: AnsiString); overload;
751 tony 45 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 tony 56 ['{eeb97b51-ec0f-473f-9f75-c1721f055fcb}']
782 tony 45 function getItemType: byte;
783     function getSize: integer;
784     procedure getRawBytes(var Buffer);
785 tony 56 function getAsString: AnsiString;
786 tony 45 function getAsInteger: integer;
787 tony 56 procedure DecodeIDCluster(var ConnectionType: integer; var DBFileName, DBSiteName: AnsiString);
788 tony 45 function getAsBytes: TByteArray;
789 tony 143 function getAsDateTime: TDateTime;
790 tony 56 procedure DecodeVersionString(var Version: byte; var VersionString: AnsiString);
791 tony 45 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 tony 56 property AsString: AnsiString read GetAsString;
800 tony 45 property Count: integer read GetCount;
801     property Items[index: integer]: IDBInfoItem read getItem; default;
802     end;
803    
804     { IDBInformation }
805    
806     IDBInformation = interface
807 tony 56 ['{7ac6777f-f0a9-498a-9f5c-4a57a554df81}']
808 tony 45 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 tony 143 {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 tony 45 {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 tony 56 IDPBItem = interface(IParameterBlockItem)
842     ['{123d4ad0-087a-4cd1-a344-1b3d03b30673}']
843     end;
844 tony 45
845 tony 56 IDPB = interface(IParameterBlock<IDPBItem>)
846     ['{e676067b-1cf4-4eba-9256-9724f57e0d16}']
847     end;
848 tony 45
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 tony 56 ['{466e9b67-9def-4807-b3e7-e08a35e7185c}']
878 tony 263 function getFirebirdAPI: IFirebirdAPI;
879 tony 45 function getDPB: IDPB;
880     function AllocateBPB: IBPB;
881 tony 143 function AllocateDIRB: IDIRB;
882 tony 45 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 tony 56 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 tony 45 params: array of const): IResultSet; overload;
899 tony 56 function OpenCursor(transaction: ITransaction; sql: AnsiString): IResultSet; overload;
900     function OpenCursor(transaction: ITransaction; sql: AnsiString;
901 tony 45 params: array of const): IResultSet; overload;
902 tony 56 function OpenCursorAtStart(transaction: ITransaction; sql: AnsiString; aSQLDialect: integer): IResultSet; overload;
903     function OpenCursorAtStart(transaction: ITransaction; sql: AnsiString; aSQLDialect: integer;
904 tony 45 params: array of const): IResultSet; overload;
905 tony 56 function OpenCursorAtStart(transaction: ITransaction; sql: AnsiString): IResultSet; overload;
906     function OpenCursorAtStart(transaction: ITransaction; sql: AnsiString;
907 tony 45 params: array of const): IResultSet; overload;
908 tony 56 function OpenCursorAtStart(sql: AnsiString): IResultSet; overload;
909     function OpenCursorAtStart(sql: AnsiString;
910 tony 45 params: array of const): IResultSet; overload;
911 tony 56 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 tony 45 aSQLDialect: integer; GenerateParamNames: boolean=false): IStatement; overload;
915 tony 56 function PrepareWithNamedParameters(transaction: ITransaction; sql: AnsiString;
916 tony 45 GenerateParamNames: boolean=false): IStatement; overload;
917    
918     {Events}
919     function GetEventHandler(Events: TStrings): IEvents; overload;
920 tony 56 function GetEventHandler(Event: AnsiString): IEvents; overload;
921 tony 45
922     {Blob - may use to open existing Blobs. However, ISQLData.AsBlob is preferred}
923    
924 tony 56 function CreateBlob(transaction: ITransaction; RelationName, ColumnName: AnsiString; BPB: IBPB=nil): IBlob; overload;
925 tony 45 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 tony 56 function OpenBlob(transaction: ITransaction; RelationName, ColumnName: AnsiString; BlobID: TISC_QUAD; BPB: IBPB=nil): IBlob;
928 tony 45
929     {Array - may use to open existing arrays. However, ISQLData.AsArray is preferred}
930    
931 tony 56 function OpenArray(transaction: ITransaction; RelationName, ColumnName: AnsiString; ArrayID: TISC_QUAD): IArray;
932     function CreateArray(transaction: ITransaction; RelationName, ColumnName: AnsiString): IArray; overload;
933 tony 45 function CreateArray(transaction: ITransaction; ArrayMetaData: IArrayMetaData): IArray; overload;
934 tony 56 function CreateArrayMetaData(SQLType: cardinal; tableName: AnsiString; columnName: AnsiString;
935 tony 47 Scale: integer; size: cardinal; charSetID: cardinal; dimensions: cardinal;
936     bounds: TArrayBounds): IArrayMetaData;
937 tony 45
938     {Database Information}
939     function GetSQLDialect: integer;
940 tony 56 function GetBlobMetaData(Transaction: ITransaction; tableName, columnName: AnsiString): IBlobMetaData;
941     function GetArrayMetaData(Transaction: ITransaction; tableName, columnName: AnsiString): IArrayMetaData;
942 tony 45 function GetDBInformation(Requests: array of byte): IDBInformation; overload;
943     function GetDBInformation(Request: byte): IDBInformation; overload;
944 tony 143 function GetDBInformation(Requests: IDIRB): IDBInformation; overload;
945 tony 117 function GetConnectString: AnsiString;
946     function GetRemoteProtocol: AnsiString;
947 tony 143 function GetAuthenticationMethod: AnsiString;
948 tony 209 function GetSecurityDatabase: AnsiString;
949 tony 117 function GetODSMajorVersion: integer;
950     function GetODSMinorVersion: integer;
951 tony 266 procedure getFBVersion(version: TStrings);
952 tony 45 function HasActivity: boolean;
953 tony 60
954     {Character Sets}
955 tony 109 function HasDefaultCharSet: boolean;
956     function GetDefaultCharSetID: integer;
957 tony 60 function GetCharsetName(CharSetID: integer): AnsiString;
958     function CharSetID2CodePage(CharSetID: integer; var CodePage: TSystemCodePage): boolean;
959     function CodePage2CharSetID(CodePage: TSystemCodePage; var CharSetID: integer): boolean;
960     function CharSetName2CharSetID(CharSetName: AnsiString; var CharSetID: integer): boolean;
961     function CharSetWidth(CharSetID: integer; var Width: integer): boolean;
962     procedure RegisterCharSet(CharSetName: AnsiString; CodePage: TSystemCodePage;
963     AllowReverseLookup:boolean; out CharSetID: integer);
964 tony 45 end;
965    
966 tony 231 TProtocolAll = (TCP, SPX, NamedPipe, Local, inet, inet4, inet6, wnet, xnet, unknownProtocol);
967 tony 143 TProtocol = TCP..xnet;
968 tony 45
969     {Service Parameter Block (SPB).
970    
971     The SPB provides the parameters used when connecting to a Service Manager. It is
972     allocated empty by the FirebirdAPI and the parameters are then added to it. Each
973     individual parameter may be accessed by the ISPBItem interface which can be used
974     to set the value, if any, of the parameter.
975    
976     The SPB parameters, and the associated symbolic codes and parameter values may be
977     found in the Interbase 6.0 API Guide.
978    
979     }
980    
981 tony 56 ISPBItem = interface(IParameterBlockItem)
982     ['{5d08ae2b-4519-41bd-8b40-97cd451c3f6a}']
983     end;
984 tony 45
985 tony 56 ISPB = interface(IParameterBlock<ISPBItem>)
986     ['{2c5836fd-41ed-4426-9b7d-5af580ec2659}']
987     end;
988 tony 45
989     {Service Query Parameter Block (SQPB).
990    
991     This is a specialised parameter block used to send data to a service manager
992     in a Query Request.
993     }
994    
995     ISQPBItem = interface(IParameterBlockItem)
996 tony 56 ['{b07841a6-33b3-47f0-b5a2-028cbc86dc97}']
997 tony 45 function CopyFrom(source: TStream; count: integer): integer;
998     end;
999    
1000 tony 56 ISQPB = interface(IParameterBlock<ISQPBItem>)
1001     ['{8553e66b-ee62-498b-8431-dff030211447}']
1002     end;
1003 tony 45
1004     {Service Request Block (SRB).
1005    
1006     The SRB specifies what is requested from the Service Manager when starting a
1007     service or querying a service. It is allocated empty by the ServiceManager API and
1008     the parameters are then added to it. Each individual parameter may be accessed
1009     by the ISRBItem interface which can be used to set the value, if any, of the parameter.
1010    
1011     The SRB parameters, and the associated symbolic codes and parameter values may be
1012     found in the Interbase 6.0 API Guide.
1013    
1014     }
1015    
1016 tony 56 ISRBItem = interface(IParameterBlockItem)
1017     ['{47ec790e-f265-4b30-9dcd-261e51677245}']
1018     end;
1019 tony 45
1020 tony 56 ISRB = interface(IParameterBlock<ISRBItem>)
1021     ['{9f2e204f-3c33-4e44-90f9-9135e95dafb9}']
1022     end;
1023 tony 45
1024     {The Service Query Results Interface.
1025    
1026     An IServiceQueryResults interface is returned by the IServiceManager Query
1027     method. The interface provides access to the information requested and
1028     returned by the method.
1029    
1030     IServiceQueryResults itself gives access to a collection of IServiceQueryResultItem.
1031     Each one provides information requested, as indicated by the ItemType and the actual
1032     value of the information. In some cases, the returned item is itself a
1033     collection of IServiceQueryResultSubItem.
1034    
1035     The IServiceQueryResultItem items, and the associated symbolic codes and parameter values may be
1036     found in the Interbase 6.0 API Guide.
1037     }
1038    
1039     IServiceQueryResultSubItem = interface
1040 tony 56 ['{8a4c381e-9923-4cc9-a96b-553729248640}']
1041 tony 45 function getItemType: byte;
1042     function getSize: integer;
1043     procedure getRawBytes(var Buffer);
1044 tony 56 function getAsString: AnsiString;
1045 tony 45 function getAsInteger: integer;
1046     function getAsByte: byte;
1047     function CopyTo(stream: TStream; count: integer): integer;
1048 tony 56 property AsString: AnsiString read getAsString;
1049 tony 45 property AsInteger: integer read getAsInteger;
1050     property AsByte: byte read getAsByte;
1051     end;
1052    
1053     IServiceQueryResultItem = interface(IServiceQueryResultSubItem)
1054 tony 56 ['{b2806886-206c-4024-8df9-5fe0a7630a5e}']
1055 tony 45 function getCount: integer;
1056     function getItem(index: integer): IServiceQueryResultSubItem;
1057     function find(ItemType: byte): IServiceQueryResultSubItem;
1058     property Items[index: integer]: IServiceQueryResultSubItem read getItem; default;
1059     property Count: integer read getCount;
1060     end;
1061    
1062     IServiceQueryResults = interface
1063 tony 56 ['{8fbbef7d-fe03-4409-828a-a787d34ef531}']
1064 tony 45 function getCount: integer;
1065     function getItem(index: integer): IServiceQueryResultItem;
1066     function find(ItemType: byte): IServiceQueryResultItem;
1067     procedure PrintBuf; {can be used to print buffer in hex for debugging}
1068     property Items[index: integer]: IServiceQueryResultItem read getItem; default;
1069     property Count: integer read getCount;
1070     end;
1071    
1072 tony 263 IFirebirdLibrary = interface;
1073    
1074 tony 45 {The IServiceManager interface provides access to a service manager. It can
1075     used to Detach and re-attach to Service Manager, to start services and to
1076     query the service manager.
1077    
1078     The interface is returned by the FirebirdAPI GetService Manager method.
1079     }
1080    
1081     { IServiceManager }
1082    
1083     IServiceManager = interface
1084 tony 56 ['{905b587d-1e1f-4e40-a3f8-a3519f852e48}']
1085 tony 263 function getFirebirdAPI: IFirebirdAPI;
1086 tony 45 function getSPB: ISPB;
1087 tony 56 function getServerName: AnsiString;
1088 tony 209 function getProtocol: TProtocol;
1089     function getPortNo: AnsiString;
1090 tony 45 procedure Attach;
1091     procedure Detach(Force: boolean=false);
1092     function IsAttached: boolean;
1093     function AllocateSRB: ISRB;
1094     function AllocateSQPB: ISQPB;
1095 tony 209 function Start(Request: ISRB; RaiseExceptionOnError: boolean=true): boolean;
1096     function Query(SQPB: ISQPB; Request: ISRB; RaiseExceptionOnError: boolean=true) :IServiceQueryResults; overload;
1097     function Query(Request: ISRB; RaiseExceptionOnError: boolean=true) :IServiceQueryResults; overload;
1098 tony 45 end;
1099    
1100 tony 263 {Tbe Firebird Library API used to get information about the Firebird library}
1101    
1102    
1103     IFirebirdLibrary = interface
1104     ['{3c04e0a1-12e0-428a-b2e1-bc6fcd97b79b}']
1105     function GetHandle: TLibHandle;
1106     function GetLibraryName: string;
1107     function GetLibraryFilePath: string;
1108     function GetFirebirdAPI: IFirebirdAPI;
1109     end;
1110    
1111 tony 45 {The Firebird API.
1112    
1113     This is the base interface and is used to create/open a database connection, to
1114     start a transaction on multiple databases and the access the service manager.
1115    
1116     The interface is returned by the FirebirdAPI function.
1117     }
1118    
1119     IFirebirdAPI = interface
1120 tony 56 ['{edeee691-c8d3-4dcf-a780-cd7e432821d5}']
1121 tony 45 {Database connections}
1122     function AllocateDPB: IDPB;
1123 tony 56 function OpenDatabase(DatabaseName: AnsiString; DPB: IDPB; RaiseExceptionOnConnectError: boolean=true): IAttachment;
1124     function CreateDatabase(DatabaseName: AnsiString; DPB: IDPB; RaiseExceptionOnError: boolean=true): IAttachment; overload;
1125     function CreateDatabase(sql: AnsiString; aSQLDialect: integer; RaiseExceptionOnError: boolean=true): IAttachment; overload;
1126 tony 45
1127     {Start Transaction against multiple databases}
1128     function AllocateTPB: ITPB;
1129     function StartTransaction(Attachments: array of IAttachment;
1130     TPB: array of byte; DefaultCompletion: TTransactionCompletion=taCommit): ITransaction; overload;
1131     function StartTransaction(Attachments: array of IAttachment;
1132     TPB: ITPB; DefaultCompletion: TTransactionCompletion=taCommit): ITransaction; overload;
1133    
1134     {Service Manager}
1135     function HasServiceAPI: boolean;
1136     function AllocateSPB: ISPB;
1137 tony 143 function GetServiceManager(ServerName: AnsiString; Protocol: TProtocol; SPB: ISPB): IServiceManager; overload;
1138     function GetServiceManager(ServerName: AnsiString; Port: AnsiString; Protocol: TProtocol; SPB: ISPB): IServiceManager; overload;
1139 tony 45
1140     {Information}
1141     function GetStatus: IStatus;
1142     function HasRollbackRetaining: boolean;
1143     function IsEmbeddedServer: boolean;
1144 tony 56 function GetImplementationVersion: AnsiString;
1145 tony 45
1146     {Firebird 3 API}
1147     function HasMasterIntf: boolean;
1148     function GetIMaster: TObject;
1149 tony 263 function GetFBLibrary: IFirebirdLibrary;
1150 tony 45 end;
1151    
1152     type
1153     TOnGetLibraryName = procedure(var libname: string);
1154    
1155     const
1156     OnGetLibraryName: TOnGetLibraryName = nil;
1157     AllowUseOfFBLIB: boolean = false;
1158    
1159     type
1160     { EIBError }
1161    
1162     EIBError = class(EDatabaseError)
1163     private
1164     FSQLCode: Long;
1165     public
1166 tony 56 constructor Create(ASQLCode: Long; Msg: AnsiString);
1167 tony 45 property SQLCode: Long read FSQLCode;
1168     end;
1169    
1170     { EIBInterBaseError - Firebird Engine errors}
1171    
1172     EIBInterBaseError = class(EIBError)
1173     private
1174     FIBErrorCode: Long;
1175     public
1176     constructor Create(Status: IStatus); overload;
1177 tony 56 constructor Create(ASQLCode: Long; AIBErrorCode: Long; Msg: AnsiString); overload;
1178 tony 45 property IBErrorCode: Long read FIBErrorCode;
1179     end;
1180    
1181     {IB Client Exceptions}
1182     EIBClientError = class(EIBError);
1183    
1184     {IBError is used internally and by IBX to throw an EIBClientError}
1185    
1186     procedure IBError(ErrMess: TIBClientError; const Args: array of const);
1187    
1188     {The Firebird API function is used to access the IFirebirdAPI interface.
1189    
1190     It will load the Firebird Client Library if this is not already loaded and
1191     select an implementation of the Firebird API (legacy 2.5 or 3.0.
1192     }
1193    
1194     function FirebirdAPI: IFirebirdAPI;
1195    
1196     {IBX support functions. Probably best ignored i.e. always used the FirebirdAPI
1197     functino to load the library and check if it's loaded.}
1198    
1199     function TryIBLoad: Boolean;
1200     procedure CheckIBLoaded;
1201    
1202 tony 263 {If you want to explicitly load the Firebird library from a
1203     non-default location then use this function and its GetFirebirdAPI function
1204     to get the API.}
1205    
1206     function LoadFBLibrary(aLibPathName: string): IFirebirdLibrary;
1207    
1208 tony 45 implementation
1209    
1210     uses FBClientAPI
1211     {$IFDEF USELEGACYFIREBIRDAPI}, FB25ClientAPI {$ENDIF}
1212     {$IFDEF USEFIREBIRD3API}, FB30ClientAPI {$ENDIF};
1213    
1214 tony 263 var FDefaultFBLibrary: IFirebirdLibrary;
1215 tony 45
1216 tony 263 type
1217    
1218     { TFBLibrary }
1219    
1220     TFBLibraryImpl = class(TFBLibrary)
1221     protected
1222     function GetFirebird3API: IFirebirdAPI; override;
1223     function GetLegacyFirebirdAPI: IFirebirdAPI; override;
1224     end;
1225    
1226     function TFBLibraryImpl.GetFirebird3API: IFirebirdAPI;
1227     begin
1228     {$IFDEF USEFIREBIRD3API}
1229     Result := TFB30ClientAPI.Create(self);
1230     {$ELSE}
1231     Result := nil;
1232     {$ENDIF}
1233     end;
1234    
1235     function TFBLibraryImpl.GetLegacyFirebirdAPI: IFirebirdAPI;
1236     begin
1237     {$IFDEF USELEGACYFIREBIRDAPI}
1238     Result := TFB25ClientAPI.Create(self);
1239     {$ELSE}
1240     Result := nil;
1241     {$ENDIF}
1242     end;
1243    
1244 tony 45 function FirebirdAPI: IFirebirdAPI;
1245     begin
1246 tony 263 if FDefaultFBLibrary = nil then
1247 tony 45 CheckIBLoaded;
1248 tony 263 Result := FDefaultFBLibrary.GetFirebirdAPI;
1249 tony 45 end;
1250    
1251     function TryIBLoad: Boolean;
1252 tony 263 var fblib: IFirebirdLibrary;
1253 tony 45 begin
1254 tony 263 Result := FDefaultFBLibrary <> nil;
1255 tony 45 try
1256     if not Result then
1257     begin
1258 tony 263 fblib := TFBLibraryImpl.Create;
1259     if (fblib <> nil) and (fblib.GetFirebirdAPI <> nil) then
1260     FDefaultFBLibrary := fblib;
1261     Result := FDefaultFBLibrary <> nil;
1262 tony 45 end;
1263     except
1264     SysUtils.showexception(ExceptObject,ExceptAddr);
1265     Result := false;
1266     end;
1267     end;
1268    
1269     procedure CheckIBLoaded;
1270     begin
1271     if not TryIBLoad then
1272     IBError(ibxeInterBaseMissing, [nil]);
1273     end;
1274    
1275 tony 263 function LoadFBLibrary(aLibPathName: string): IFirebirdLibrary;
1276     var fblib: IFirebirdLibrary;
1277     begin
1278     if trim(aLibPathName) = '' then
1279     begin
1280     CheckIBLoaded;
1281     Result := FDefaultFBLibrary;
1282     end
1283     else
1284     begin
1285     fblib := TFBLibraryImpl.GetFBLibrary(aLibPathName);
1286     if (fblib = nil) or (fblib.GetFirebirdAPI = nil) then
1287     IBError(ibxeInterBaseMissing, [nil]);
1288     Result := fblib;
1289     end;
1290     end;
1291    
1292 tony 45 { EIBError }
1293    
1294 tony 56 constructor EIBError.Create(ASQLCode: Long; Msg: AnsiString);
1295 tony 45 begin
1296     inherited Create(Msg);
1297     FSQLCode := ASQLCode;
1298     end;
1299    
1300     { EIBInterBaseError }
1301    
1302     constructor EIBInterBaseError.Create(Status: IStatus);
1303     begin
1304     inherited Create(Status.Getsqlcode,Status.GetMessage);
1305     FIBErrorCode := Status.GetIBErrorCode;
1306     end;
1307    
1308     constructor EIBInterBaseError.Create(ASQLCode: Long; AIBErrorCode: Long;
1309 tony 56 Msg: AnsiString);
1310 tony 45 begin
1311     inherited Create(ASQLCode,Msg);
1312     FIBErrorCode := AIBErrorCode;
1313     end;
1314    
1315     procedure IBError(ErrMess: TIBClientError; const Args: array of const);
1316     begin
1317     raise EIBClientError.Create(Ord(ErrMess),
1318     Format(GetErrorMessage(ErrMess), Args));
1319     end;
1320    
1321     initialization
1322 tony 263 FDefaultFBLibrary := nil;
1323 tony 45
1324 tony 209 finalization
1325 tony 263 FDefaultFBLibrary := nil;
1326 tony 45
1327     end.
1328