ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/branches/udr/client/IB.pas
Revision: 117
Committed: Mon Jan 22 13:58:11 2018 UTC (6 years, 10 months ago) by tony
Content type: text/x-pascal
Original Path: ibx/trunk/fbintf/IB.pas
File size: 49331 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     Classes, SysUtils, DB, FBMessages, IBExternals;
126    
127 tony 47 const
128     {Interface version information}
129     FBIntf_Major = 1;
130     FBIntf_Minor = 0;
131 tony 56 FBIntf_Release = 2;
132     FBIntf_Version = '1.0.2';
133 tony 47
134 tony 45 {These include files are converted from the 'C' originals in the Firebird API
135     and define the various constants used by the API}
136    
137 tony 56 {$I 'include/consts_pub.inc'}
138     {$I 'include/inf_pub.inc'}
139     {$I 'include/configkeys.inc'}
140 tony 45
141     {The following constants define the values return by calls to the GetSQLType
142     methods provided by several of the interfaces defined below.}
143    
144     (*********************)
145     (** SQL definitions **)
146     (*********************)
147     SQL_VARYING = 448;
148     SQL_TEXT = 452;
149     SQL_DOUBLE = 480;
150     SQL_FLOAT = 482;
151     SQL_LONG = 496;
152     SQL_SHORT = 500;
153     SQL_TIMESTAMP = 510;
154     SQL_BLOB = 520;
155     SQL_D_FLOAT = 530;
156     SQL_ARRAY = 540;
157     SQL_QUAD = 550;
158     SQL_TYPE_TIME = 560;
159     SQL_TYPE_DATE = 570;
160     SQL_INT64 = 580;
161     SQL_BOOLEAN = 32764;
162     SQL_DATE = SQL_TIMESTAMP;
163    
164     type
165     TGDS_QUAD = record
166     gds_quad_high : ISC_LONG;
167     gds_quad_low : UISC_LONG;
168     end;
169     TGDS__QUAD = TGDS_QUAD;
170     TISC_QUAD = TGDS_QUAD;
171     PGDS_QUAD = ^TGDS_QUAD;
172     PGDS__QUAD = ^TGDS__QUAD;
173     PISC_QUAD = ^TISC_QUAD;
174    
175 tony 56 {$IFNDEF FPC}
176     {Delphi only seems to define CP_UTF8 and CP_UTF16}
177     const
178     CP_ACP = 0; // default to ANSI code page
179     CP_OEMCP = 1; // default to OEM (console) code page
180     CP_UTF16BE = 1201; // unicodeFFFE
181     CP_UTF7 = 65000; // utf-7
182     CP_ASCII = 20127; // us-ascii
183     CP_NONE = $FFFF; // rawbytestring encoding
184    
185     {$ENDIF}
186    
187     type
188     {$IF not declared(TSystemCodePage)}
189     TSystemCodePage = word; {not defined in Delphi}
190     {$IFEND}
191    
192 tony 45 TIBSQLStatementTypes =
193     (SQLUnknown, SQLSelect, SQLInsert,
194     SQLUpdate, SQLDelete, SQLDDL,
195     SQLGetSegment, SQLPutSegment,
196     SQLExecProcedure, SQLStartTransaction,
197     SQLCommit, SQLRollback,
198     SQLSelectForUpdate, SQLSetGenerator);
199    
200     TFBStatusCode = cardinal;
201     TByteArray = array of byte;
202    
203     IAttachment = interface;
204     ITransaction = interface;
205    
206 tony 56 {The IParameterBlock interface provides the template for all parameter
207 tony 45 block interfaces}
208    
209 tony 56 IParameterBlock<_IItem> = interface
210 tony 45 function getCount: integer;
211     function Add(ParamType: byte): _IItem;
212     function getItems(index: integer): _IItem;
213     function Find(ParamType: byte): _IItem;
214     procedure PrintBuf; {can be used to print buffer in hex for debugging}
215     property Count: integer read getCount;
216     property Items[index: integer]: _IItem read getItems; default;
217     end;
218    
219     {IParameterBlockItem is not used on its own but instead provides a base type for
220     different parameter block items }
221    
222     IParameterBlockItem = interface
223 tony 56 ['{53b23f7b-abda-46a5-9aa5-07bd5e723266}']
224 tony 45 function getParamType: byte;
225     function getAsInteger: integer;
226 tony 56 function getAsString: AnsiString;
227 tony 45 function getAsByte: byte;
228 tony 56 procedure setAsString(aValue: AnsiString);
229 tony 45 procedure setAsByte(aValue: byte);
230     procedure SetAsInteger(aValue: integer);
231 tony 56 property AsString: AnsiString read getAsString write setAsString;
232 tony 45 property AsByte: byte read getAsByte write setAsByte;
233     property AsInteger: integer read getAsInteger write SetAsInteger;
234     end;
235    
236    
237     {The IStatus interface provides access to error information, if any, returned
238     by the last API call. It can also be used to customise the error message
239     returned by a database engine exception - see EIBInterbaseError.
240    
241     This interface can be accessed from IFirebirdAPI.
242     }
243    
244     IStatus = interface
245 tony 56 ['{34167722-af38-4831-b08a-93162d58ede3}']
246 tony 45 function GetIBErrorCode: Long;
247     function Getsqlcode: Long;
248 tony 56 function GetMessage: AnsiString;
249 tony 45 function CheckStatusVector(ErrorCodes: array of TFBStatusCode): Boolean;
250     function GetIBDataBaseErrorMessages: TIBDataBaseErrorMessages;
251     procedure SetIBDataBaseErrorMessages(Value: TIBDataBaseErrorMessages);
252     end;
253    
254     { The array metadata interface provides access to the metadata used to describe
255     an array column in a Firebird table.
256     }
257    
258     TArrayBound = record
259     UpperBound: short;
260     LowerBound: short;
261     end;
262     TArrayBounds = array of TArrayBound;
263    
264     IArrayMetaData = interface
265 tony 56 ['{7dd0aea4-59af-4c2a-b958-565d5025c489}']
266 tony 45 function GetSQLType: cardinal;
267 tony 56 function GetSQLTypeName: AnsiString;
268 tony 45 function GetScale: integer;
269     function GetSize: cardinal;
270     function GetCharSetID: cardinal;
271 tony 56 function GetTableName: AnsiString;
272     function GetColumnName: AnsiString;
273 tony 45 function GetDimensions: integer;
274     function GetBounds: TArrayBounds;
275     end;
276    
277     {The array interface provides access to and modification of the array data
278     contained in an array field of a Firebird Table. The array element is
279     selected by specifying its co-ordinates using an integer array. The
280     getter and setter methods used should be appropriate for the type of data
281     contained in the array. Automatic conversion is provided to and from strings.
282     That is GetAsString and SetAsString are safe to use for sql types other than
283     boolean.
284    
285     The interface is returned by a GetAsArray getter method (see ISQLData). A new array
286     can be obtained from the IAttachment interface. The SetAsArray setter method
287     (See ISQLParam) is used to apply an updated or new array to the database using
288     an UPDATE or INSERT statement.
289    
290     }
291    
292     TArrayEventReason = (arChanging,arChanged);
293     IArray = interface;
294     TArrayEventHandler = procedure(Sender: IArray; Reason: TArrayEventReason) of object;
295    
296     IArray = interface(IArrayMetaData)
297 tony 56 ['{631c6bb1-fb49-44fb-a64a-c49859632b88}']
298 tony 45 function GetArrayID: TISC_QUAD;
299     procedure Clear;
300     function IsEmpty: boolean;
301     procedure PreLoad;
302     procedure CancelChanges;
303     procedure SaveChanges;
304     function GetAsInteger(index: array of integer): integer;
305     function GetAsBoolean(index: array of integer): boolean;
306     function GetAsCurrency(index: array of integer): Currency;
307     function GetAsInt64(index: array of integer): Int64;
308     function GetAsDateTime(index: array of integer): TDateTime;
309     function GetAsDouble(index: array of integer): Double;
310     function GetAsFloat(index: array of integer): Float;
311     function GetAsLong(index: array of integer): Long;
312     function GetAsShort(index: array of integer): Short;
313 tony 56 function GetAsString(index: array of integer): AnsiString;
314 tony 45 function GetAsVariant(index: array of integer): Variant;
315     procedure SetAsInteger(index: array of integer; AValue: integer);
316     procedure SetAsBoolean(index: array of integer; AValue: boolean);
317     procedure SetAsCurrency(index: array of integer; Value: Currency);
318     procedure SetAsInt64(index: array of integer; Value: Int64);
319     procedure SetAsDate(index: array of integer; Value: TDateTime);
320     procedure SetAsLong(index: array of integer; Value: Long);
321     procedure SetAsTime(index: array of integer; Value: TDateTime);
322     procedure SetAsDateTime(index: array of integer; Value: TDateTime);
323     procedure SetAsDouble(index: array of integer; Value: Double);
324     procedure SetAsFloat(index: array of integer; Value: Float);
325     procedure SetAsShort(index: array of integer; Value: Short);
326 tony 56 procedure SetAsString(index: array of integer; Value: AnsiString);
327 tony 45 procedure SetAsVariant(index: array of integer; Value: Variant);
328     procedure SetBounds(dim, UpperBound, LowerBound: integer);
329     function GetAttachment: IAttachment;
330     function GetTransaction: ITransaction;
331     procedure AddEventHandler(Handler: TArrayEventHandler);
332     procedure RemoveEventHandler(Handler: TArrayEventHandler);
333     end;
334    
335     { The Blob metadata interface provides access to the metadata used to describe
336     a blob column in a Firebird table.
337     }
338    
339     IBlobMetaData = interface
340 tony 56 ['{575f3c61-bb33-46a5-8975-bb7d1b6e37cc}']
341 tony 45 function GetSubType: integer;
342     function GetCharSetID: cardinal;
343     function GetCodePage: TSystemCodePage;
344     function GetSegmentSize: cardinal;
345 tony 56 function GetRelationName: AnsiString;
346     function GetColumnName: AnsiString;
347 tony 45 end;
348    
349     {The Blob Parameter block is used to select a Blob Filter}
350    
351 tony 56 IBPBItem = interface (IParameterBlockItem)
352     ['{660822a5-3114-4c16-b6cb-c1a7b2aba70d}']
353     end;
354 tony 45
355 tony 87 IBPB = interface (IParameterBlock<IBPBItem>)
356 tony 56 ['{e0cb9eb5-17f7-4416-b7d1-3cddd1dfca76}']
357     end;
358 tony 45
359     { The Blob Interface provides access to a blob data item.
360    
361     The interface is returned by a GetAsBlob getter method (see ISQLData). A new Blob
362     can be obtained from the IAttachment interface. The SetAsBlob setter method
363     (See ISQLParam) is used to apply an updated or new array to the database using
364     an UPDATE or INSERT statement.
365     }
366    
367     TFBBlobMode = (fbmRead,fbmWrite);
368     TBlobType = (btSegmented,btStream);
369    
370     IBlob = interface(IBlobMetaData)
371 tony 56 ['{3090a145-7780-442b-b15b-efd4568b8611}']
372 tony 45 function GetBPB: IBPB;
373     procedure Cancel;
374     procedure Close;
375     function GetBlobID: TISC_QUAD;
376     function GetBlobMode: TFBBlobMode;
377     function GetBlobSize: Int64;
378     procedure GetInfo(var NumSegments: Int64; var MaxSegmentSize,
379     TotalSize: Int64; var BlobType: TBlobType);
380     function Read(var Buffer; Count: Longint): Longint;
381     function Write(const Buffer; Count: Longint): Longint;
382 tony 56 function LoadFromFile(Filename: AnsiString): IBlob;
383 tony 45 function LoadFromStream(S: TStream) : IBlob;
384 tony 56 function SaveToFile(Filename: AnsiString): IBlob;
385 tony 45 function SaveToStream(S: TStream): IBlob;
386     function GetAsString: rawbytestring;
387     procedure SetAsString(aValue: rawbytestring);
388     function SetString(aValue: rawbytestring): IBlob;
389     function GetAttachment: IAttachment;
390     function GetTransaction: ITransaction;
391     property AsString: rawbytestring read GetAsString write SetAsString;
392     end;
393    
394     { The IColumnMetaData interface provides access to the per column metadata for
395     the output of an SQL Statement.
396     }
397    
398     { IColumnMetaData }
399    
400     IColumnMetaData = interface
401 tony 56 ['{c222e6c3-53c1-469f-9e05-0a5c3ef232d8}']
402 tony 45 function GetIndex: integer;
403     function GetSQLType: cardinal;
404 tony 56 function GetSQLTypeName: AnsiString;
405 tony 45 function getSubtype: integer;
406 tony 56 function getRelationName: AnsiString;
407     function getOwnerName: AnsiString;
408     function getSQLName: AnsiString; {Name of the column}
409     function getAliasName: AnsiString; {Alias Name of column or Column Name if no alias}
410     function getName: AnsiString; {Disambiguated uppercase Field Name}
411 tony 45 function getScale: integer;
412     function getCharSetID: cardinal;
413     function getCodePage: TSystemCodePage;
414     function getIsNullable: boolean;
415     function GetSize: cardinal;
416     function GetArrayMetaData: IArrayMetaData; {Valid only for Array SQL Type}
417     function GetBlobMetaData: IBlobMetaData; {Valid only for Blob SQL Type}
418 tony 56 property Name: AnsiString read GetName;
419 tony 45 property Size: cardinal read GetSize;
420     property SQLType: cardinal read GetSQLType;
421     property Scale: integer read getScale;
422     property SQLSubtype: integer read getSubtype;
423     property IsNullable: Boolean read GetIsNullable;
424     end;
425    
426     {
427     The IMetaData interface provides access to the set of column metadata
428     for the output of an SQL Statement
429     }
430    
431     { IMetaData }
432    
433     IMetaData = interface
434 tony 56 ['{4dafdbb6-0d36-4f1f-9c95-8b132804b965}']
435 tony 45 function getCount: integer;
436     function getColumnMetaData(index: integer): IColumnMetaData;
437 tony 56 function GetUniqueRelationName: AnsiString; {Non empty if all columns come from the same table}
438     function ByName(Idx: AnsiString): IColumnMetaData;
439 tony 45 property ColMetaData[index: integer]: IColumnMetaData read getColumnMetaData; default;
440     property Count: integer read getCount;
441     end;
442    
443     {
444     The ISQLData interface provides access to the data returned in a field in the
445     current row returned from a query or the result of an SQL Execute statement.
446    
447     It subclasses IColumnMetaData and so also provides access to the metadata
448     associated with the column.
449    
450     The getter and setter methods, and the corresponding properties, provide typed
451     access to the field data. The method/property used should be consistent
452     with the SQL Type. Automatic conversion is provided from strings.
453     That is GetAsString is safe to use for sql types other than boolean.
454     }
455    
456    
457     ISQLData = interface(IColumnMetaData)
458 tony 56 ['{3f493e31-7e3f-4606-a07c-b210b9e3619d}']
459 tony 45 function GetAsBoolean: boolean;
460     function GetAsCurrency: Currency;
461     function GetAsInt64: Int64;
462     function GetAsDateTime: TDateTime;
463     function GetAsDouble: Double;
464     function GetAsFloat: Float;
465     function GetAsLong: Long;
466     function GetAsPointer: Pointer;
467     function GetAsQuad: TISC_QUAD;
468     function GetAsShort: short;
469 tony 56 function GetAsString: AnsiString;
470 tony 45 function GetIsNull: Boolean;
471     function GetAsVariant: Variant;
472     function GetAsBlob: IBlob; overload;
473     function GetAsBlob(BPB: IBPB): IBlob; overload;
474     function GetAsArray: IArray;
475     property AsDate: TDateTime read GetAsDateTime;
476     property AsBoolean:boolean read GetAsBoolean;
477     property AsTime: TDateTime read GetAsDateTime;
478     property AsDateTime: TDateTime read GetAsDateTime ;
479     property AsDouble: Double read GetAsDouble;
480     property AsFloat: Float read GetAsFloat;
481     property AsCurrency: Currency read GetAsCurrency;
482     property AsInt64: Int64 read GetAsInt64 ;
483     property AsInteger: Integer read GetAsLong;
484     property AsLong: Long read GetAsLong;
485     property AsPointer: Pointer read GetAsPointer;
486     property AsQuad: TISC_QUAD read GetAsQuad;
487     property AsShort: short read GetAsShort;
488 tony 56 property AsString: AnsiString read GetAsString;
489 tony 45 property AsVariant: Variant read GetAsVariant ;
490     property AsBlob: IBlob read GetAsBlob;
491     property AsArray: IArray read GetAsArray;
492     property IsNull: Boolean read GetIsNull;
493     property Value: Variant read GetAsVariant;
494     end;
495    
496     { An IResults interface is returned as the result of an SQL Execute statement
497     and provides access to the fields returned, if any. It is a collection of
498     ISQLData interfaces which are, in turn, used to access the data returned by
499     each field of the result set.
500     }
501    
502     IResults = interface
503 tony 56 ['{e836b2bb-93d1-4bbf-a8eb-7ce535de3bb5}']
504 tony 45 function getCount: integer;
505     function GetTransaction: ITransaction;
506 tony 56 function ByName(Idx: AnsiString): ISQLData;
507 tony 45 function getSQLData(index: integer): ISQLData;
508 tony 56 procedure GetData(index: integer; var IsNull:boolean; var len: short; var data: PByte);
509 tony 45 procedure SetRetainInterfaces(aValue: boolean);
510     property Data[index: integer]: ISQLData read getSQLData; default;
511     property Count: integer read getCount;
512     end;
513    
514     { An IResultSet interface is returned as the result of an SQL Open Cursor statement
515     (e.g. Select Statement) and provides access to the fields returned, if any
516     for the current row. It is a collection of ISQLData interfaces which are,
517     in turn, used to access the data returned by each field of the current row.
518     }
519     IResultSet = interface(IResults)
520 tony 56 ['{0ae4979b-7857-4e8c-8918-ec6f155b51a0}']
521 tony 45 function FetchNext: boolean;
522 tony 56 function GetCursorName: AnsiString;
523 tony 45 function IsEof: boolean;
524     procedure Close;
525     end;
526    
527     {The ISQLParam interface is used to provide access to each parameter in a
528     parametised SQL Statement. It subclasses IColumnMetaData and this part of
529     the interface may be used to access information on the expected SQL Type, etc.
530    
531     It also subclasses ISQLData and this part of the interface may be used to access
532     current values for each parameter.
533    
534     Otherwise, the interface comprises the Setter Methods and properties used to
535     set the value of each parameter.
536    
537     Automatic conversion is provided to and from strings. That is GetAsString and
538     SetAsString are safe to use for sql types other than boolean - provided automatic
539     conversion is possible.
540     }
541    
542     ISQLParam = interface
543 tony 56 ['{b22b4578-6d41-4807-a9a9-d2ec8d1d5a14}']
544 tony 45 function GetIndex: integer;
545     function GetSQLType: cardinal;
546 tony 56 function GetSQLTypeName: AnsiString;
547 tony 45 function getSubtype: integer;
548 tony 56 function getName: AnsiString;
549 tony 45 function getScale: integer;
550     function getCharSetID: cardinal;
551     function getCodePage: TSystemCodePage;
552     function getIsNullable: boolean;
553     function GetSize: cardinal;
554     function GetAsBoolean: boolean;
555     function GetAsCurrency: Currency;
556     function GetAsInt64: Int64;
557     function GetAsDateTime: TDateTime;
558     function GetAsDouble: Double;
559     function GetAsFloat: Float;
560     function GetAsLong: Long;
561     function GetAsPointer: Pointer;
562     function GetAsQuad: TISC_QUAD;
563     function GetAsShort: short;
564 tony 56 function GetAsString: AnsiString;
565 tony 45 function GetIsNull: boolean;
566     function GetAsVariant: Variant;
567     function GetAsBlob: IBlob;
568     function GetAsArray: IArray;
569     procedure Clear;
570     function GetModified: boolean;
571     procedure SetAsBoolean(AValue: boolean);
572     procedure SetAsCurrency(aValue: Currency);
573     procedure SetAsInt64(aValue: Int64);
574     procedure SetAsDate(aValue: TDateTime);
575     procedure SetAsLong(aValue: Long);
576     procedure SetAsTime(aValue: TDateTime);
577     procedure SetAsDateTime(aValue: TDateTime);
578     procedure SetAsDouble(aValue: Double);
579     procedure SetAsFloat(aValue: Float);
580     procedure SetAsPointer(aValue: Pointer);
581     procedure SetAsShort(aValue: Short);
582 tony 56 procedure SetAsString(aValue: AnsiString);
583 tony 45 procedure SetAsVariant(aValue: Variant);
584     procedure SetIsNull(aValue: Boolean);
585     procedure SetAsBlob(aValue: IBlob);
586     procedure SetAsArray(anArray: IArray);
587     procedure SetAsQuad(aValue: TISC_QUAD);
588     procedure SetCharSetID(aValue: cardinal);
589     property AsDate: TDateTime read GetAsDateTime write SetAsDate;
590     property AsBoolean:boolean read GetAsBoolean write SetAsBoolean;
591     property AsTime: TDateTime read GetAsDateTime write SetAsTime;
592     property AsDateTime: TDateTime read GetAsDateTime write SetAsDateTime;
593     property AsDouble: Double read GetAsDouble write SetAsDouble;
594     property AsFloat: Float read GetAsFloat write SetAsFloat;
595     property AsCurrency: Currency read GetAsCurrency write SetAsCurrency;
596     property AsInt64: Int64 read GetAsInt64 write SetAsInt64;
597     property AsInteger: Integer read GetAsLong write SetAsLong;
598     property AsLong: Long read GetAsLong write SetAsLong;
599     property AsPointer: Pointer read GetAsPointer write SetAsPointer;
600     property AsShort: Short read GetAsShort write SetAsShort;
601 tony 56 property AsString: AnsiString read GetAsString write SetAsString;
602 tony 45 property AsVariant: Variant read GetAsVariant write SetAsVariant;
603     property AsBlob: IBlob read GetAsBlob write SetAsBlob;
604     property AsArray: IArray read GetAsArray write SetAsArray;
605     property AsQuad: TISC_QUAD read GetAsQuad write SetAsQuad;
606     property Value: Variant read GetAsVariant write SetAsVariant;
607     property IsNull: Boolean read GetIsNull write SetIsNull;
608     property IsNullable: Boolean read GetIsNullable;
609     property Modified: Boolean read getModified;
610 tony 56 property Name: AnsiString read GetName;
611 tony 45 property SQLType: cardinal read GetSQLType;
612     end;
613    
614     {
615     The ISQLParams interface provides access to the collection of parameters used
616     for the input to an SQL Statement
617     }
618    
619     ISQLParams = interface
620 tony 56 ['{c6d95ac7-b2b7-461b-b890-afef0acbb077}']
621 tony 45 function getCount: integer;
622     function getSQLParam(index: integer): ISQLParam;
623 tony 56 function ByName(Idx: AnsiString): ISQLParam ;
624 tony 45 function GetModified: Boolean;
625     property Modified: Boolean read GetModified;
626     property Params[index: integer]: ISQLParam read getSQLParam; default;
627     property Count: integer read getCount;
628     end;
629    
630 tony 47
631     TPerfStats = (psCurrentMemory, psMaxMemory,
632     psRealTime, psUserTime, psBuffers,
633     psReads, psWrites, psFetches,psDeltaMemory);
634    
635 tony 56 TPerfCounters = array[TPerfStats] of comp;
636 tony 47
637 tony 45 {The IStatement interface provides access to an SQL Statement once it has been
638     initially prepared. The interface is returned from the IAttachment interface.
639     }
640    
641     IStatement = interface
642 tony 56 ['{a260576d-a07d-4a66-b02d-1b72543fd7cf}']
643 tony 45 function GetMetaData: IMetaData; {Output Metadata}
644     function GetSQLParams: ISQLParams;{Statement Parameters}
645 tony 56 function GetPlan: AnsiString;
646 tony 45 function GetRowsAffected(var SelectCount, InsertCount, UpdateCount, DeleteCount: integer): boolean;
647     function GetSQLStatementType: TIBSQLStatementTypes;
648 tony 56 function GetSQLText: AnsiString;
649 tony 45 function GetSQLDialect: integer;
650     function IsPrepared: boolean;
651     procedure Prepare(aTransaction: ITransaction=nil);
652     function Execute(aTransaction: ITransaction=nil): IResults;
653     function OpenCursor(aTransaction: ITransaction=nil): IResultSet;
654     function GetAttachment: IAttachment;
655     function GetTransaction: ITransaction;
656     procedure SetRetainInterfaces(aValue: boolean);
657 tony 47 procedure EnableStatistics(aValue: boolean);
658     function GetPerfStatistics(var stats: TPerfCounters): boolean;
659 tony 45 property MetaData: IMetaData read GetMetaData;
660     property SQLParams: ISQLParams read GetSQLParams;
661     property SQLStatementType: TIBSQLStatementTypes read GetSQLStatementType;
662     end;
663    
664     {Transaction Parameter Block: (TPB)
665    
666     The TPB provides the parameters used when starting a transaction. It is allocated
667     empty by the FirebirdAPI and the parameters are then added to it. Each individual
668     parameter may be accessed by the ITPBItem interface which can be used to set the
669     value, if any, of the parameter.
670    
671     The TPB parameters, and the associated symbolic codes and parameter values may be
672     found in the Interbase 6.0 API Guide.
673     }
674    
675 tony 56 ITPBItem = interface(IParameterBlockItem)
676     ['{544c1f2b-7c12-4a87-a4a5-face7ea72671}']
677     end;
678 tony 45
679 tony 56 ITPB = interface(IParameterBlock<ITPBItem>)
680     ['{7369b0ff-defe-437b-81fe-19b211d42d25}']
681     end;
682 tony 45
683     {The ITransactionAction interface provides access to a Transaction once it
684     has been initially started. After a Commit or Rollback, a transaction
685     may be restarted, optinally with a new TPB.
686    
687     A multi-database transaction is started from the FirebirdAPI. A single database
688     transaction is started from the IAttachment interface.
689     }
690    
691     TTransactionAction = (TARollback, TACommit, TACommitRetaining, TARollbackRetaining);
692     TTransactionCompletion = TARollback.. TACommit;
693    
694     ITransaction = interface
695 tony 56 ['{30928d0e-a9d7-4c61-b7cf-14f4f38abe2a}']
696 tony 45 function getTPB: ITPB;
697     procedure Start(DefaultCompletion: TTransactionCompletion=taCommit);
698     function GetInTransaction: boolean;
699     procedure PrepareForCommit; {Two phase commit - stage 1}
700     procedure Commit(Force: boolean=false);
701     procedure CommitRetaining;
702     function HasActivity: boolean;
703     procedure Rollback(Force: boolean=false);
704     procedure RollbackRetaining;
705     function GetAttachmentCount: integer;
706     function GetAttachment(index: integer): IAttachment;
707     property InTransaction: boolean read GetInTransaction;
708     end;
709    
710     { The IEvents Interface is used to handle events from a single database. The
711     interface is allocated from the IAttachment Interface.
712    
713     Note that the EventHandler called when an event occurs following AsynWaitForEvent
714     is called in a different thread to the calling program and TThread.Synchronize
715     may be needed to pass the event back to the main thread.
716    
717     Neither AsyncWaitForEvent nor WaitForEvent is intended to be thread safe
718     in a multi-threaded environment and should always be called from the main
719     thread.
720     }
721    
722     TEventInfo = record
723 tony 56 EventName: AnsiString;
724 tony 45 Count: integer;
725     end;
726    
727     TEventCounts = array of TEventInfo;
728     IEvents = interface;
729     TEventHandler = procedure(Sender: IEvents) of object;
730    
731     { IEvents }
732    
733     IEvents = interface
734 tony 56 ['{6a0be233-ed08-4524-889c-2e45d0c20e5f}']
735 tony 45 procedure GetEvents(EventNames: TStrings);
736     procedure SetEvents(EventNames: TStrings); overload;
737 tony 56 procedure SetEvents(EventName: AnsiString); overload;
738 tony 45 procedure Cancel;
739     function ExtractEventCounts: TEventCounts;
740     procedure WaitForEvent;
741     procedure AsyncWaitForEvent(EventHandler: TEventHandler);
742     function GetAttachment: IAttachment;
743     end;
744    
745     {The IDBInformation Interface.
746    
747     An IDBInformation interface is returned by the IAttachment GetDBInformation
748     method. The interface provides access to the information requested and
749     returned by the method.
750    
751     IDBInformation itself gives access to a collection of IDBInfoItems. Each one
752     provides information requested, as indicated by the ItemType and the actual
753     value of the information. In some cases, the returned item is itself a
754     colletion of IDBInfoItems.
755    
756     The IDBInformation items, and the associated symbolic codes and parameter values may be
757     found in the Interbase 6.0 API Guide.
758     }
759    
760     TDBOperationCount = record
761     TableID: UShort;
762     Count: cardinal;
763     end;
764    
765     TDBOperationCounts = array of TDBOperationCount;
766    
767     IDBInfoItem = interface
768 tony 56 ['{eeb97b51-ec0f-473f-9f75-c1721f055fcb}']
769 tony 45 function getItemType: byte;
770     function getSize: integer;
771     procedure getRawBytes(var Buffer);
772 tony 56 function getAsString: AnsiString;
773 tony 45 function getAsInteger: integer;
774 tony 56 procedure DecodeIDCluster(var ConnectionType: integer; var DBFileName, DBSiteName: AnsiString);
775 tony 45 function getAsBytes: TByteArray;
776 tony 56 procedure DecodeVersionString(var Version: byte; var VersionString: AnsiString);
777 tony 45 function getOperationCounts: TDBOperationCounts;
778     procedure DecodeUserNames(UserNames: TStrings);
779    
780     {user names only}
781     function GetCount: integer;
782     function GetItem(index: integer): IDBInfoItem;
783     function Find(ItemType: byte): IDBInfoItem;
784     property AsInteger: integer read getAsInteger;
785 tony 56 property AsString: AnsiString read GetAsString;
786 tony 45 property Count: integer read GetCount;
787     property Items[index: integer]: IDBInfoItem read getItem; default;
788     end;
789    
790     { IDBInformation }
791    
792     IDBInformation = interface
793 tony 56 ['{7ac6777f-f0a9-498a-9f5c-4a57a554df81}']
794 tony 45 function GetCount: integer;
795     function GetItem(index: integer): IDBInfoItem;
796     function Find(ItemType: byte): IDBInfoItem;
797     procedure PrintBuf; {can be used to print buffer in hex for debugging}
798     property Count: integer read GetCount;
799     property Items[index: integer]: IDBInfoItem read getItem; default;
800     end;
801    
802     {The Database Parameter Block (DPB).
803    
804     The DPB provides the parameters used when connecting to a database. It is allocated
805     empty by the FirebirdAPI and the parameters are then added to it. Each individual
806     parameter may be accessed by the IDPBItem interface which can be used to set the
807     value, if any, of the parameter.
808    
809     The DPB parameters, and the associated symbolic codes and parameter values may be
810     found in the Interbase 6.0 API Guide.
811     }
812    
813 tony 56 IDPBItem = interface(IParameterBlockItem)
814     ['{123d4ad0-087a-4cd1-a344-1b3d03b30673}']
815     end;
816 tony 45
817 tony 56 IDPB = interface(IParameterBlock<IDPBItem>)
818     ['{e676067b-1cf4-4eba-9256-9724f57e0d16}']
819     end;
820 tony 45
821     {The IAttachment interface provides access to a Database Connection. It may be
822     used to:
823    
824     a. Disconnect and reconnect to the database.
825    
826     b. Start a Transaction on the database
827    
828     c. Execute directly SQL DDL Statements and others that return no information.
829    
830     d. OpenCursors (i.e. execute SQL Select statements and return the results)
831    
832     e. Prepare SQL Statements, returning an IStatement interface for further processing.
833    
834     f. Provide access to an SQL Event Handler.
835    
836     g. Access Database Information.
837    
838     h. Support the handling of Array and Blob data.
839    
840     Note that SQL statements can be prepared with named parameters (PSQL style).
841     This then allows the parameters to be accessed by name. The same name can
842     be used for more than one parameter, allowing a single operation to be used
843     to set all parameters with the same name.
844     }
845    
846     { IAttachment }
847    
848     IAttachment = interface
849 tony 56 ['{466e9b67-9def-4807-b3e7-e08a35e7185c}']
850 tony 45 function getDPB: IDPB;
851     function AllocateBPB: IBPB;
852     procedure Connect;
853     procedure Disconnect(Force: boolean=false);
854     function IsConnected: boolean;
855     procedure DropDatabase;
856     function StartTransaction(TPB: array of byte; DefaultCompletion: TTransactionCompletion=taCommit): ITransaction; overload;
857     function StartTransaction(TPB: ITPB; DefaultCompletion: TTransactionCompletion=taCommit): ITransaction; overload;
858 tony 56 procedure ExecImmediate(transaction: ITransaction; sql: AnsiString; SQLDialect: integer); overload;
859     procedure ExecImmediate(TPB: array of byte; sql: AnsiString; SQLDialect: integer); overload;
860     procedure ExecImmediate(transaction: ITransaction; sql: AnsiString); overload;
861     procedure ExecImmediate(TPB: array of byte; sql: AnsiString); overload;
862     function ExecuteSQL(TPB: array of byte; sql: AnsiString; SQLDialect: integer; params: array of const): IResults; overload;
863     function ExecuteSQL(transaction: ITransaction; sql: AnsiString; SQLDialect: integer; params: array of const): IResults; overload;
864     function ExecuteSQL(TPB: array of byte; sql: AnsiString; params: array of const): IResults; overload;
865     function ExecuteSQL(transaction: ITransaction; sql: AnsiString; params: array of const): IResults; overload;
866     function OpenCursor(transaction: ITransaction; sql: AnsiString; aSQLDialect: integer): IResultSet; overload;
867     function OpenCursor(transaction: ITransaction; sql: AnsiString; aSQLDialect: integer;
868 tony 45 params: array of const): IResultSet; overload;
869 tony 56 function OpenCursor(transaction: ITransaction; sql: AnsiString): IResultSet; overload;
870     function OpenCursor(transaction: ITransaction; sql: AnsiString;
871 tony 45 params: array of const): IResultSet; overload;
872 tony 56 function OpenCursorAtStart(transaction: ITransaction; sql: AnsiString; aSQLDialect: integer): IResultSet; overload;
873     function OpenCursorAtStart(transaction: ITransaction; sql: AnsiString; aSQLDialect: integer;
874 tony 45 params: array of const): IResultSet; overload;
875 tony 56 function OpenCursorAtStart(transaction: ITransaction; sql: AnsiString): IResultSet; overload;
876     function OpenCursorAtStart(transaction: ITransaction; sql: AnsiString;
877 tony 45 params: array of const): IResultSet; overload;
878 tony 56 function OpenCursorAtStart(sql: AnsiString): IResultSet; overload;
879     function OpenCursorAtStart(sql: AnsiString;
880 tony 45 params: array of const): IResultSet; overload;
881 tony 56 function Prepare(transaction: ITransaction; sql: AnsiString; aSQLDialect: integer): IStatement; overload;
882     function Prepare(transaction: ITransaction; sql: AnsiString): IStatement; overload;
883     function PrepareWithNamedParameters(transaction: ITransaction; sql: AnsiString;
884 tony 45 aSQLDialect: integer; GenerateParamNames: boolean=false): IStatement; overload;
885 tony 56 function PrepareWithNamedParameters(transaction: ITransaction; sql: AnsiString;
886 tony 45 GenerateParamNames: boolean=false): IStatement; overload;
887    
888     {Events}
889     function GetEventHandler(Events: TStrings): IEvents; overload;
890 tony 56 function GetEventHandler(Event: AnsiString): IEvents; overload;
891 tony 45
892     {Blob - may use to open existing Blobs. However, ISQLData.AsBlob is preferred}
893    
894 tony 56 function CreateBlob(transaction: ITransaction; RelationName, ColumnName: AnsiString; BPB: IBPB=nil): IBlob; overload;
895 tony 45 function CreateBlob(transaction: ITransaction; BlobMetaData: IBlobMetaData; BPB: IBPB=nil): IBlob; overload;
896     function CreateBlob(transaction: ITransaction; SubType: integer; CharSetID: cardinal=0; BPB: IBPB=nil): IBlob; overload;
897 tony 56 function OpenBlob(transaction: ITransaction; RelationName, ColumnName: AnsiString; BlobID: TISC_QUAD; BPB: IBPB=nil): IBlob;
898 tony 45
899     {Array - may use to open existing arrays. However, ISQLData.AsArray is preferred}
900    
901 tony 56 function OpenArray(transaction: ITransaction; RelationName, ColumnName: AnsiString; ArrayID: TISC_QUAD): IArray;
902     function CreateArray(transaction: ITransaction; RelationName, ColumnName: AnsiString): IArray; overload;
903 tony 45 function CreateArray(transaction: ITransaction; ArrayMetaData: IArrayMetaData): IArray; overload;
904 tony 56 function CreateArrayMetaData(SQLType: cardinal; tableName: AnsiString; columnName: AnsiString;
905 tony 47 Scale: integer; size: cardinal; charSetID: cardinal; dimensions: cardinal;
906     bounds: TArrayBounds): IArrayMetaData;
907 tony 45
908     {Database Information}
909     function GetSQLDialect: integer;
910 tony 56 function GetBlobMetaData(Transaction: ITransaction; tableName, columnName: AnsiString): IBlobMetaData;
911     function GetArrayMetaData(Transaction: ITransaction; tableName, columnName: AnsiString): IArrayMetaData;
912 tony 45 function GetDBInformation(Requests: array of byte): IDBInformation; overload;
913     function GetDBInformation(Request: byte): IDBInformation; overload;
914 tony 117 function GetConnectString: AnsiString;
915     function GetRemoteProtocol: AnsiString;
916     function GetODSMajorVersion: integer;
917     function GetODSMinorVersion: integer;
918 tony 45 function HasActivity: boolean;
919 tony 60
920     {Character Sets}
921 tony 109 function HasDefaultCharSet: boolean;
922     function GetDefaultCharSetID: integer;
923 tony 60 function GetCharsetName(CharSetID: integer): AnsiString;
924     function CharSetID2CodePage(CharSetID: integer; var CodePage: TSystemCodePage): boolean;
925     function CodePage2CharSetID(CodePage: TSystemCodePage; var CharSetID: integer): boolean;
926     function CharSetName2CharSetID(CharSetName: AnsiString; var CharSetID: integer): boolean;
927     function CharSetWidth(CharSetID: integer; var Width: integer): boolean;
928     procedure RegisterCharSet(CharSetName: AnsiString; CodePage: TSystemCodePage;
929     AllowReverseLookup:boolean; out CharSetID: integer);
930 tony 45 end;
931    
932     TProtocol = (TCP, SPX, NamedPipe, Local);
933    
934     {Service Parameter Block (SPB).
935    
936     The SPB provides the parameters used when connecting to a Service Manager. It is
937     allocated empty by the FirebirdAPI and the parameters are then added to it. Each
938     individual parameter may be accessed by the ISPBItem interface which can be used
939     to set the value, if any, of the parameter.
940    
941     The SPB parameters, and the associated symbolic codes and parameter values may be
942     found in the Interbase 6.0 API Guide.
943    
944     }
945    
946 tony 56 ISPBItem = interface(IParameterBlockItem)
947     ['{5d08ae2b-4519-41bd-8b40-97cd451c3f6a}']
948     end;
949 tony 45
950 tony 56 ISPB = interface(IParameterBlock<ISPBItem>)
951     ['{2c5836fd-41ed-4426-9b7d-5af580ec2659}']
952     end;
953 tony 45
954     {Service Query Parameter Block (SQPB).
955    
956     This is a specialised parameter block used to send data to a service manager
957     in a Query Request.
958     }
959    
960     ISQPBItem = interface(IParameterBlockItem)
961 tony 56 ['{b07841a6-33b3-47f0-b5a2-028cbc86dc97}']
962 tony 45 function CopyFrom(source: TStream; count: integer): integer;
963     end;
964    
965 tony 56 ISQPB = interface(IParameterBlock<ISQPBItem>)
966     ['{8553e66b-ee62-498b-8431-dff030211447}']
967     end;
968 tony 45
969     {Service Request Block (SRB).
970    
971     The SRB specifies what is requested from the Service Manager when starting a
972     service or querying a service. It is allocated empty by the ServiceManager API and
973     the parameters are then added to it. Each individual parameter may be accessed
974     by the ISRBItem interface which can be used to set the value, if any, of the parameter.
975    
976     The SRB 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 ISRBItem = interface(IParameterBlockItem)
982     ['{47ec790e-f265-4b30-9dcd-261e51677245}']
983     end;
984 tony 45
985 tony 56 ISRB = interface(IParameterBlock<ISRBItem>)
986     ['{9f2e204f-3c33-4e44-90f9-9135e95dafb9}']
987     end;
988 tony 45
989     {The Service Query Results Interface.
990    
991     An IServiceQueryResults interface is returned by the IServiceManager Query
992     method. The interface provides access to the information requested and
993     returned by the method.
994    
995     IServiceQueryResults itself gives access to a collection of IServiceQueryResultItem.
996     Each one provides information requested, as indicated by the ItemType and the actual
997     value of the information. In some cases, the returned item is itself a
998     collection of IServiceQueryResultSubItem.
999    
1000     The IServiceQueryResultItem items, and the associated symbolic codes and parameter values may be
1001     found in the Interbase 6.0 API Guide.
1002     }
1003    
1004     IServiceQueryResultSubItem = interface
1005 tony 56 ['{8a4c381e-9923-4cc9-a96b-553729248640}']
1006 tony 45 function getItemType: byte;
1007     function getSize: integer;
1008     procedure getRawBytes(var Buffer);
1009 tony 56 function getAsString: AnsiString;
1010 tony 45 function getAsInteger: integer;
1011     function getAsByte: byte;
1012     function CopyTo(stream: TStream; count: integer): integer;
1013 tony 56 property AsString: AnsiString read getAsString;
1014 tony 45 property AsInteger: integer read getAsInteger;
1015     property AsByte: byte read getAsByte;
1016     end;
1017    
1018     IServiceQueryResultItem = interface(IServiceQueryResultSubItem)
1019 tony 56 ['{b2806886-206c-4024-8df9-5fe0a7630a5e}']
1020 tony 45 function getCount: integer;
1021     function getItem(index: integer): IServiceQueryResultSubItem;
1022     function find(ItemType: byte): IServiceQueryResultSubItem;
1023     property Items[index: integer]: IServiceQueryResultSubItem read getItem; default;
1024     property Count: integer read getCount;
1025     end;
1026    
1027     IServiceQueryResults = interface
1028 tony 56 ['{8fbbef7d-fe03-4409-828a-a787d34ef531}']
1029 tony 45 function getCount: integer;
1030     function getItem(index: integer): IServiceQueryResultItem;
1031     function find(ItemType: byte): IServiceQueryResultItem;
1032     procedure PrintBuf; {can be used to print buffer in hex for debugging}
1033     property Items[index: integer]: IServiceQueryResultItem read getItem; default;
1034     property Count: integer read getCount;
1035     end;
1036    
1037     {The IServiceManager interface provides access to a service manager. It can
1038     used to Detach and re-attach to Service Manager, to start services and to
1039     query the service manager.
1040    
1041     The interface is returned by the FirebirdAPI GetService Manager method.
1042     }
1043    
1044     { IServiceManager }
1045    
1046     IServiceManager = interface
1047 tony 56 ['{905b587d-1e1f-4e40-a3f8-a3519f852e48}']
1048 tony 45 function getSPB: ISPB;
1049 tony 56 function getServerName: AnsiString;
1050 tony 45 procedure Attach;
1051     procedure Detach(Force: boolean=false);
1052     function IsAttached: boolean;
1053     function AllocateSRB: ISRB;
1054     function AllocateSQPB: ISQPB;
1055     procedure Start(Request: ISRB);
1056     function Query(SQPB: ISQPB; Request: ISRB) :IServiceQueryResults; overload;
1057     function Query(Request: ISRB) :IServiceQueryResults; overload;
1058     end;
1059    
1060     {The Firebird API.
1061    
1062     This is the base interface and is used to create/open a database connection, to
1063     start a transaction on multiple databases and the access the service manager.
1064    
1065     The interface is returned by the FirebirdAPI function.
1066     }
1067    
1068     IFirebirdAPI = interface
1069 tony 56 ['{edeee691-c8d3-4dcf-a780-cd7e432821d5}']
1070 tony 45 {Database connections}
1071     function AllocateDPB: IDPB;
1072 tony 56 function OpenDatabase(DatabaseName: AnsiString; DPB: IDPB; RaiseExceptionOnConnectError: boolean=true): IAttachment;
1073     function CreateDatabase(DatabaseName: AnsiString; DPB: IDPB; RaiseExceptionOnError: boolean=true): IAttachment; overload;
1074     function CreateDatabase(sql: AnsiString; aSQLDialect: integer; RaiseExceptionOnError: boolean=true): IAttachment; overload;
1075 tony 45
1076     {Start Transaction against multiple databases}
1077     function AllocateTPB: ITPB;
1078     function StartTransaction(Attachments: array of IAttachment;
1079     TPB: array of byte; DefaultCompletion: TTransactionCompletion=taCommit): ITransaction; overload;
1080     function StartTransaction(Attachments: array of IAttachment;
1081     TPB: ITPB; DefaultCompletion: TTransactionCompletion=taCommit): ITransaction; overload;
1082    
1083     {Service Manager}
1084     function HasServiceAPI: boolean;
1085     function AllocateSPB: ISPB;
1086 tony 56 function GetServiceManager(ServerName: AnsiString; Protocol: TProtocol; SPB: ISPB): IServiceManager;
1087 tony 45
1088     {Information}
1089     function GetStatus: IStatus;
1090     function GetLibraryName: string;
1091     function HasRollbackRetaining: boolean;
1092     function IsEmbeddedServer: boolean;
1093 tony 56 function GetImplementationVersion: AnsiString;
1094 tony 45
1095     {Firebird 3 API}
1096     function HasMasterIntf: boolean;
1097     function GetIMaster: TObject;
1098     end;
1099    
1100     type
1101     TOnGetLibraryName = procedure(var libname: string);
1102    
1103     const
1104     OnGetLibraryName: TOnGetLibraryName = nil;
1105     AllowUseOfFBLIB: boolean = false;
1106    
1107     type
1108     { EIBError }
1109    
1110     EIBError = class(EDatabaseError)
1111     private
1112     FSQLCode: Long;
1113     public
1114 tony 56 constructor Create(ASQLCode: Long; Msg: AnsiString);
1115 tony 45 property SQLCode: Long read FSQLCode;
1116     end;
1117    
1118     { EIBInterBaseError - Firebird Engine errors}
1119    
1120     EIBInterBaseError = class(EIBError)
1121     private
1122     FIBErrorCode: Long;
1123     public
1124     constructor Create(Status: IStatus); overload;
1125 tony 56 constructor Create(ASQLCode: Long; AIBErrorCode: Long; Msg: AnsiString); overload;
1126 tony 45 property IBErrorCode: Long read FIBErrorCode;
1127     end;
1128    
1129     {IB Client Exceptions}
1130     EIBClientError = class(EIBError);
1131    
1132     {IBError is used internally and by IBX to throw an EIBClientError}
1133    
1134     procedure IBError(ErrMess: TIBClientError; const Args: array of const);
1135    
1136     {The Firebird API function is used to access the IFirebirdAPI interface.
1137    
1138     It will load the Firebird Client Library if this is not already loaded and
1139     select an implementation of the Firebird API (legacy 2.5 or 3.0.
1140     }
1141    
1142     function FirebirdAPI: IFirebirdAPI;
1143    
1144     {IBX support functions. Probably best ignored i.e. always used the FirebirdAPI
1145     functino to load the library and check if it's loaded.}
1146    
1147     function TryIBLoad: Boolean;
1148     procedure CheckIBLoaded;
1149    
1150     implementation
1151    
1152     uses FBClientAPI
1153     {$IFDEF USELEGACYFIREBIRDAPI}, FB25ClientAPI {$ENDIF}
1154     {$IFDEF USEFIREBIRD3API}, FB30ClientAPI {$ENDIF};
1155    
1156     var FFirebirdAPI: IFirebirdAPI;
1157    
1158     function FirebirdAPI: IFirebirdAPI;
1159     begin
1160     if FFirebirdAPI = nil then
1161     CheckIBLoaded;
1162     Result := FFirebirdAPI;
1163     end;
1164    
1165     function TryIBLoad: Boolean;
1166     begin
1167     Result := FFirebirdAPI <> nil;
1168     try
1169     {$IFDEF USEFIREBIRD3API}
1170     if not Result then
1171     begin
1172     FFirebirdAPI := TFB30ClientAPI.Create;
1173     Result := FFirebirdAPI.HasMasterIntf;
1174     end;
1175     {$ENDIF}
1176     {$IFDEF USELEGACYFIREBIRDAPI}
1177     if not Result then
1178     begin
1179     FFirebirdAPI := nil;
1180     FFirebirdAPI := TFB25ClientAPI.Create;
1181     Result := true;
1182     end;
1183     {$ENDIF}
1184     if Result and not (FFirebirdAPI as TFBClientAPI).IsLibraryLoaded then
1185     begin
1186     Result := false;
1187     FFirebirdAPI := nil;
1188     end;
1189     except
1190     SysUtils.showexception(ExceptObject,ExceptAddr);
1191     Result := false;
1192     end;
1193     end;
1194    
1195     procedure CheckIBLoaded;
1196     begin
1197     if not TryIBLoad then
1198     IBError(ibxeInterBaseMissing, [nil]);
1199     end;
1200    
1201     { EIBError }
1202    
1203 tony 56 constructor EIBError.Create(ASQLCode: Long; Msg: AnsiString);
1204 tony 45 begin
1205     inherited Create(Msg);
1206     FSQLCode := ASQLCode;
1207     end;
1208    
1209     { EIBInterBaseError }
1210    
1211     constructor EIBInterBaseError.Create(Status: IStatus);
1212     begin
1213     inherited Create(Status.Getsqlcode,Status.GetMessage);
1214     FIBErrorCode := Status.GetIBErrorCode;
1215     end;
1216    
1217     constructor EIBInterBaseError.Create(ASQLCode: Long; AIBErrorCode: Long;
1218 tony 56 Msg: AnsiString);
1219 tony 45 begin
1220     inherited Create(ASQLCode,Msg);
1221     FIBErrorCode := AIBErrorCode;
1222     end;
1223    
1224     procedure IBError(ErrMess: TIBClientError; const Args: array of const);
1225     begin
1226     raise EIBClientError.Create(Ord(ErrMess),
1227     Format(GetErrorMessage(ErrMess), Args));
1228     end;
1229    
1230     initialization
1231     FFirebirdAPI := nil;
1232    
1233    
1234     end.
1235