00001 {*********************************************************}
00002 { }
00003 { Zeos Database Objects }
00004 { Delphi interface to gds32.dll }
00005 { from Firebird }
00006 { }
00007 { Originally written by Sergey Seroukhov }
00008 { }
00009 {*********************************************************}
00010
00011 {@********************************************************}
00012 { Copyright (c) 1999-2006 Zeos Development Group }
00013 { }
00014 { License Agreement: }
00015 { }
00016 { This library is distributed in the hope that it will be }
00017 { useful, but WITHOUT ANY WARRANTY; without even the }
00018 { implied warranty of MERCHANTABILITY or FITNESS FOR }
00019 { A PARTICULAR PURPOSE. See the GNU Lesser General }
00020 { Public License for more details. }
00021 { }
00022 { The source code of the ZEOS Libraries and packages are }
00023 { distributed under the Library GNU General Public }
00024 { License (see the file COPYING / COPYING.ZEOS) }
00025 { with the following modification: }
00026 { As a special exception, the copyright holders of this }
00027 { library give you permission to link this library with }
00028 { independent modules to produce an executable, }
00029 { regardless of the license terms of these independent }
00030 { modules, and to copy and distribute the resulting }
00031 { executable under terms of your choice, provided that }
00032 { you also meet, for each linked independent module, }
00033 { the terms and conditions of the license of that module. }
00034 { An independent module is a module which is not derived }
00035 { from or based on this library. If you modify this }
00036 { library, you may extend this exception to your version }
00037 { of the library, but you are not obligated to do so. }
00038 { If you do not wish to do so, delete this exception }
00039 { statement from your version. }
00040 { }
00041 { }
00042 { The project web site is located on: }
00043 { http:
00044 { http:
00045 { svn:
00046 { }
00047 { http:
00048 { http:
00049 { }
00050 { }
00051 { }
00052 { Zeos Development Group. }
00053 {********************************************************@}
00054
00055 unit ZPlainFirebird21;
00056
00057 interface
00058
00059 {$I ZPlain.inc}
00060
00061 {$J+}
00062
00063 uses
00064 {$IFNDEF VER130BELOW}
00065 Types,
00066 {$ENDIF}
00067 ZCompatibility, ZPlainLoader, ZPlainFirebirdInterbaseConstants,
00068 ZPlainFirebirdDriver;
00069
00070 { ***************** Plain API Constants definition **************** }
00071
00072 const
00073 WINDOWS1_DLL_LOCATION = 'fbclient21.dll';
00074 WINDOWS1_DLL_LOCATION_EMBEDDED = 'fbclientd21.dll';
00075
00076 LINUX1_DLL_LOCATION = 'libfbclient.so.21';
00077 LINUX1_DLL_LOCATION_EMBEDDED = 'libfbembed.so.21';
00078 LINUX1_IB_CRYPT_LOCATION = 'libcrypt.so.21';
00079
00080 type
00081
00082 { ************** Plain API Function types definition ************* }
00083
00084 { General database routines }
00085
00086 Tisc_attach_database = function(status_vector: PISC_STATUS;
00087 db_name_length: Short; db_name: PChar; db_handle: PISC_DB_HANDLE;
00088 parm_buffer_length: Short; parm_buffer: PChar): ISC_STATUS;
00089 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00090
00091 Tisc_detach_database = function(status_vector: PISC_STATUS;
00092 db_handle: PISC_DB_HANDLE): ISC_STATUS;
00093 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00094
00095 Tisc_drop_database = function(status_vector: PISC_STATUS;
00096 db_handle: PISC_DB_HANDLE): ISC_STATUS;
00097 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00098
00099 Tisc_database_info = function(status_vector: PISC_STATUS;
00100 db_handle: PISC_DB_HANDLE; item_list_buffer_length: Short;
00101 item_list_buffer: PChar; result_buffer_length: Short;
00102 result_buffer: PChar): ISC_STATUS;
00103 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00104
00105
00106 { Array processing routines }
00107 Tisc_array_gen_sdl = function(status_vector: PISC_STATUS;
00108 isc_array_desc: PISC_ARRAY_DESC; isc_arg3: PShort;
00109 isc_arg4: PChar; isc_arg5: PShort): ISC_STATUS;
00110 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00111
00112 Tisc_array_get_slice = function(status_vector: PISC_STATUS;
00113 db_handle: PISC_DB_HANDLE; trans_handle: PISC_TR_HANDLE;
00114 array_id: PISC_QUAD; descriptor: PISC_ARRAY_DESC;
00115 dest_array: PVoid; slice_length: ISC_LONG): ISC_STATUS;
00116 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00117
00118 Tisc_array_lookup_bounds = function(status_vector: PISC_STATUS;
00119 db_handle: PISC_DB_HANDLE; trans_handle: PISC_TR_HANDLE;
00120 table_name, column_name: PChar;
00121 descriptor: PISC_ARRAY_DESC): ISC_STATUS;
00122 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00123
00124 Tisc_array_lookup_desc = function(status_vector: PISC_STATUS;
00125 db_handle: PISC_DB_HANDLE; trans_handle: PISC_TR_HANDLE;
00126 table_name, column_name: PChar;
00127 descriptor: PISC_ARRAY_DESC): ISC_STATUS;
00128 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00129
00130 Tisc_array_set_desc = function(status_vector: PISC_STATUS;
00131 table_name: PChar; column_name: PChar;
00132 sql_dtype, sql_length, sql_dimensions: PShort;
00133 descriptor: PISC_ARRAY_DESC): ISC_STATUS;
00134 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00135
00136 Tisc_array_put_slice = function(status_vector: PISC_STATUS;
00137 db_handle: PISC_DB_HANDLE; trans_handle: PISC_TR_HANDLE;
00138 array_id: PISC_QUAD; descriptor: PISC_ARRAY_DESC;
00139 source_array: PVoid; slice_length: PISC_LONG): ISC_STATUS;
00140 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00141
00142 Tisc_free = function(isc_arg1: PChar): ISC_LONG;
00143 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00144
00145 Tisc_sqlcode = function(status_vector: PISC_STATUS): ISC_LONG;
00146 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00147
00148 Tisc_sql_interprete = procedure(sqlcode: Short; buffer: PChar;
00149 buffer_length: Short); {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00150
00151 Tisc_interprete = function(buffer: PChar; status_vector: PPISC_STATUS):
00152 ISC_STATUS; {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00153
00154 Tfb_interpret = function(buffer: PChar; bufsize: integer; status_vector: PPISC_STATUS):
00155 ISC_STATUS; {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00156
00157 { Transaction support routines }
00158
00159 Tisc_start_transaction = function(status_vector: PISC_STATUS;
00160 tran_handle: PISC_TR_HANDLE; db_handle_count: Short;
00161 db_handle: PISC_DB_HANDLE; tpb_length: Word; tpb_address: PChar):
00162 ISC_STATUS; {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00163
00164 Tisc_start_multiple = function(status_vector: PISC_STATUS;
00165 tran_handle: PISC_TR_HANDLE; db_handle_count: Short;
00166 teb_vector_address: PISC_TEB): ISC_STATUS;
00167 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00168
00169 Tisc_rollback_transaction = function(status_vector: PISC_STATUS;
00170 tran_handle: PISC_TR_HANDLE): ISC_STATUS;
00171 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00172
00173 Tisc_rollback_retaining = function(status_vector: PISC_STATUS;
00174 tran_handle: PISC_TR_HANDLE): ISC_STATUS;
00175 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00176
00177 Tisc_commit_retaining = function(status_vector: PISC_STATUS;
00178 tran_handle: PISC_TR_HANDLE): ISC_STATUS;
00179 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00180
00181 Tisc_commit_transaction = function(status_vector: PISC_STATUS;
00182 tran_handle: PISC_TR_HANDLE): ISC_STATUS;
00183 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00184
00185 Tisc_transaction_info = function(status_vector: PISC_STATUS;
00186 tr_handle: PISC_TR_HANDLE; item_list_buffer_length: Short;
00187 item_list_buffer: PChar; result_buffer_length: Short;
00188 result_buffer: PChar): ISC_STATUS;
00189 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00190
00191 { Dynamic SQL routines }
00192
00193 Tisc_dsql_allocate_statement = function(status_vector: PISC_STATUS;
00194 db_handle: PISC_DB_HANDLE; stmt_handle: PISC_STMT_HANDLE): ISC_STATUS;
00195 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00196
00197 Tisc_dsql_alloc_statement2 = function(status_vector: PISC_STATUS;
00198 db_handle: PISC_DB_HANDLE; stmt_handle: PISC_STMT_HANDLE): ISC_STATUS;
00199 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00200
00201 Tisc_dsql_describe = function(status_vector: PISC_STATUS;
00202 stmt_handle: PISC_STMT_HANDLE; dialect: Word; xsqlda: PXSQLDA): ISC_STATUS;
00203 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00204
00205 Tisc_dsql_describe_bind = function(status_vector: PISC_STATUS;
00206 stmt_handle: PISC_STMT_HANDLE; dialect: Word; xsqlda: PXSQLDA): ISC_STATUS;
00207 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00208
00209 Tisc_dsql_execute = function(status_vector: PISC_STATUS;
00210 tran_handle: PISC_TR_HANDLE; stmt_handle: PISC_STMT_HANDLE; dialect: Word;
00211 xsqlda: PXSQLDA): ISC_STATUS;
00212 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00213
00214 Tisc_dsql_execute2 = function(status_vector: PISC_STATUS;
00215 tran_handle: PISC_TR_HANDLE; stmt_handle: PISC_STMT_HANDLE; dialect: Word;
00216 in_xsqlda, out_xsqlda: PXSQLDA): ISC_STATUS;
00217 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00218
00219 Tisc_dsql_execute_immediate = function(status_vector: PISC_STATUS;
00220 db_handle: PISC_DB_HANDLE; tran_handle: PISC_TR_HANDLE; length: Word;
00221 statement: PChar; dialect: Word; xsqlda: PXSQLDA): ISC_STATUS;
00222 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00223
00224 Tisc_dsql_fetch = function(status_vector: PISC_STATUS;
00225 stmt_handle: PISC_STMT_HANDLE; dialect: Word; xsqlda: PXSQLDA): ISC_STATUS;
00226 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00227
00228 Tisc_dsql_free_statement = function(status_vector: PISC_STATUS;
00229 stmt_handle: PISC_STMT_HANDLE; options: Word): ISC_STATUS;
00230 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00231
00232 Tisc_dsql_prepare = function(status_vector: PISC_STATUS;
00233 tran_handle: PISC_TR_HANDLE; stmt_handle: PISC_STMT_HANDLE;
00234 length: Word; statement: PChar; dialect: Word; xsqlda: PXSQLDA):
00235 ISC_STATUS; {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00236
00237 Tisc_dsql_set_cursor_name = function(status_vector: PISC_STATUS;
00238 stmt_handle: PISC_STMT_HANDLE; cursor_name: PChar; _type: Word): ISC_STATUS;
00239 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00240
00241 Tisc_dsql_sql_info = function(status_vector: PISC_STATUS;
00242 stmt_handle: PISC_STMT_HANDLE; item_length: Short; items: PChar;
00243 buffer_length: Short; buffer: PChar): ISC_STATUS;
00244 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00245
00246 { Blob processing routines }
00247
00248 Tisc_open_blob2 = function(status_vector: PISC_STATUS;
00249 db_handle: PISC_DB_HANDLE; tran_handle: PISC_TR_HANDLE;
00250 blob_handle: PISC_BLOB_HANDLE; blob_id: PISC_QUAD; bpb_length: Short;
00251 bpb_buffer: PChar): ISC_STATUS;
00252 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00253
00254 Tisc_create_blob2 = function(status_vector: PISC_STATUS;
00255 db_handle: PISC_DB_HANDLE; tran_handle: PISC_TR_HANDLE;
00256 blob_handle: PISC_BLOB_HANDLE; blob_id: PISC_QUAD; bpb_length: Short;
00257 bpb_address: PChar): ISC_STATUS;
00258 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00259
00260 Tisc_blob_info = function(status_vector: PISC_STATUS;
00261 blob_handle: PISC_BLOB_HANDLE; item_list_buffer_length: Short;
00262 item_list_buffer: PChar; result_buffer_length: Short; result_buffer: PChar):
00263 ISC_STATUS; {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00264
00265 Tisc_close_blob = function(status_vector: PISC_STATUS;
00266 blob_handle: PISC_BLOB_HANDLE): ISC_STATUS;
00267 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00268
00269 Tisc_cancel_blob = function(status_vector: PISC_STATUS;
00270 blob_handle: PISC_BLOB_HANDLE): ISC_STATUS;
00271 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00272
00273 Tisc_get_segment = function(status_vector: PISC_STATUS;
00274 blob_handle: PISC_BLOB_HANDLE; actual_seg_length: PWord;
00275 seg_buffer_length: Word; seg_buffer: PChar): ISC_STATUS;
00276 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00277
00278 Tisc_put_segment = function(status_vector: PISC_STATUS;
00279 blob_handle: PISC_BLOB_HANDLE; seg_buffer_len: Word; seg_buffer: PChar):
00280 ISC_STATUS; {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00281
00282 { Event processing routines }
00283
00284 Tisc_event_block = function(event_buffer: PPChar; result_buffer: PPChar;
00285 id_count: Word; event_list: array of PChar): ISC_LONG;
00286 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00287
00288 Tisc_event_counts = procedure(status_vector: PISC_STATUS;
00289 buffer_length: Short; event_buffer: PChar; result_buffer: PChar);
00290 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00291
00292 Tisc_cancel_events = function(status_vector: PISC_STATUS;
00293 db_handle: PISC_DB_HANDLE; event_id: PISC_LONG): ISC_STATUS;
00294 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00295
00296 Tisc_que_events = function(status_vector: PISC_STATUS;
00297 db_handle: PISC_DB_HANDLE; event_id: PISC_LONG; length: Short;
00298 event_buffer: PChar; event_function: TISC_CALLBACK;
00299 event_function_arg: PVoid): ISC_STATUS;
00300 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00301
00302 { Types convertion routines }
00303
00304 Tisc_decode_date = procedure(ib_date: PISC_QUAD; tm_date: PCTimeStructure);
00305 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00306
00307 Tisc_encode_date = procedure(tm_date: PCTimeStructure; ib_date: PISC_QUAD);
00308 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00309
00310 { Interbase Version 6 routines }
00311 Tisc_decode_sql_date = procedure(ib_date: PISC_DATE;
00312 tm_date: PCTimeStructure); {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00313
00314 Tisc_decode_sql_time = procedure(ib_time: PISC_TIME;
00315 tm_date: PCTimeStructure); {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00316
00317 Tisc_decode_timestamp = procedure(ib_timestamp: PISC_TIMESTAMP;
00318 tm_date: PCTimeStructure); {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00319
00320 Tisc_encode_sql_date = procedure(tm_date: PCTimeStructure;
00321 ib_date: PISC_DATE); {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00322
00323 Tisc_encode_sql_time = procedure(tm_date: PCTimeStructure;
00324 ib_time: PISC_TIME); {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00325
00326 Tisc_encode_timestamp = procedure(tm_date: PCTimeStructure;
00327 ib_timestamp: PISC_TIMESTAMP);
00328 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00329
00330 Tisc_vax_integer = function(buffer: PChar; length: Short): ISC_LONG;
00331 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00332
00333 { ************* Plain API Function variables definition ************ }
00334
00335 var
00336 { General database routines }
00337 isc_attach_database: Tisc_attach_database;
00338 isc_detach_database: Tisc_detach_database;
00339 isc_drop_database: Tisc_drop_database;
00340 isc_database_info: Tisc_database_info;
00341 isc_free: Tisc_free;
00342 isc_sqlcode: Tisc_sqlcode;
00343 isc_sql_interprete: Tisc_sql_interprete;
00344 isc_interprete: Tisc_interprete;
00345 fb_interpret: Tfb_interpret;
00346
00347 { Transaction support routines }
00348 isc_start_transaction: Tisc_start_transaction;
00349 isc_start_multiple: Tisc_start_multiple;
00350 isc_rollback_transaction: Tisc_rollback_transaction;
00351 isc_rollback_retaining: Tisc_rollback_retaining;
00352 isc_commit_transaction: Tisc_commit_transaction;
00353 isc_commit_retaining: Tisc_commit_retaining;
00354 isc_transaction_info: Tisc_transaction_info;
00355
00356 { Dynamic SQL routines }
00357 isc_dsql_allocate_statement: Tisc_dsql_allocate_statement;
00358 isc_dsql_alloc_statement2: Tisc_dsql_alloc_statement2;
00359 isc_dsql_describe: Tisc_dsql_describe;
00360 isc_dsql_describe_bind: Tisc_dsql_describe_bind;
00361 isc_dsql_execute: Tisc_dsql_execute;
00362 isc_dsql_execute2: Tisc_dsql_execute2;
00363 isc_dsql_execute_immediate: Tisc_dsql_execute_immediate;
00364 isc_dsql_fetch: Tisc_dsql_fetch;
00365 isc_dsql_free_statement: Tisc_dsql_free_statement;
00366 isc_dsql_prepare: Tisc_dsql_prepare;
00367 isc_dsql_set_cursor_name: Tisc_dsql_set_cursor_name;
00368 isc_dsql_sql_info: Tisc_dsql_sql_info;
00369
00370 { Array processing routines }
00371 isc_array_gen_sdl: Tisc_array_gen_sdl;
00372 isc_array_get_slice: Tisc_array_get_slice;
00373 isc_array_lookup_bounds: Tisc_array_lookup_bounds;
00374 isc_array_lookup_desc: Tisc_array_lookup_desc;
00375 isc_array_set_desc: Tisc_array_set_desc;
00376 isc_array_put_slice: Tisc_array_put_slice;
00377
00378 { Blob processing routines }
00379 isc_open_blob2: Tisc_open_blob2;
00380 isc_create_blob2: Tisc_create_blob2;
00381 isc_blob_info: Tisc_blob_info;
00382 isc_close_blob: Tisc_close_blob;
00383 isc_cancel_blob: Tisc_cancel_blob;
00384 isc_get_segment: Tisc_get_segment;
00385 isc_put_segment: Tisc_put_segment;
00386
00387 { Event processing routines }
00388 isc_que_events: Tisc_que_events;
00389 isc_event_counts: Tisc_event_counts;
00390 isc_event_block: Tisc_event_block;
00391 isc_cancel_events: Tisc_cancel_events;
00392
00393 { Types convertion routines }
00394 isc_encode_date: Tisc_encode_date;
00395 isc_decode_date: Tisc_decode_date;
00396 isc_vax_integer: Tisc_vax_integer;
00397
00398 isc_encode_sql_date: Tisc_encode_sql_date;
00399 isc_decode_sql_date: Tisc_decode_sql_date;
00400
00401 isc_encode_sql_time: Tisc_encode_sql_time;
00402 isc_decode_sql_time: Tisc_decode_sql_time;
00403
00404 isc_encode_timestamp: Tisc_encode_timestamp;
00405 isc_decode_timestamp: Tisc_decode_timestamp;
00406
00407 var
00408 LibraryLoader: TZNativeLibraryLoader;
00409 LibraryLoaderEmbedded: TZNativeLibraryLoader;
00410
00411 implementation
00412
00413 uses SysUtils,
00414 {$IFNDEF UNIX}
00415 Windows,
00416 {$ELSE}
00417 {$IFNDEF FPC}
00418 libc,
00419 {$ENDIF}
00420 {$ENDIF}
00421 ZMessages;
00422
00423 {$IFDEF UNIX}
00424 {$IFDEF INTERBASE_CRYPT}
00425 {$DEFINE ENABLE_INTERBASE_CRYPT}
00426 {$ENDIF}
00427 {$ENDIF}
00428
00429 type
00430 {** Implements a loader for Firebird native library. }
00431 TZFirebirdNativeLibraryLoader = class (TZNativeLibraryLoader)
00432 {$IFDEF ENABLE_INTERBASE_CRYPT}
00433 private
00434 FPreLocations: TStringDynArray;
00435 FPreHandle: LongWord;
00436 FPreLoaded: Boolean;
00437 FPreRequared: boolean;
00438 protected
00439 function LoadNativeLibrary: Boolean; override;
00440 procedure FreeNativeLibrary; override;
00441
00442 public
00443 constructor Create(PreLocations, Locations: array of string;
00444 PreRequared: boolean = False); overload;
00445
00446 property PreHandle: LongWord read FPreHandle write FPreHandle;
00447 property PreLoaded: Boolean read FPreLoaded write FPreLoaded;
00448 {$ENDIF}
00449 public
00450 function Load: Boolean; override;
00451 end;
00452
00453 { TZFirebirdNativeLibraryLoader }
00454
00455 {**
00456 Creates this loader class and assignes main properties.
00457 @param Locations locations of native library on windows platform.
00458 }
00459 {$IFDEF ENABLE_INTERBASE_CRYPT}
00460 constructor TZFirebirdNativeLibraryLoader.Create(PreLocations,
00461 Locations: array of string; PreRequared: boolean);
00462 var
00463 I: Integer;
00464 begin
00465 inherited Create(Locations);
00466 SetLength(FPreLocations, Length(PreLocations));
00467 for I := 0 to High(PreLocations) do
00468 FPreLocations[I] := PreLocations[I];
00469 FPreRequared := PreRequared;
00470 end;
00471 {$ENDIF}
00472
00473 {**
00474 Frees a previously loaded library.
00475 }
00476 {$IFDEF ENABLE_INTERBASE_CRYPT}
00477 procedure TZFirebirdNativeLibraryLoader.FreeNativeLibrary;
00478 begin
00479 inherited FreeNativeLibrary;
00480 if (PreHandle <> 0) and Loaded then
00481 FreeLibrary(PreHandle);
00482 PreHandle := 0;
00483 PreLoaded := False;
00484 end;
00485 {$ENDIF}
00486
00487 {**
00488 Loads a library module.
00489 @return <code>True</code> if library was successfully loaded.
00490 }
00491 function TZFirebirdNativeLibraryLoader.Load: Boolean;
00492 begin
00493 Result := inherited Load;
00494
00495 isc_sqlcode := GetAddress('isc_sqlcode');
00496 isc_sql_interprete := GetAddress('isc_sql_interprete');
00497 isc_interprete := GetAddress('isc_interprete');
00498 fb_interpret := GetAddress('fb_interpret');
00499 isc_vax_integer := GetAddress('isc_vax_integer');
00500
00501 isc_array_gen_sdl := GetAddress( 'isc_array_gen_sdl');
00502 isc_array_get_slice := GetAddress( 'isc_array_get_slice');
00503 isc_array_lookup_bounds := GetAddress( 'isc_array_lookup_bounds');
00504 isc_array_lookup_desc := GetAddress( 'isc_array_lookup_desc');
00505 isc_array_set_desc := GetAddress( 'isc_array_set_desc');
00506 isc_array_put_slice := GetAddress( 'isc_array_put_slice');
00507
00508 isc_blob_info := GetAddress('isc_blob_info');
00509 isc_open_blob2 := GetAddress('isc_open_blob2');
00510 isc_close_blob := GetAddress('isc_close_blob');
00511 isc_cancel_blob := GetAddress('isc_cancel_blob');
00512 isc_get_segment := GetAddress('isc_get_segment');
00513 isc_put_segment := GetAddress('isc_put_segment');
00514 isc_create_blob2 := GetAddress('isc_create_blob2');
00515 isc_decode_date := GetAddress('isc_decode_date');
00516 isc_encode_date := GetAddress('isc_encode_date');
00517 isc_dsql_free_statement := GetAddress('isc_dsql_free_statement');
00518 isc_dsql_execute2 := GetAddress('isc_dsql_execute2');
00519 isc_dsql_execute := GetAddress('isc_dsql_execute');
00520 isc_dsql_set_cursor_name := GetAddress('isc_dsql_set_cursor_name');
00521 isc_dsql_fetch := GetAddress('isc_dsql_fetch');
00522 isc_dsql_sql_info := GetAddress('isc_dsql_sql_info');
00523 isc_dsql_allocate_statement := GetAddress('isc_dsql_allocate_statement');
00524 isc_dsql_alloc_statement2 := GetAddress('isc_dsql_alloc_statement2');
00525 isc_dsql_prepare := GetAddress('isc_dsql_prepare');
00526 isc_dsql_describe_bind := GetAddress('isc_dsql_describe_bind');
00527 isc_dsql_describe := GetAddress('isc_dsql_describe');
00528 isc_dsql_execute_immediate := GetAddress('isc_dsql_execute_immediate');
00529 isc_drop_database := GetAddress('isc_drop_database');
00530 isc_detach_database := GetAddress('isc_detach_database');
00531 isc_attach_database := GetAddress('isc_attach_database');
00532 isc_database_info := GetAddress('isc_database_info');
00533 isc_transaction_info := GetAddress('isc_transaction_info');
00534 isc_start_multiple := GetAddress('isc_start_multiple');
00535 isc_start_transaction := GetAddress('isc_start_transaction');
00536 isc_commit_transaction := GetAddress('isc_commit_transaction');
00537
00538 isc_commit_retaining := GetAddress('isc_commit_retaining');
00539 isc_rollback_transaction := GetAddress('isc_rollback_transaction');
00540 isc_cancel_events := GetAddress('isc_cancel_events');
00541 isc_que_events := GetAddress('isc_que_events');
00542 isc_event_counts := GetAddress('isc_event_counts');
00543 isc_event_block := GetAddress('isc_event_block');
00544 isc_free := GetAddress('isc_free');
00545
00546 isc_rollback_retaining := GetAddress( 'isc_rollback_retaining');
00547 isc_decode_sql_date := GetAddress('isc_decode_sql_date');
00548 isc_decode_sql_time := GetAddress('isc_decode_sql_time');
00549 isc_decode_timestamp := GetAddress('isc_decode_timestamp');
00550 isc_encode_sql_date := GetAddress('isc_encode_sql_date');
00551 isc_encode_sql_time := GetAddress('isc_encode_sql_time');
00552 isc_encode_timestamp := GetAddress('isc_encode_timestamp');
00553 end;
00554
00555 {**
00556 Loads a library module and initializes the handle.
00557 @return <code>True</code> is library was successfully loaded.
00558 }
00559 {$IFDEF ENABLE_INTERBASE_CRYPT}
00560 function TZFirebirdNativeLibraryLoader.LoadNativeLibrary: Boolean;
00561 var
00562 I: Integer;
00563 Location: string;
00564 TriedLocations: string;
00565 begin
00566 if Length(FPreLocations) <> 0 then
00567 begin
00568 PreLoaded := False;
00569 Location := '';
00570 TriedLocations := '';
00571 if PreHandle = 0 then
00572 begin
00573 for I := 0 to High(FPreLocations) do
00574 begin
00575 Location := FPreLocations[I];
00576
00577
00578
00579 {$IFDEF UNIX}
00580 {$IFDEF FPC}
00581 PreHandle := ZCompatibility.LoadLibrary(PChar(Location));
00582 {$ELSE}
00583 PreHandle := HMODULE(dlopen(PChar(Location), RTLD_GLOBAL));
00584 {$ENDIF}
00585 {$ELSE}
00586 PreHandle := LoadLibrary(PChar(Location));
00587 {$ENDIF}
00588
00589 if PreHandle <> 0 then
00590 begin
00591 PreLoaded := True;
00592 Break;
00593 end;
00594 if TriedLocations <> '' then
00595 TriedLocations := TriedLocations + ', ';
00596 TriedLocations := TriedLocations + Location;
00597 end;
00598 end;
00599
00600 if (not PreLoaded) and (FPreRequared) then
00601 raise Exception.Create(Format(SLibraryNotFound, [TriedLocations]));
00602 end;
00603
00604 Result := inherited LoadNativeLibrary;
00605 end;
00606 {$ENDIF}
00607
00608 initialization
00609 {$IFNDEF UNIX}
00610 LibraryLoader := TZFirebirdNativeLibraryLoader.Create(
00611 [WINDOWS1_DLL_LOCATION
00612 {$IFNDEF FIREBIRD_STRICT_DLL_LOADING}
00613 , WINDOWS2_DLL_LOCATION
00614 {$ENDIF}
00615 ]);
00616 LibraryLoaderEmbedded := TZFirebirdNativeLibraryLoader.Create(
00617 [WINDOWS1_DLL_LOCATION_EMBEDDED
00618 {$IFNDEF FIREBIRD_STRICT_DLL_LOADING}
00619 ,WINDOWS2_DLL_LOCATION_EMBEDDED
00620 {$ENDIF}
00621 ]);
00622
00623 {$ELSE}
00624 {$IFDEF ENABLE_INTERBASE_CRYPT}
00625 LibraryLoader := TZFirebirdNativeLibraryLoader.Create(
00626 [LINUX1_IB_CRYPT_LOCATION
00627 {$IFNDEF FIREBIRD_STRICT_DLL_LOADING}
00628 , LINUX2_IB_CRYPT_LOCATION
00629 {$ENDIF}
00630 ],[LINUX1_DLL_LOCATION
00631
00632 {$IFNDEF FIREBIRD_STRICT_DLL_LOADING}
00633 ,LINUX2_DLL_LOCATION
00634 {$ENDIF}
00635 ]);
00636
00637 LibraryLoaderEmbedded := TZFirebirdNativeLibraryLoader.Create(
00638 [LINUX1_IB_CRYPT_LOCATION
00639 {$IFNDEF FIREBIRD_STRICT_DLL_LOADING}
00640 ,LINUX2_IB_CRYPT_LOCATION
00641 {$ENDIF}
00642 ], [LINUX1_DLL_LOCATION_EMBEDDED
00643 {$IFNDEF FIREBIRD_STRICT_DLL_LOADING}
00644 ,LINUX2_DLL_LOCATION_EMBEDDED
00645 {$ENDIF}
00646 ]);
00647 {$ELSE}
00648 LibraryLoader := TZFirebirdNativeLibraryLoader.Create(
00649 [LINUX1_DLL_LOCATION
00650 {$IFNDEF FIREBIRD_STRICT_DLL_LOADING}
00651 ,LINUX2_DLL_LOCATION
00652 {$ENDIF}
00653 ]);
00654 LibraryLoaderEmbedded := TZFirebirdNativeLibraryLoader.Create(
00655 [LINUX1_DLL_LOCATION_EMBEDDED
00656 {$IFNDEF FIREBIRD_STRICT_DLL_LOADING}
00657 ,LINUX2_DLL_LOCATION_EMBEDDED
00658 {$ENDIF}
00659 ]);
00660 {$ENDIF}
00661 {$ENDIF}
00662 finalization
00663 if Assigned(LibraryLoader) then
00664 LibraryLoader.Free;
00665 if Assigned(LibraryLoaderEmbedded) then
00666 LibraryLoaderEmbedded.Free;
00667 end.