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