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