ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/branches/udr/client/IB.pas
Revision: 349
Committed: Mon Oct 18 08:39:40 2021 UTC (3 years, 1 month ago) by tony
Content type: text/x-pascal
Original Path: ibx/trunk/fbintf/IB.pas
File size: 62863 byte(s)
Log Message:
FIxes Merged

File Contents

# Content
1 (*
2 * Firebird Interface (fbintf). The fbintf components provide a set of
3 * Pascal language bindings for the Firebird API. Although predominantly
4 * a new development they include source code taken from IBX and may be
5 * considered a derived product. This software thus also includes the copyright
6 * notice and license conditions from IBX.
7 *
8 * Except for those parts dervied from IBX, contents of this file are subject
9 * to the Initial Developer's Public License Version 1.0 (the "License"); you
10 * may not use this file except in compliance with the License. You may obtain a
11 * copy of the License here:
12 *
13 * http://www.firebirdsql.org/index.php?op=doc&id=idpl
14 *
15 * Software distributed under the License is distributed on an "AS
16 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
17 * implied. See the License for the specific language governing rights
18 * and limitations under the License.
19 *
20 * The Initial Developer of the Original Code is Tony Whyman.
21 *
22 * The Original Code is (C) 2016 Tony Whyman, MWA Software
23 * (http://www.mwasoftware.co.uk).
24 *
25 * All Rights Reserved.
26 *
27 * Contributor(s): ______________________________________.
28 *
29 *)
30 {************************************************************************}
31 { }
32 { Borland Delphi Visual Component Library }
33 { InterBase Express core components }
34 { }
35 { Copyright (c) 1998-2000 Inprise Corporation }
36 { }
37 { InterBase Express is based in part on the product }
38 { Free IB Components, written by Gregory H. Deatz for }
39 { Hoagland, Longo, Moran, Dunst & Doukas Company. }
40 { Free IB Components is used under license. }
41 { }
42 { The contents of this file are subject to the InterBase }
43 { Public License Version 1.0 (the "License"); you may not }
44 { use this file except in compliance with the License. You }
45 { may obtain a copy of the License at http://www.Inprise.com/IPL.html }
46 { Software distributed under the License is distributed on }
47 { an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either }
48 { express or implied. See the License for the specific language }
49 { governing rights and limitations under the License. }
50 { The Original Code was created by InterBase Software Corporation }
51 { and its successors. }
52 { Portions created by Inprise Corporation are Copyright (C) Inprise }
53 { Corporation. All Rights Reserved. }
54 { Contributor(s): Jeff Overcash }
55 { }
56 { IBX For Lazarus (Firebird Express) }
57 { Contributor: Tony Whyman, MWA Software http://www.mwasoftware.co.uk }
58 { Portions created by MWA Software are copyright McCallum Whyman }
59 { Associates Ltd 2011 - 2015 }
60 { }
61 {************************************************************************}
62 unit IB;
63 {$IFDEF MSWINDOWS}
64 {$DEFINE WINDOWS}
65 {$ENDIF}
66
67 {$IFDEF FPC}
68 {$mode delphi}
69 {$codepage UTF8}
70 {$interfaces COM}
71 {$IF defined(FPC) and (FPC_FULLVERSION < 30000) }
72 {$ERROR FPC Version 3.0.0 or later is required}
73 {$IFEND}
74 {$ENDIF}
75
76 {$IFNDEF LEGACYFIREBIRDAPIONLY}
77 {$DEFINE USEFIREBIRD3API}
78 {$ENDIF}
79 {$IFNDEF FIREBIRD3APIONLY}
80 {$DEFINE USELEGACYFIREBIRDAPI}
81 {$ENDIF}
82
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 6. FPC and Delphi Support.
114
115 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 Classes,
130 {$IFDEF WINDOWS}Windows, {$ENDIF}
131 {$IFDEF FPC} Dynlibs, {$ENDIF}
132 SysUtils, DB, FBMessages, IBExternals, FmtBcd;
133
134 const
135 {Interface version information}
136 FBIntf_Major = 1;
137 FBIntf_Minor = 3;
138 FBIntf_Release = 2;
139 FBIntf_Version = '1.3.2';
140
141 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 {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 {$I 'include/consts_pub.inc'}
160 {$I 'include/dyn_consts.inc'}
161 {$I 'include/inf_pub.inc'}
162 {$I 'include/configkeys.inc'}
163 {$I 'include/blr.inc'}
164
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 SQL_TIMESTAMP_TZ_EX = 32748;
186 SQL_TIME_TZ_EX = 32750;
187 SQL_INT128 = 32752;
188 SQL_BOOLEAN = 32764;
189 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 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 {$IFNDEF FPC}
209 {Delphi missing definitions}
210 type
211 TLibHandle = THandle;
212
213 const
214 NilHandle = 0;
215 DirectorySeparator = '\';
216
217 {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 TIBSQLStatementTypes =
234 (SQLUnknown, SQLSelect, SQLInsert,
235 SQLUpdate, SQLDelete, SQLDDL,
236 SQLGetSegment, SQLPutSegment,
237 SQLExecProcedure, SQLStartTransaction,
238 SQLCommit, SQLRollback,
239 SQLSelectForUpdate, SQLSetGenerator,
240 SQLSavePoint);
241
242 TFBStatusCode = cardinal;
243 TByteArray = array of byte;
244 TFBTimeZoneID = ISC_USHORT;
245
246 IFirebirdAPI = interface;
247 IAttachment = interface;
248 ITransaction = interface;
249 IStatement = interface;
250
251 {The IParameterBlock interface provides the template for all parameter
252 block interfaces}
253
254 IParameterBlock<_IItem> = interface
255 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 IParameterBlockWithTypeNames<_IItem> = interface(IParameterBlock<_IItem>)
265 function AddByTypeName(ParamTypeName: AnsiString): _IItem;
266 function GetDPBParamTypeName(ParamType: byte): Ansistring; deprecated 'Use Get ParamTypeName';
267 function GetParamTypeName(ParamType: byte): Ansistring;
268 end;
269
270 {IParameterBlockItem is not used on its own but instead provides a base type for
271 different parameter block items }
272
273 IParameterBlockItem = interface
274 ['{53b23f7b-abda-46a5-9aa5-07bd5e723266}']
275 function getParamType: byte;
276 function getAsInteger: integer;
277 function getAsString: AnsiString;
278 function getAsByte: byte;
279 procedure setAsString(aValue: AnsiString);
280 procedure setAsByte(aValue: byte);
281 procedure SetAsInteger(aValue: integer);
282 property AsString: AnsiString read getAsString write setAsString;
283 property AsByte: byte read getAsByte write setAsByte;
284 property AsInteger: integer read getAsInteger write SetAsInteger;
285 end;
286
287 IParameterBlockItemWithTypeName = interface(IParameterBlockItem)
288 function getParamTypeName: AnsiString;
289 end;
290
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 TIBDataBaseErrorMessage = (ShowSQLCode,
299 ShowIBMessage,
300 ShowSQLMessage);
301
302 TIBDataBaseErrorMessages = set of TIBDataBaseErrorMessage;
303
304 TStatusCode = long;
305
306 IStatus = interface
307 ['{34167722-af38-4831-b08a-93162d58ede3}']
308 function GetIBErrorCode: TStatusCode;
309 function Getsqlcode: TStatusCode;
310 function GetMessage: AnsiString;
311 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 ['{7dd0aea4-59af-4c2a-b958-565d5025c489}']
328 function GetSQLType: cardinal;
329 function GetSQLTypeName: AnsiString;
330 function GetScale: integer;
331 function GetSize: cardinal;
332 function GetCharSetWidth: integer;
333 function GetCharSetID: cardinal;
334 function GetTableName: AnsiString;
335 function GetColumnName: AnsiString;
336 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 ['{631c6bb1-fb49-44fb-a64a-c49859632b88}']
361 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 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 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 function GetAsString(index: array of integer): AnsiString;
382 function GetAsVariant(index: array of integer): Variant;
383 function GetAsBCD(index: array of integer): tBCD;
384 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 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 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 procedure SetAsString(index: array of integer; Value: AnsiString);
401 procedure SetAsVariant(index: array of integer; Value: Variant);
402 procedure SetAsBcd(index: array of integer; aValue: tBCD);
403 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 ['{575f3c61-bb33-46a5-8975-bb7d1b6e37cc}']
416 function GetSubType: integer;
417 function GetCharSetID: cardinal;
418 function GetCodePage: TSystemCodePage;
419 function GetSegmentSize: cardinal;
420 function GetRelationName: AnsiString;
421 function GetColumnName: AnsiString;
422 end;
423
424 {The Blob Parameter block is used to select a Blob Filter}
425
426 IBPBItem = interface (IParameterBlockItem)
427 ['{660822a5-3114-4c16-b6cb-c1a7b2aba70d}']
428 end;
429
430 IBPB = interface (IParameterBlock<IBPBItem>)
431 ['{e0cb9eb5-17f7-4416-b7d1-3cddd1dfca76}']
432 end;
433
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 ['{3090a145-7780-442b-b15b-efd4568b8611}']
447 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 function LoadFromFile(Filename: AnsiString): IBlob;
458 function LoadFromStream(S: TStream) : IBlob;
459 function SaveToFile(Filename: AnsiString): IBlob;
460 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 TIBDateTimeFormats = (dfTimestamp, {SQL TIMESTAMP}
474 dfDateTime, {SQL DATETIME}
475 dfTime, {SQL TIME}
476 dfTimestampTZ, {SQL_TIMESTAMP_TZ}
477 dfTimeTZ); {SQLTIME_TZ
478
479 { IColumnMetaData }
480
481 IColumnMetaData = interface
482 ['{c222e6c3-53c1-469f-9e05-0a5c3ef232d8}']
483 function GetIndex: integer;
484 function GetSQLType: cardinal;
485 function GetSQLTypeName: AnsiString;
486 function getSubtype: integer;
487 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 function getScale: integer;
493 function getCharSetID: cardinal;
494 function getCodePage: TSystemCodePage;
495 function GetCharSetWidth: integer;
496 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 function GetDateTimeStrLength(DateTimeFormat: TIBDateTimeFormats): integer;
501 function GetStatement: IStatement;
502 function GetTransaction: ITransaction;
503 property Name: AnsiString read GetName;
504 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 ['{4dafdbb6-0d36-4f1f-9c95-8b132804b965}']
520 function getCount: integer;
521 function getColumnMetaData(index: integer): IColumnMetaData;
522 function GetUniqueRelationName: AnsiString; {Non empty if all columns come from the same table}
523 function ByName(Idx: AnsiString): IColumnMetaData;
524 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 ['{3f493e31-7e3f-4606-a07c-b210b9e3619d}']
544 function GetStrDataLength: short;
545 function GetAsBoolean: boolean;
546 function GetAsCurrency: Currency;
547 function GetAsInt64: Int64;
548 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 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 function GetAsString: AnsiString;
563 function GetIsNull: Boolean;
564 function GetAsVariant: Variant;
565 function GetAsBlob: IBlob; overload;
566 function GetAsBlob(BPB: IBPB): IBlob; overload;
567 function GetAsArray: IArray;
568 function GetAsBCD: tBCD;
569 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 property AsString: AnsiString read GetAsString;
583 property AsVariant: Variant read GetAsVariant ;
584 property AsBlob: IBlob read GetAsBlob;
585 property AsArray: IArray read GetAsArray;
586 property AsBCD: tBCD read GetAsBCD;
587 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 ['{e836b2bb-93d1-4bbf-a8eb-7ce535de3bb5}']
599 function getCount: integer;
600 function GetStatement: IStatement;
601 function GetTransaction: ITransaction;
602 function ByName(Idx: AnsiString): ISQLData;
603 function getSQLData(index: integer): ISQLData;
604 procedure GetData(index: integer; var IsNull:boolean; var len: short; var data: PByte);
605 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 ['{0ae4979b-7857-4e8c-8918-ec6f155b51a0}']
617 function FetchNext: boolean;
618 function GetCursorName: AnsiString;
619 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. The interface comprises the Setter Methods and properties used to
625 set the value of each parameter.
626
627 Automatic conversion is provided to and from strings. That is GetAsString and
628 SetAsString are safe to use for sql types other than boolean - provided automatic
629 conversion is possible.
630
631 ISQLParam is subclassed from the IParamMetaData interface. This interface provides
632 access to the parameter metadata. This metadata is mutable and can change after
633 a parameter is set to a given value. This is acceptable as long as the parameter
634 metadata is type compatible with the underlying column metadata and hence the
635 parameter value can be converted by Firebird into a value acceptable by the
636 underlying column. The column metadata, which is unmutable, can be obtained
637 by the ISQLParam.getColMetadata interface. When a statement is prepared, the
638 parameter metadata is always initialised to the column metadata.
639 }
640
641 IParamMetaData = interface
642 ['{4e148c4e-2d48-4991-a263-f66eca05c6aa}']
643 function GetSQLType: cardinal;
644 function GetSQLTypeName: AnsiString;
645 function getSubtype: integer;
646 function getScale: integer;
647 function getCharSetID: cardinal;
648 function getCodePage: TSystemCodePage;
649 function getIsNullable: boolean;
650 function GetSize: cardinal;
651 property SQLType: cardinal read GetSQLType;
652 end;
653
654 ISQLParam = interface(IParamMetaData)
655 ['{b22b4578-6d41-4807-a9a9-d2ec8d1d5a14}']
656 function getColMetadata: IParamMetaData;
657 function GetIndex: integer;
658 function getName: AnsiString;
659 function GetAsBoolean: boolean;
660 function GetAsCurrency: Currency;
661 function GetAsInt64: Int64;
662 function GetAsDateTime: TDateTime; overload;
663 procedure GetAsDateTime(var aDateTime: TDateTime; var dstOffset: smallint; var aTimezoneID: TFBTimeZoneID); overload;
664 procedure GetAsDateTime(var aDateTime: TDateTime; var dstOffset: smallint; var aTimezone: AnsiString); overload;
665 procedure GetAsTime(var aTime: TDateTime; var dstOffset: smallint; var aTimezoneID: TFBTimeZoneID; OnDate: TDateTime); overload;
666 procedure GetAsTime(var aTime: TDateTime; var dstOffset: smallint; var aTimezone: AnsiString; OnDate: TDateTime); overload;
667 procedure GetAsTime(var aTime: TDateTime; var dstOffset: smallint; var aTimezoneID: TFBTimeZoneID); overload;
668 procedure GetAsTime(var aTime: TDateTime; var dstOffset: smallint; var aTimezone: AnsiString); overload;
669 function GetAsUTCDateTime: TDateTime;
670 function GetAsDouble: Double;
671 function GetAsFloat: Float;
672 function GetAsLong: Long;
673 function GetAsPointer: Pointer;
674 function GetAsQuad: TISC_QUAD;
675 function GetAsShort: short;
676 function GetAsString: AnsiString;
677 function GetIsNull: boolean;
678 function GetAsVariant: Variant;
679 function GetAsBlob: IBlob;
680 function GetAsArray: IArray;
681 function GetAsBCD: tBCD;
682 function GetStatement: IStatement;
683 function GetTransaction: ITransaction;
684 procedure Clear;
685 function GetModified: boolean;
686 procedure SetAsBoolean(AValue: boolean);
687 procedure SetAsCurrency(aValue: Currency);
688 procedure SetAsInt64(aValue: Int64);
689 procedure SetAsDate(aValue: TDateTime);
690 procedure SetAsLong(aValue: Long);
691 procedure SetAsTime(aValue: TDateTime); overload;
692 procedure SetAsTime(aValue: TDateTime; OnDate: TDateTime; aTimeZoneID: TFBTimeZoneID); overload;
693 procedure SetAsTime(aValue: TDateTime; OnDate: TDateTime; aTimeZone: AnsiString); overload;
694 procedure SetAsTime(aValue: TDateTime; aTimeZoneID: TFBTimeZoneID); overload;
695 procedure SetAsTime(aValue: TDateTime; aTimeZone: AnsiString); overload;
696 procedure SetAsDateTime(aValue: TDateTime); overload;
697 procedure SetAsDateTime(aValue: TDateTime; aTimeZoneID: TFBTimeZoneID); overload;
698 procedure SetAsDateTime(aValue: TDateTime; aTimeZone: AnsiString); overload;
699 procedure SetAsUTCDateTime(aUTCTime: TDateTime);
700 procedure SetAsDouble(aValue: Double);
701 procedure SetAsFloat(aValue: Float);
702 procedure SetAsPointer(aValue: Pointer);
703 procedure SetAsShort(aValue: Short);
704 procedure SetAsString(aValue: AnsiString);
705 procedure SetAsVariant(aValue: Variant);
706 procedure SetIsNull(aValue: Boolean);
707 procedure SetAsBlob(aValue: IBlob);
708 procedure SetAsArray(anArray: IArray);
709 procedure SetAsQuad(aValue: TISC_QUAD);
710 procedure SetCharSetID(aValue: cardinal);
711 procedure SetAsBcd(aValue: tBCD);
712 property AsDate: TDateTime read GetAsDateTime write SetAsDate;
713 property AsBoolean:boolean read GetAsBoolean write SetAsBoolean;
714 property AsTime: TDateTime read GetAsDateTime write SetAsTime;
715 property AsDateTime: TDateTime read GetAsDateTime write SetAsDateTime;
716 property AsDouble: Double read GetAsDouble write SetAsDouble;
717 property AsFloat: Float read GetAsFloat write SetAsFloat;
718 property AsCurrency: Currency read GetAsCurrency write SetAsCurrency;
719 property AsInt64: Int64 read GetAsInt64 write SetAsInt64;
720 property AsInteger: Integer read GetAsLong write SetAsLong;
721 property AsLong: Long read GetAsLong write SetAsLong;
722 property AsPointer: Pointer read GetAsPointer write SetAsPointer;
723 property AsShort: Short read GetAsShort write SetAsShort;
724 property AsString: AnsiString read GetAsString write SetAsString;
725 property AsVariant: Variant read GetAsVariant write SetAsVariant;
726 property AsBlob: IBlob read GetAsBlob write SetAsBlob;
727 property AsArray: IArray read GetAsArray write SetAsArray;
728 property AsBCD: tBCD read GetAsBCD write SetAsBCD;
729 property AsQuad: TISC_QUAD read GetAsQuad write SetAsQuad;
730 property Value: Variant read GetAsVariant write SetAsVariant;
731 property IsNull: Boolean read GetIsNull write SetIsNull;
732 property IsNullable: Boolean read GetIsNullable;
733 property Modified: Boolean read getModified;
734 property Name: AnsiString read GetName;
735 end;
736
737 {
738 The ISQLParams interface provides access to the collection of parameters used
739 for the input to an SQL Statement
740 }
741
742 ISQLParams = interface
743 ['{c6d95ac7-b2b7-461b-b890-afef0acbb077}']
744 function getCount: integer;
745 function getSQLParam(index: integer): ISQLParam;
746 function ByName(Idx: AnsiString): ISQLParam ;
747 function GetModified: Boolean;
748 function GetHasCaseSensitiveParams: Boolean;
749 property Modified: Boolean read GetModified;
750 property Params[index: integer]: ISQLParam read getSQLParam; default;
751 property Count: integer read getCount;
752 end;
753
754
755 TPerfStats = (psCurrentMemory, psMaxMemory,
756 psRealTime, psUserTime, psBuffers,
757 psReads, psWrites, psFetches,psDeltaMemory);
758
759 TPerfCounters = array[TPerfStats] of Int64;
760
761 {Batch Query Execution Support}
762
763 TBatchCompletionState = (bcExecuteFailed, bcSuccessNoInfo, bcNoMoreErrors);
764
765 IBatchCompletion = interface
766 ['{9bc3d49d-16d9-4606-94e5-ee987103ad92}']
767 function getTotalProcessed: cardinal;
768 function getState(updateNo: cardinal): TBatchCompletionState;
769 function getStatusMessage(updateNo: cardinal): AnsiString;
770 function getUpdated: integer;
771 function getErrorStatus(var RowNo: integer; var status: IStatus): boolean;
772 end;
773
774 {The IStatement interface provides access to an SQL Statement once it has been
775 initially prepared. The interface is returned from the IAttachment interface.
776 }
777
778 IStatement = interface
779 ['{a260576d-a07d-4a66-b02d-1b72543fd7cf}']
780 function GetMetaData: IMetaData; {Output Metadata}
781 function GetSQLParams: ISQLParams;{Statement Parameters}
782 function GetPlan: AnsiString;
783 function GetRowsAffected(var SelectCount, InsertCount, UpdateCount, DeleteCount: integer): boolean;
784 function GetSQLStatementType: TIBSQLStatementTypes;
785 function GetSQLStatementTypeName: AnsiString;
786 function GetSQLText: AnsiString;
787 function GetProcessedSQLText: AnsiString;
788 function GetSQLDialect: integer;
789 function IsPrepared: boolean;
790 function HasBatchMode: boolean;
791 function IsInBatchMode: boolean;
792 procedure Prepare(aTransaction: ITransaction=nil);
793 function Execute(aTransaction: ITransaction=nil): IResults;
794 function OpenCursor(aTransaction: ITransaction=nil): IResultSet;
795 function GetAttachment: IAttachment;
796 function GetTransaction: ITransaction;
797 procedure SetRetainInterfaces(aValue: boolean);
798 procedure EnableStatistics(aValue: boolean);
799 function GetPerfStatistics(var stats: TPerfCounters): boolean;
800 {IBatch interface support}
801 procedure AddToBatch;
802 function ExecuteBatch(aTransaction: ITransaction=nil): IBatchCompletion;
803 procedure CancelBatch;
804 function GetBatchCompletion: IBatchCompletion;
805 function GetBatchRowLimit: integer;
806 procedure SetBatchRowLimit(aLimit: integer);
807 {Stale Reference Check}
808 procedure SetStaleReferenceChecks(Enable:boolean); {default true}
809 function GetStaleReferenceChecks: boolean;
810
811 property MetaData: IMetaData read GetMetaData;
812 property SQLParams: ISQLParams read GetSQLParams;
813 property SQLStatementType: TIBSQLStatementTypes read GetSQLStatementType;
814 end;
815
816 {Transaction Parameter Block: (TPB)
817
818 The TPB provides the parameters used when starting a transaction. It is allocated
819 empty by the FirebirdAPI and the parameters are then added to it. Each individual
820 parameter may be accessed by the ITPBItem interface which can be used to set the
821 value, if any, of the parameter.
822
823 The TPB parameters, and the associated symbolic codes and parameter values may be
824 found in the Interbase 6.0 API Guide.
825 }
826
827 ITPBItem = interface(IParameterBlockItemWithTypeName)
828 ['{544c1f2b-7c12-4a87-a4a5-face7ea72671}']
829 function getParamTypeName: AnsiString;
830 end;
831
832 ITPB = interface(IParameterBlockWithTypeNames<ITPBItem>)
833 ['{7369b0ff-defe-437b-81fe-19b211d42d25}']
834 end;
835
836 {The ITransactionAction interface provides access to a Transaction once it
837 has been initially started. After a Commit or Rollback, a transaction
838 may be restarted, optinally with a new TPB.
839
840 A multi-database transaction is started from the FirebirdAPI. A single database
841 transaction is started from the IAttachment interface.
842 }
843
844 TTransactionAction = (TARollback, TACommit, TACommitRetaining, TARollbackRetaining);
845 TTransactionCompletion = TARollback.. TACommit;
846
847 ITransaction = interface
848 ['{30928d0e-a9d7-4c61-b7cf-14f4f38abe2a}']
849 function getTPB: ITPB;
850 procedure Start(DefaultCompletion: TTransactionCompletion=taCommit);
851 function GetInTransaction: boolean;
852 procedure PrepareForCommit; {Two phase commit - stage 1}
853 procedure Commit(Force: boolean=false);
854 procedure CommitRetaining;
855 function HasActivity: boolean;
856 procedure Rollback(Force: boolean=false);
857 procedure RollbackRetaining;
858 function GetAttachmentCount: integer;
859 function GetAttachment(index: integer): IAttachment;
860 property InTransaction: boolean read GetInTransaction;
861 end;
862
863 { The IEvents Interface is used to handle events from a single database. The
864 interface is allocated from the IAttachment Interface.
865
866 Note that the EventHandler called when an event occurs following AsynWaitForEvent
867 is called in a different thread to the calling program and TThread.Synchronize
868 may be needed to pass the event back to the main thread.
869
870 Neither AsyncWaitForEvent nor WaitForEvent is intended to be thread safe
871 in a multi-threaded environment and should always be called from the main
872 thread.
873 }
874
875 TEventInfo = record
876 EventName: AnsiString;
877 Count: integer;
878 end;
879
880 TEventCounts = array of TEventInfo;
881 IEvents = interface;
882 TEventHandler = procedure(Sender: IEvents) of object;
883
884 { IEvents }
885
886 IEvents = interface
887 ['{6a0be233-ed08-4524-889c-2e45d0c20e5f}']
888 procedure GetEvents(EventNames: TStrings);
889 procedure SetEvents(EventNames: TStrings); overload;
890 procedure SetEvents(EventName: AnsiString); overload;
891 procedure Cancel;
892 function ExtractEventCounts: TEventCounts;
893 procedure WaitForEvent;
894 procedure AsyncWaitForEvent(EventHandler: TEventHandler);
895 function GetAttachment: IAttachment;
896 end;
897
898 TTZTextOptions = (tzOffset, {Time Zone Rendered as an offset to GMT}
899 tzGMT, {No Time Zone. Time part is always rendered in GMT}
900 tzOriginalID); {Time Zone shown as originally entered}
901
902 {The ITimeZoneServices interface provides access to the time zone database
903 used for the attachment. It may be used in support of TIMESTAMP WITH TIME ZONE
904 and TIME WITH TIME ZONE data types.}
905
906 ITimeZoneServices = interface
907 ['{163821f5-ebef-42b9-ac60-8ac4b5c09954}']
908 {utility functions}
909 function TimeZoneID2TimeZoneName(aTimeZoneID: TFBTimeZoneID): AnsiString;
910 function TimeZoneName2TimeZoneID(aTimeZone: AnsiString): TFBTimeZoneID;
911 function LocalTimeToGMT(aLocalTime: TDateTime; aTimeZone: AnsiString): TDateTime; overload;
912 function LocalTimeToGMT(aLocalTime: TDateTime; aTimeZoneID: TFBTimeZoneID): TDateTime; overload;
913 function GMTToLocalTime(aGMTTime: TDateTime; aTimeZone: AnsiString): TDateTime; overload;
914 function GMTToLocalTime(aGMTTime: TDateTime; aTimeZoneID: TFBTimeZoneID): TDateTime; overload;
915 function GetEffectiveOffsetMins(aLocalTime: TDateTime; aTimeZone: AnsiString): integer; overload;
916 function GetEffectiveOffsetMins(aLocalTime: TDateTime; aTimeZoneID: TFBTimeZoneID): integer; overload;
917
918 {Time Zone DB Information}
919 function UsingRemoteTZDB: boolean;
920 procedure SetUseLocalTZDB(useLocalTZDB: boolean);
921 function GetLocalTimeZoneName: AnsiString;
922 function GetLocalTimeZoneID: TFBTimeZoneID;
923 procedure GetTimeZoneInfo(aTimeZone: AnsiString; OnDate: TDateTime;
924 var ZoneOffset, DSTOffset, EffectiveOffset: integer);
925 {Configurable Options}
926 function GetTimeTZDate: TDateTime;
927 procedure SetTimeTZDate(aDate: TDateTime);
928 function GetTZTextOption: TTZTextOptions;
929 procedure SetTZTextOption(aOptionValue: TTZTextOptions);
930 end;
931
932 {The IDBInformation Interface.
933
934 An IDBInformation interface is returned by the IAttachment GetDBInformation
935 method. The interface provides access to the information requested and
936 returned by the method.
937
938 IDBInformation itself gives access to a collection of IDBInfoItems. Each one
939 provides information requested, as indicated by the ItemType and the actual
940 value of the information. In some cases, the returned item is itself a
941 colletion of IDBInfoItems.
942
943 The IDBInformation items, and the associated symbolic codes and parameter values may be
944 found in the Interbase 6.0 API Guide.
945 }
946
947 TDBOperationCount = record
948 TableID: UShort;
949 Count: cardinal;
950 end;
951
952 TDBOperationCounts = array of TDBOperationCount;
953
954 IDBInfoItem = interface
955 ['{eeb97b51-ec0f-473f-9f75-c1721f055fcb}']
956 function getItemType: byte;
957 function getSize: integer;
958 procedure getRawBytes(var Buffer);
959 function getAsString: AnsiString;
960 function getAsInteger: int64;
961 procedure DecodeIDCluster(var ConnectionType: integer; var DBFileName, DBSiteName: AnsiString);
962 function getAsBytes: TByteArray;
963 function getAsDateTime: TDateTime;
964 procedure DecodeVersionString(var Version: byte; var VersionString: AnsiString);
965 function getOperationCounts: TDBOperationCounts;
966 procedure DecodeUserNames(UserNames: TStrings);
967
968 {user names only}
969 function GetCount: integer;
970 function GetItem(index: integer): IDBInfoItem;
971 function Find(ItemType: byte): IDBInfoItem;
972 property AsInteger: int64 read getAsInteger;
973 property AsString: AnsiString read GetAsString;
974 property Count: integer read GetCount;
975 property Items[index: integer]: IDBInfoItem read getItem; default;
976 end;
977
978 { IDBInformation }
979
980 IDBInformation = interface
981 ['{7ac6777f-f0a9-498a-9f5c-4a57a554df81}']
982 function GetCount: integer;
983 function GetItem(index: integer): IDBInfoItem;
984 function Find(ItemType: byte): IDBInfoItem;
985 procedure PrintBuf; {can be used to print buffer in hex for debugging}
986 property Count: integer read GetCount;
987 property Items[index: integer]: IDBInfoItem read getItem; default;
988 end;
989
990 {The Database Information Request Block is used to pass requests for
991 database information where at least one item requested has a parameter.
992 At present, this is only fb_info_page_contents which has a single
993 integer parameter.}
994
995 IDIRBItem = interface(IParameterBlockItem)
996 ['{d34a7511-8435-4a24-81a7-5103d218d234}']
997 end;
998
999 IDIRB = interface(IParameterBlock<IDIRBItem>)
1000 ['{1010e5ac-0a8f-403b-a302-91625e9d9579}']
1001 end;
1002
1003
1004 {The Database Parameter Block (DPB).
1005
1006 The DPB provides the parameters used when connecting to a database. It is allocated
1007 empty by the FirebirdAPI and the parameters are then added to it. Each individual
1008 parameter may be accessed by the IDPBItem interface which can be used to set the
1009 value, if any, of the parameter.
1010
1011 The DPB parameters, and the associated symbolic codes and parameter values may be
1012 found in the Interbase 6.0 API Guide.
1013 }
1014
1015 IDPBItem = interface(IParameterBlockItemWithTypeName)
1016 ['{123d4ad0-087a-4cd1-a344-1b3d03b30673}']
1017 end;
1018
1019 IDPB = interface(IParameterBlockWithTypeNames<IDPBItem>)
1020 ['{e676067b-1cf4-4eba-9256-9724f57e0d16}']
1021 end;
1022
1023 {The IAttachment interface provides access to a Database Connection. It may be
1024 used to:
1025
1026 a. Disconnect and reconnect to the database.
1027
1028 b. Start a Transaction on the database
1029
1030 c. Execute directly SQL DDL Statements and others that return no information.
1031
1032 d. OpenCursors (i.e. execute SQL Select statements and return the results)
1033
1034 e. Prepare SQL Statements, returning an IStatement interface for further processing.
1035
1036 f. Provide access to an SQL Event Handler.
1037
1038 g. Access Database Information.
1039
1040 h. Support the handling of Array and Blob data.
1041
1042 Note that SQL statements can be prepared with named parameters (PSQL style).
1043 This then allows the parameters to be accessed by name. The same name can
1044 be used for more than one parameter, allowing a single operation to be used
1045 to set all parameters with the same name.
1046 }
1047
1048 { IAttachment }
1049
1050 IAttachment = interface
1051 ['{466e9b67-9def-4807-b3e7-e08a35e7185c}']
1052 function getFirebirdAPI: IFirebirdAPI;
1053 function getDPB: IDPB;
1054 function AllocateBPB: IBPB;
1055 function AllocateDIRB: IDIRB;
1056 procedure Connect;
1057 procedure Disconnect(Force: boolean=false);
1058 function IsConnected: boolean;
1059 procedure DropDatabase;
1060 function StartTransaction(TPB: array of byte; DefaultCompletion: TTransactionCompletion=taCommit): ITransaction; overload;
1061 function StartTransaction(TPB: ITPB; DefaultCompletion: TTransactionCompletion=taCommit): ITransaction; overload;
1062 procedure ExecImmediate(transaction: ITransaction; sql: AnsiString; SQLDialect: integer); overload;
1063 procedure ExecImmediate(TPB: array of byte; sql: AnsiString; SQLDialect: integer); overload;
1064 procedure ExecImmediate(transaction: ITransaction; sql: AnsiString); overload;
1065 procedure ExecImmediate(TPB: array of byte; sql: AnsiString); overload;
1066 function ExecuteSQL(TPB: array of byte; sql: AnsiString; SQLDialect: integer; params: array of const): IResults; overload;
1067 function ExecuteSQL(transaction: ITransaction; sql: AnsiString; SQLDialect: integer; params: array of const): IResults; overload;
1068 function ExecuteSQL(TPB: array of byte; sql: AnsiString; params: array of const): IResults; overload;
1069 function ExecuteSQL(transaction: ITransaction; sql: AnsiString; params: array of const): IResults; overload;
1070 function OpenCursor(transaction: ITransaction; sql: AnsiString; aSQLDialect: integer): IResultSet; overload;
1071 function OpenCursor(transaction: ITransaction; sql: AnsiString; aSQLDialect: integer;
1072 params: array of const): IResultSet; overload;
1073 function OpenCursor(transaction: ITransaction; sql: AnsiString): IResultSet; overload;
1074 function OpenCursor(transaction: ITransaction; sql: AnsiString;
1075 params: array of const): IResultSet; overload;
1076 function OpenCursorAtStart(transaction: ITransaction; sql: AnsiString; aSQLDialect: integer): IResultSet; overload;
1077 function OpenCursorAtStart(transaction: ITransaction; sql: AnsiString; aSQLDialect: integer;
1078 params: array of const): IResultSet; overload;
1079 function OpenCursorAtStart(transaction: ITransaction; sql: AnsiString): IResultSet; overload;
1080 function OpenCursorAtStart(transaction: ITransaction; sql: AnsiString;
1081 params: array of const): IResultSet; overload;
1082 function OpenCursorAtStart(sql: AnsiString): IResultSet; overload;
1083 function OpenCursorAtStart(sql: AnsiString;
1084 params: array of const): IResultSet; overload;
1085 function Prepare(transaction: ITransaction; sql: AnsiString; aSQLDialect: integer): IStatement; overload;
1086 function Prepare(transaction: ITransaction; sql: AnsiString): IStatement; overload;
1087 function PrepareWithNamedParameters(transaction: ITransaction; sql: AnsiString;
1088 aSQLDialect: integer; GenerateParamNames: boolean=false;
1089 CaseSensitiveParams: boolean = false): IStatement; overload;
1090 function PrepareWithNamedParameters(transaction: ITransaction; sql: AnsiString;
1091 GenerateParamNames: boolean=false;
1092 CaseSensitiveParams: boolean = false): IStatement; overload;
1093
1094 {Events}
1095 function GetEventHandler(Events: TStrings): IEvents; overload;
1096 function GetEventHandler(Event: AnsiString): IEvents; overload;
1097
1098 {Blob - may use to open existing Blobs. However, ISQLData.AsBlob is preferred}
1099
1100 function CreateBlob(transaction: ITransaction; RelationName, ColumnName: AnsiString; BPB: IBPB=nil): IBlob; overload;
1101 function CreateBlob(transaction: ITransaction; BlobMetaData: IBlobMetaData; BPB: IBPB=nil): IBlob; overload;
1102 function CreateBlob(transaction: ITransaction; SubType: integer; CharSetID: cardinal=0; BPB: IBPB=nil): IBlob; overload;
1103 function OpenBlob(transaction: ITransaction; RelationName, ColumnName: AnsiString; BlobID: TISC_QUAD; BPB: IBPB=nil): IBlob; overload;
1104 function OpenBlob(transaction: ITransaction; BlobMetaData: IBlobMetaData; BlobID: TISC_QUAD; BPB: IBPB=nil): IBlob; overload;
1105 function GetInlineBlobLimit: integer;
1106 procedure SetInlineBlobLimit(limit: integer);
1107
1108 {Array - may use to open existing arrays. However, ISQLData.AsArray is preferred}
1109
1110 function OpenArray(transaction: ITransaction; RelationName, ColumnName: AnsiString; ArrayID: TISC_QUAD): IArray; overload;
1111 function OpenArray(transaction: ITransaction; ArrayMetaData: IArrayMetaData; ArrayID: TISC_QUAD): IArray; overload;
1112 function CreateArray(transaction: ITransaction; RelationName, ColumnName: AnsiString): IArray; overload;
1113 function CreateArray(transaction: ITransaction; ArrayMetaData: IArrayMetaData): IArray; overload;
1114 function CreateArrayMetaData(SQLType: cardinal; tableName: AnsiString; columnName: AnsiString;
1115 Scale: integer; size: cardinal; charSetID: cardinal; dimensions: cardinal;
1116 bounds: TArrayBounds): IArrayMetaData;
1117
1118 {Database Information}
1119 function GetSQLDialect: integer;
1120 function GetBlobMetaData(Transaction: ITransaction; tableName, columnName: AnsiString): IBlobMetaData;
1121 function GetArrayMetaData(Transaction: ITransaction; tableName, columnName: AnsiString): IArrayMetaData;
1122 function GetDBInformation(Requests: array of byte): IDBInformation; overload;
1123 function GetDBInformation(Request: byte): IDBInformation; overload;
1124 function GetDBInformation(Requests: IDIRB): IDBInformation; overload;
1125 function GetConnectString: AnsiString;
1126 function GetRemoteProtocol: AnsiString;
1127 function GetAuthenticationMethod: AnsiString;
1128 function GetSecurityDatabase: AnsiString;
1129 function GetODSMajorVersion: integer;
1130 function GetODSMinorVersion: integer;
1131 procedure getFBVersion(version: TStrings);
1132 function HasActivity: boolean;
1133 function HasDecFloatSupport: boolean;
1134 function HasBatchMode: boolean;
1135
1136 {Character Sets}
1137 function HasDefaultCharSet: boolean;
1138 function GetDefaultCharSetID: integer;
1139 function GetCharsetName(CharSetID: integer): AnsiString;
1140 function CharSetID2CodePage(CharSetID: integer; var CodePage: TSystemCodePage): boolean;
1141 function CodePage2CharSetID(CodePage: TSystemCodePage; var CharSetID: integer): boolean;
1142 function CharSetName2CharSetID(CharSetName: AnsiString; var CharSetID: integer): boolean;
1143 function CharSetWidth(CharSetID: integer; var Width: integer): boolean;
1144 procedure RegisterCharSet(CharSetName: AnsiString; CodePage: TSystemCodePage;
1145 AllowReverseLookup:boolean; out CharSetID: integer);
1146
1147 {Time Zone Database}
1148 function GetTimeZoneServices: ITimeZoneServices;
1149 function HasTimeZoneSupport: boolean;
1150 end;
1151
1152 TProtocolAll = (TCP, SPX, NamedPipe, Local, inet, inet4, inet6, wnet, xnet, unknownProtocol);
1153 TProtocol = TCP..xnet;
1154
1155 {Service Parameter Block (SPB).
1156
1157 The SPB provides the parameters used when connecting to a Service Manager. It is
1158 allocated empty by the FirebirdAPI and the parameters are then added to it. Each
1159 individual parameter may be accessed by the ISPBItem interface which can be used
1160 to set the value, if any, of the parameter.
1161
1162 The SPB parameters, and the associated symbolic codes and parameter values may be
1163 found in the Interbase 6.0 API Guide.
1164
1165 }
1166
1167 ISPBItem = interface(IParameterBlockItemWithTypeName)
1168 ['{5d08ae2b-4519-41bd-8b40-97cd451c3f6a}']
1169 end;
1170
1171 ISPB = interface(IParameterBlockWithTypeNames<ISPBItem>)
1172 ['{2c5836fd-41ed-4426-9b7d-5af580ec2659}']
1173 end;
1174
1175 {Service Query Parameter Block (SQPB).
1176
1177 This is a specialised parameter block used to send data to a service manager
1178 in a Query Request.
1179 }
1180
1181 ISQPBItem = interface(IParameterBlockItem)
1182 ['{b07841a6-33b3-47f0-b5a2-028cbc86dc97}']
1183 function CopyFrom(source: TStream; count: integer): integer;
1184 end;
1185
1186 ISQPB = interface(IParameterBlock<ISQPBItem>)
1187 ['{8553e66b-ee62-498b-8431-dff030211447}']
1188 end;
1189
1190 {Service Request Block (SRB).
1191
1192 The SRB specifies what is requested from the Service Manager when starting a
1193 service or querying a service. It is allocated empty by the ServiceManager API and
1194 the parameters are then added to it. Each individual parameter may be accessed
1195 by the ISRBItem interface which can be used to set the value, if any, of the parameter.
1196
1197 The SRB parameters, and the associated symbolic codes and parameter values may be
1198 found in the Interbase 6.0 API Guide.
1199
1200 }
1201
1202 ISRBItem = interface(IParameterBlockItem)
1203 ['{47ec790e-f265-4b30-9dcd-261e51677245}']
1204 end;
1205
1206 ISRB = interface(IParameterBlock<ISRBItem>)
1207 ['{9f2e204f-3c33-4e44-90f9-9135e95dafb9}']
1208 end;
1209
1210 {The Service Query Results Interface.
1211
1212 An IServiceQueryResults interface is returned by the IServiceManager Query
1213 method. The interface provides access to the information requested and
1214 returned by the method.
1215
1216 IServiceQueryResults itself gives access to a collection of IServiceQueryResultItem.
1217 Each one provides information requested, as indicated by the ItemType and the actual
1218 value of the information. In some cases, the returned item is itself a
1219 collection of IServiceQueryResultSubItem.
1220
1221 The IServiceQueryResultItem items, and the associated symbolic codes and parameter values may be
1222 found in the Interbase 6.0 API Guide.
1223 }
1224
1225 IServiceQueryResultSubItem = interface
1226 ['{8a4c381e-9923-4cc9-a96b-553729248640}']
1227 function getItemType: byte;
1228 function getSize: integer;
1229 procedure getRawBytes(var Buffer);
1230 function getAsString: AnsiString;
1231 function getAsInteger: int64;
1232 function getAsByte: byte;
1233 function CopyTo(stream: TStream; count: integer): integer;
1234 property AsString: AnsiString read getAsString;
1235 property AsInteger: int64 read getAsInteger;
1236 property AsByte: byte read getAsByte;
1237 end;
1238
1239 IServiceQueryResultItem = interface(IServiceQueryResultSubItem)
1240 ['{b2806886-206c-4024-8df9-5fe0a7630a5e}']
1241 function getCount: integer;
1242 function getItem(index: integer): IServiceQueryResultSubItem;
1243 function find(ItemType: byte): IServiceQueryResultSubItem;
1244 property Items[index: integer]: IServiceQueryResultSubItem read getItem; default;
1245 property Count: integer read getCount;
1246 end;
1247
1248 IServiceQueryResults = interface
1249 ['{8fbbef7d-fe03-4409-828a-a787d34ef531}']
1250 function getCount: integer;
1251 function getItem(index: integer): IServiceQueryResultItem;
1252 function find(ItemType: byte): IServiceQueryResultItem;
1253 procedure PrintBuf; {can be used to print buffer in hex for debugging}
1254 property Items[index: integer]: IServiceQueryResultItem read getItem; default;
1255 property Count: integer read getCount;
1256 end;
1257
1258 IFirebirdLibrary = interface;
1259
1260 {The IServiceManager interface provides access to a service manager. It can
1261 used to Detach and re-attach to Service Manager, to start services and to
1262 query the service manager.
1263
1264 The interface is returned by the FirebirdAPI GetService Manager method.
1265 }
1266
1267 { IServiceManager }
1268
1269 IServiceManager = interface
1270 ['{905b587d-1e1f-4e40-a3f8-a3519f852e48}']
1271 function getFirebirdAPI: IFirebirdAPI;
1272 function getSPB: ISPB;
1273 function getServerName: AnsiString;
1274 function getProtocol: TProtocol;
1275 function getPortNo: AnsiString;
1276 procedure Attach;
1277 procedure Detach(Force: boolean=false);
1278 function IsAttached: boolean;
1279 function AllocateSRB: ISRB;
1280 function AllocateSQPB: ISQPB;
1281 function Start(Request: ISRB; RaiseExceptionOnError: boolean=true): boolean;
1282 function Query(SQPB: ISQPB; Request: ISRB; RaiseExceptionOnError: boolean=true) :IServiceQueryResults; overload;
1283 function Query(Request: ISRB; RaiseExceptionOnError: boolean=true) :IServiceQueryResults; overload;
1284 end;
1285
1286 {Tbe Firebird Library API used to get information about the Firebird library}
1287
1288
1289 IFirebirdLibrary = interface
1290 ['{3c04e0a1-12e0-428a-b2e1-bc6fcd97b79b}']
1291 function GetHandle: TLibHandle;
1292 function GetLibraryName: string;
1293 function GetLibraryFilePath: string;
1294 function GetFirebirdAPI: IFirebirdAPI;
1295 end;
1296
1297 {The Firebird API.
1298
1299 This is the base interface and is used to create/open a database connection, to
1300 start a transaction on multiple databases and the access the service manager.
1301
1302 The interface is returned by the FirebirdAPI function.
1303 }
1304
1305 { IFirebirdAPI }
1306
1307 IFirebirdAPI = interface
1308 ['{edeee691-c8d3-4dcf-a780-cd7e432821d5}']
1309 {Database connections}
1310 function AllocateDPB: IDPB;
1311 function OpenDatabase(DatabaseName: AnsiString; DPB: IDPB; RaiseExceptionOnConnectError: boolean=true): IAttachment;
1312 function CreateDatabase(DatabaseName: AnsiString; DPB: IDPB; RaiseExceptionOnError: boolean=true): IAttachment; overload;
1313 function CreateDatabase(sql: AnsiString; aSQLDialect: integer; RaiseExceptionOnError: boolean=true): IAttachment; overload;
1314
1315 {Start Transaction against multiple databases}
1316 function AllocateTPB: ITPB;
1317 function StartTransaction(Attachments: array of IAttachment;
1318 TPB: array of byte; DefaultCompletion: TTransactionCompletion=taCommit): ITransaction; overload;
1319 function StartTransaction(Attachments: array of IAttachment;
1320 TPB: ITPB; DefaultCompletion: TTransactionCompletion=taCommit): ITransaction; overload;
1321
1322 {Service Manager}
1323 function HasServiceAPI: boolean;
1324 function AllocateSPB: ISPB;
1325 function GetServiceManager(ServerName: AnsiString; Protocol: TProtocol; SPB: ISPB): IServiceManager; overload;
1326 function GetServiceManager(ServerName: AnsiString; Port: AnsiString; Protocol: TProtocol; SPB: ISPB): IServiceManager; overload;
1327
1328 {Information}
1329 function GetStatus: IStatus;
1330 function HasRollbackRetaining: boolean;
1331 function IsEmbeddedServer: boolean;
1332 function GetImplementationVersion: AnsiString;
1333 function GetClientMajor: integer;
1334 function GetClientMinor: integer;
1335 function HasDecFloatSupport: boolean;
1336 function HasLocalTZDB: boolean;
1337 function HasTimeZoneSupport: boolean;
1338 function HasExtendedTZSupport: boolean;
1339
1340 {Firebird 3 API}
1341 function HasMasterIntf: boolean;
1342 function GetIMaster: TObject; deprecated 'Use FirebirdAPI.QueryInterface and FBClientLib.pas IFBIMasterProvider instead';
1343 function GetFBLibrary: IFirebirdLibrary;
1344 end;
1345
1346 type
1347 TOnGetLibraryName = procedure(var libname: string);
1348
1349 const
1350 OnGetLibraryName: TOnGetLibraryName = nil;
1351 AllowUseOfFBLIB: boolean = false;
1352
1353 type
1354 { EIBError }
1355
1356 EIBError = class(EDatabaseError)
1357 private
1358 FSQLCode: Long;
1359 public
1360 constructor Create(ASQLCode: Long; Msg: AnsiString);
1361 property SQLCode: Long read FSQLCode;
1362 end;
1363
1364 { EIBInterBaseError - Firebird Engine errors}
1365
1366 EIBInterBaseError = class(EIBError)
1367 private
1368 FIBErrorCode: Long;
1369 public
1370 constructor Create(Status: IStatus); overload;
1371 constructor Create(ASQLCode: Long; AIBErrorCode: Long; Msg: AnsiString); overload;
1372 property IBErrorCode: Long read FIBErrorCode;
1373 end;
1374
1375 {IB Client Exceptions}
1376 EIBClientError = class(EIBError);
1377
1378 {Used to explicitly report a Batch Buffer overflow}
1379 EIBBatchBufferOverflow = class(EIBError);
1380
1381 {The Firebird API function is used to access the IFirebirdAPI interface.
1382
1383 It will load the Firebird Client Library if this is not already loaded and
1384 select an implementation of the Firebird API (legacy 2.5 or 3.0.
1385 }
1386
1387 function FirebirdAPI: IFirebirdAPI;
1388
1389 {IBX support functions. Probably best ignored i.e. always used the FirebirdAPI
1390 function to load the library and check if it's loaded.}
1391
1392 function TryIBLoad: Boolean;
1393 procedure CheckIBLoaded;
1394
1395 {If you want to explicitly load the Firebird library from a
1396 non-default location then use this function and its GetFirebirdAPI function
1397 to get the API.}
1398
1399 function LoadFBLibrary(aLibPathName: string): IFirebirdLibrary;
1400
1401
1402 implementation
1403
1404 uses FBClientAPI
1405 {$IFDEF USELEGACYFIREBIRDAPI}, FB25ClientAPI {$ENDIF}
1406 {$IFDEF USEFIREBIRD3API}, FB30ClientAPI {$ENDIF};
1407
1408 var FDefaultFBLibrary: IFirebirdLibrary;
1409
1410 type
1411
1412 { TFBLibrary }
1413
1414 TFBLibraryImpl = class(TFBLibrary)
1415 protected
1416 function GetFirebird3API: IFirebirdAPI; override;
1417 function GetLegacyFirebirdAPI: IFirebirdAPI; override;
1418 end;
1419
1420 function TFBLibraryImpl.GetFirebird3API: IFirebirdAPI;
1421 begin
1422 {$IFDEF USEFIREBIRD3API}
1423 Result := TFB30ClientAPI.Create(self);
1424 {$ELSE}
1425 Result := nil;
1426 {$ENDIF}
1427 end;
1428
1429 function TFBLibraryImpl.GetLegacyFirebirdAPI: IFirebirdAPI;
1430 begin
1431 {$IFDEF USELEGACYFIREBIRDAPI}
1432 Result := TFB25ClientAPI.Create(self);
1433 {$ELSE}
1434 Result := nil;
1435 {$ENDIF}
1436 end;
1437
1438 function FirebirdAPI: IFirebirdAPI;
1439 begin
1440 if FDefaultFBLibrary = nil then
1441 CheckIBLoaded;
1442 Result := FDefaultFBLibrary.GetFirebirdAPI;
1443 end;
1444
1445 function TryIBLoad: Boolean;
1446 var fblib: IFirebirdLibrary;
1447 begin
1448 Result := FDefaultFBLibrary <> nil;
1449 try
1450 if not Result then
1451 begin
1452 fblib := TFBLibraryImpl.Create;
1453 if (fblib <> nil) and (fblib.GetFirebirdAPI <> nil) then
1454 FDefaultFBLibrary := fblib;
1455 Result := FDefaultFBLibrary <> nil;
1456 end;
1457 except
1458 SysUtils.showexception(ExceptObject,ExceptAddr);
1459 Result := false;
1460 end;
1461 end;
1462
1463 procedure CheckIBLoaded;
1464 begin
1465 if not TryIBLoad then
1466 IBError(ibxeInterBaseMissing, [nil]);
1467 end;
1468
1469 function LoadFBLibrary(aLibPathName: string): IFirebirdLibrary;
1470 var fblib: IFirebirdLibrary;
1471 begin
1472 if trim(aLibPathName) = '' then
1473 begin
1474 CheckIBLoaded;
1475 Result := FDefaultFBLibrary;
1476 end
1477 else
1478 begin
1479 fblib := TFBLibraryImpl.GetFBLibrary(aLibPathName);
1480 if (fblib = nil) or (fblib.GetFirebirdAPI = nil) then
1481 IBError(ibxeInterBaseMissing, [nil]);
1482 Result := fblib;
1483 end;
1484 end;
1485
1486 { EIBError }
1487
1488 constructor EIBError.Create(ASQLCode: Long; Msg: AnsiString);
1489 begin
1490 inherited Create(Msg);
1491 FSQLCode := ASQLCode;
1492 end;
1493
1494 { EIBInterBaseError }
1495
1496 constructor EIBInterBaseError.Create(Status: IStatus);
1497 begin
1498 inherited Create(Status.Getsqlcode,Status.GetMessage);
1499 FIBErrorCode := Status.GetIBErrorCode;
1500 end;
1501
1502 constructor EIBInterBaseError.Create(ASQLCode: Long; AIBErrorCode: Long;
1503 Msg: AnsiString);
1504 begin
1505 inherited Create(ASQLCode,Msg);
1506 FIBErrorCode := AIBErrorCode;
1507 end;
1508
1509
1510 initialization
1511 FDefaultFBLibrary := nil;
1512
1513 finalization
1514 FDefaultFBLibrary := nil;
1515
1516 end.
1517