ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/branches/udr/client/IB.pas
Revision: 338
Committed: Wed Jun 9 12:07:56 2021 UTC (3 years, 5 months ago) by tony
Content type: text/x-pascal
Original Path: ibx/trunk/fbintf/IB.pas
File size: 60937 byte(s)
Log Message:
Merge Fixes

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