ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/branches/udr/client/IB.pas
Revision: 345
Committed: Mon Aug 23 14:22:29 2021 UTC (3 years, 3 months ago) by tony
Content type: text/x-pascal
Original Path: ibx/trunk/fbintf/IB.pas
File size: 62201 byte(s)
Log Message:
Merged into public release

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