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