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 ZPlainFirebird20;
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 = 'fbclient20.dll';
00074 WINDOWS1_DLL_LOCATION_EMBEDDED = 'fbclientd20.dll';
00075
00076 LINUX1_DLL_LOCATION = 'libfbclient.so.20';
00077 LINUX1_DLL_LOCATION_EMBEDDED = 'libfbembed.so.20';
00078 LINUX1_IB_CRYPT_LOCATION = 'libcrypt.so.20';
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 { Array processing routines }
00106 Tisc_array_gen_sdl = function(status_vector: PISC_STATUS;
00107 isc_array_desc: PISC_ARRAY_DESC; isc_arg3: PShort;
00108 isc_arg4: PChar; isc_arg5: PShort): ISC_STATUS;
00109 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00110
00111 Tisc_array_get_slice = function(status_vector: PISC_STATUS;
00112 db_handle: PISC_DB_HANDLE; trans_handle: PISC_TR_HANDLE;
00113 array_id: PISC_QUAD; descriptor: PISC_ARRAY_DESC;
00114 dest_array: PVoid; slice_length: ISC_LONG): ISC_STATUS;
00115 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00116
00117 Tisc_array_lookup_bounds = function(status_vector: PISC_STATUS;
00118 db_handle: PISC_DB_HANDLE; trans_handle: PISC_TR_HANDLE;
00119 table_name, column_name: PChar;
00120 descriptor: PISC_ARRAY_DESC): ISC_STATUS;
00121 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00122
00123 Tisc_array_lookup_desc = function(status_vector: PISC_STATUS;
00124 db_handle: PISC_DB_HANDLE; trans_handle: PISC_TR_HANDLE;
00125 table_name, column_name: PChar;
00126 descriptor: PISC_ARRAY_DESC): ISC_STATUS;
00127 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00128
00129 Tisc_array_set_desc = function(status_vector: PISC_STATUS;
00130 table_name: PChar; column_name: PChar;
00131 sql_dtype, sql_length, sql_dimensions: PShort;
00132 descriptor: PISC_ARRAY_DESC): ISC_STATUS;
00133 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00134
00135 Tisc_array_put_slice = function(status_vector: PISC_STATUS;
00136 db_handle: PISC_DB_HANDLE; trans_handle: PISC_TR_HANDLE;
00137 array_id: PISC_QUAD; descriptor: PISC_ARRAY_DESC;
00138 source_array: PVoid; slice_length: PISC_LONG): ISC_STATUS;
00139 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00140
00141 Tisc_free = function(isc_arg1: PChar): ISC_LONG;
00142 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00143
00144 Tisc_sqlcode = function(status_vector: PISC_STATUS): ISC_LONG;
00145 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00146
00147 Tisc_sql_interprete = procedure(sqlcode: Short; buffer: PChar;
00148 buffer_length: Short); {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00149
00150 Tisc_interprete = function(buffer: PChar; status_vector: PPISC_STATUS):
00151 ISC_STATUS; {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00152
00153 { Transaction support routines }
00154
00155 Tisc_start_transaction = function(status_vector: PISC_STATUS;
00156 tran_handle: PISC_TR_HANDLE; db_handle_count: Short;
00157 db_handle: PISC_DB_HANDLE; tpb_length: Word; tpb_address: PChar):
00158 ISC_STATUS; {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00159
00160 Tisc_start_multiple = function(status_vector: PISC_STATUS;
00161 tran_handle: PISC_TR_HANDLE; db_handle_count: Short;
00162 teb_vector_address: PISC_TEB): ISC_STATUS;
00163 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00164
00165 Tisc_rollback_transaction = function(status_vector: PISC_STATUS;
00166 tran_handle: PISC_TR_HANDLE): ISC_STATUS;
00167 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00168
00169 Tisc_rollback_retaining = function(status_vector: PISC_STATUS;
00170 tran_handle: PISC_TR_HANDLE): ISC_STATUS;
00171 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00172
00173 Tisc_commit_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_transaction = function(status_vector: PISC_STATUS;
00178 tran_handle: PISC_TR_HANDLE): ISC_STATUS;
00179 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00180
00181 Tisc_transaction_info = function(status_vector: PISC_STATUS;
00182 tr_handle: PISC_TR_HANDLE; item_list_buffer_length: Short;
00183 item_list_buffer: PChar; result_buffer_length: Short;
00184 result_buffer: PChar): ISC_STATUS;
00185 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00186
00187 { Dynamic SQL routines }
00188
00189 Tisc_dsql_allocate_statement = function(status_vector: PISC_STATUS;
00190 db_handle: PISC_DB_HANDLE; stmt_handle: PISC_STMT_HANDLE): ISC_STATUS;
00191 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00192
00193 Tisc_dsql_alloc_statement2 = 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_describe = function(status_vector: PISC_STATUS;
00198 stmt_handle: PISC_STMT_HANDLE; dialect: Word; xsqlda: PXSQLDA): ISC_STATUS;
00199 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00200
00201 Tisc_dsql_describe_bind = 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_execute = function(status_vector: PISC_STATUS;
00206 tran_handle: PISC_TR_HANDLE; stmt_handle: PISC_STMT_HANDLE; dialect: Word;
00207 xsqlda: PXSQLDA): ISC_STATUS;
00208 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00209
00210 Tisc_dsql_execute2 = function(status_vector: PISC_STATUS;
00211 tran_handle: PISC_TR_HANDLE; stmt_handle: PISC_STMT_HANDLE; dialect: Word;
00212 in_xsqlda, out_xsqlda: PXSQLDA): ISC_STATUS;
00213 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00214
00215 Tisc_dsql_execute_immediate = function(status_vector: PISC_STATUS;
00216 db_handle: PISC_DB_HANDLE; tran_handle: PISC_TR_HANDLE; length: Word;
00217 statement: PChar; dialect: Word; xsqlda: PXSQLDA): ISC_STATUS;
00218 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00219
00220 Tisc_dsql_fetch = function(status_vector: PISC_STATUS;
00221 stmt_handle: PISC_STMT_HANDLE; dialect: Word; xsqlda: PXSQLDA): ISC_STATUS;
00222 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00223
00224 Tisc_dsql_free_statement = function(status_vector: PISC_STATUS;
00225 stmt_handle: PISC_STMT_HANDLE; options: Word): ISC_STATUS;
00226 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00227
00228 Tisc_dsql_prepare = function(status_vector: PISC_STATUS;
00229 tran_handle: PISC_TR_HANDLE; stmt_handle: PISC_STMT_HANDLE;
00230 length: Word; statement: PChar; dialect: Word; xsqlda: PXSQLDA):
00231 ISC_STATUS; {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00232
00233 Tisc_dsql_set_cursor_name = function(status_vector: PISC_STATUS;
00234 stmt_handle: PISC_STMT_HANDLE; cursor_name: PChar; _type: Word): ISC_STATUS;
00235 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00236
00237 Tisc_dsql_sql_info = function(status_vector: PISC_STATUS;
00238 stmt_handle: PISC_STMT_HANDLE; item_length: Short; items: PChar;
00239 buffer_length: Short; buffer: PChar): ISC_STATUS;
00240 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00241
00242 { Blob processing routines }
00243
00244 Tisc_open_blob2 = function(status_vector: PISC_STATUS;
00245 db_handle: PISC_DB_HANDLE; tran_handle: PISC_TR_HANDLE;
00246 blob_handle: PISC_BLOB_HANDLE; blob_id: PISC_QUAD; bpb_length: Short;
00247 bpb_buffer: PChar): ISC_STATUS;
00248 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00249
00250 Tisc_create_blob2 = function(status_vector: PISC_STATUS;
00251 db_handle: PISC_DB_HANDLE; tran_handle: PISC_TR_HANDLE;
00252 blob_handle: PISC_BLOB_HANDLE; blob_id: PISC_QUAD; bpb_length: Short;
00253 bpb_address: PChar): ISC_STATUS;
00254 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00255
00256 Tisc_blob_info = function(status_vector: PISC_STATUS;
00257 blob_handle: PISC_BLOB_HANDLE; item_list_buffer_length: Short;
00258 item_list_buffer: PChar; result_buffer_length: Short; result_buffer: PChar):
00259 ISC_STATUS; {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00260
00261 Tisc_close_blob = function(status_vector: PISC_STATUS;
00262 blob_handle: PISC_BLOB_HANDLE): ISC_STATUS;
00263 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00264
00265 Tisc_cancel_blob = function(status_vector: PISC_STATUS;
00266 blob_handle: PISC_BLOB_HANDLE): ISC_STATUS;
00267 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00268
00269 Tisc_get_segment = function(status_vector: PISC_STATUS;
00270 blob_handle: PISC_BLOB_HANDLE; actual_seg_length: PWord;
00271 seg_buffer_length: Word; seg_buffer: PChar): ISC_STATUS;
00272 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00273
00274 Tisc_put_segment = function(status_vector: PISC_STATUS;
00275 blob_handle: PISC_BLOB_HANDLE; seg_buffer_len: Word; seg_buffer: PChar):
00276 ISC_STATUS; {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00277
00278 { Event processing routines }
00279
00280 Tisc_event_block = function(event_buffer: PPChar; result_buffer: PPChar;
00281 id_count: Word; event_list: array of PChar): ISC_LONG;
00282 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00283
00284 Tisc_event_counts = procedure(status_vector: PISC_STATUS;
00285 buffer_length: Short; event_buffer: PChar; result_buffer: PChar);
00286 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00287
00288 Tisc_cancel_events = function(status_vector: PISC_STATUS;
00289 db_handle: PISC_DB_HANDLE; event_id: PISC_LONG): ISC_STATUS;
00290 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00291
00292 Tisc_que_events = function(status_vector: PISC_STATUS;
00293 db_handle: PISC_DB_HANDLE; event_id: PISC_LONG; length: Short;
00294 event_buffer: PChar; event_function: TISC_CALLBACK;
00295 event_function_arg: PVoid): ISC_STATUS;
00296 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00297
00298 { Types convertion routines }
00299
00300 Tisc_decode_date = procedure(ib_date: PISC_QUAD; tm_date: PCTimeStructure);
00301 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00302
00303 Tisc_encode_date = procedure(tm_date: PCTimeStructure; ib_date: PISC_QUAD);
00304 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00305
00306 { Interbase Version 6 routines }
00307 Tisc_decode_sql_date = procedure(ib_date: PISC_DATE;
00308 tm_date: PCTimeStructure); {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00309
00310 Tisc_decode_sql_time = procedure(ib_time: PISC_TIME;
00311 tm_date: PCTimeStructure); {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00312
00313 Tisc_decode_timestamp = procedure(ib_timestamp: PISC_TIMESTAMP;
00314 tm_date: PCTimeStructure); {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00315
00316 Tisc_encode_sql_date = procedure(tm_date: PCTimeStructure;
00317 ib_date: PISC_DATE); {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00318
00319 Tisc_encode_sql_time = procedure(tm_date: PCTimeStructure;
00320 ib_time: PISC_TIME); {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00321
00322 Tisc_encode_timestamp = procedure(tm_date: PCTimeStructure;
00323 ib_timestamp: PISC_TIMESTAMP);
00324 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00325
00326 Tisc_vax_integer = function(buffer: PChar; length: Short): ISC_LONG;
00327 {$IFNDEF UNIX} stdcall {$ELSE} cdecl {$ENDIF};
00328
00329 { ************* Plain API Function variables definition ************ }
00330
00331 var
00332 { General database routines }
00333 isc_attach_database: Tisc_attach_database;
00334 isc_detach_database: Tisc_detach_database;
00335 isc_drop_database: Tisc_drop_database;
00336 isc_database_info: Tisc_database_info;
00337 isc_free: Tisc_free;
00338 isc_sqlcode: Tisc_sqlcode;
00339 isc_sql_interprete: Tisc_sql_interprete;
00340 isc_interprete: Tisc_interprete;
00341
00342 { Transaction support routines }
00343 isc_start_transaction: Tisc_start_transaction;
00344 isc_start_multiple: Tisc_start_multiple;
00345 isc_rollback_transaction: Tisc_rollback_transaction;
00346 isc_rollback_retaining: Tisc_rollback_retaining;
00347 isc_commit_transaction: Tisc_commit_transaction;
00348 isc_commit_retaining: Tisc_commit_retaining;
00349 isc_transaction_info: Tisc_transaction_info;
00350
00351 { Dynamic SQL routines }
00352 isc_dsql_allocate_statement: Tisc_dsql_allocate_statement;
00353 isc_dsql_alloc_statement2: Tisc_dsql_alloc_statement2;
00354 isc_dsql_describe: Tisc_dsql_describe;
00355 isc_dsql_describe_bind: Tisc_dsql_describe_bind;
00356 isc_dsql_execute: Tisc_dsql_execute;
00357 isc_dsql_execute2: Tisc_dsql_execute2;
00358 isc_dsql_execute_immediate: Tisc_dsql_execute_immediate;
00359 isc_dsql_fetch: Tisc_dsql_fetch;
00360 isc_dsql_free_statement: Tisc_dsql_free_statement;
00361 isc_dsql_prepare: Tisc_dsql_prepare;
00362 isc_dsql_set_cursor_name: Tisc_dsql_set_cursor_name;
00363 isc_dsql_sql_info: Tisc_dsql_sql_info;
00364
00365 { Array processing routines }
00366 isc_array_gen_sdl: Tisc_array_gen_sdl;
00367 isc_array_get_slice: Tisc_array_get_slice;
00368 isc_array_lookup_bounds: Tisc_array_lookup_bounds;
00369 isc_array_lookup_desc: Tisc_array_lookup_desc;
00370 isc_array_set_desc: Tisc_array_set_desc;
00371 isc_array_put_slice: Tisc_array_put_slice;
00372
00373 { Blob processing routines }
00374 isc_open_blob2: Tisc_open_blob2;
00375 isc_create_blob2: Tisc_create_blob2;
00376 isc_blob_info: Tisc_blob_info;
00377 isc_close_blob: Tisc_close_blob;
00378 isc_cancel_blob: Tisc_cancel_blob;
00379 isc_get_segment: Tisc_get_segment;
00380 isc_put_segment: Tisc_put_segment;
00381
00382 { Event processing routines }
00383 isc_que_events: Tisc_que_events;
00384 isc_event_counts: Tisc_event_counts;
00385 isc_event_block: Tisc_event_block;
00386 isc_cancel_events: Tisc_cancel_events;
00387
00388 { Types convertion routines }
00389 isc_encode_date: Tisc_encode_date;
00390 isc_decode_date: Tisc_decode_date;
00391 isc_vax_integer: Tisc_vax_integer;
00392
00393 isc_encode_sql_date: Tisc_encode_sql_date;
00394 isc_decode_sql_date: Tisc_decode_sql_date;
00395
00396 isc_encode_sql_time: Tisc_encode_sql_time;
00397 isc_decode_sql_time: Tisc_decode_sql_time;
00398
00399 isc_encode_timestamp: Tisc_encode_timestamp;
00400 isc_decode_timestamp: Tisc_decode_timestamp;
00401
00402 var
00403 LibraryLoader: TZNativeLibraryLoader;
00404 LibraryLoaderEmbedded: TZNativeLibraryLoader;
00405
00406 implementation
00407
00408 uses SysUtils,
00409 {$IFNDEF UNIX}
00410 Windows,
00411 {$ELSE}
00412 {$IFNDEF FPC}
00413 libc,
00414 {$ENDIF}
00415 {$ENDIF}
00416 ZMessages;
00417
00418 {$IFDEF UNIX}
00419 {$IFDEF INTERBASE_CRYPT}
00420 {$DEFINE ENABLE_INTERBASE_CRYPT}
00421 {$ENDIF}
00422 {$ENDIF}
00423
00424 type
00425 {** Implements a loader for Firebird native library. }
00426 TZFirebirdNativeLibraryLoader = class (TZNativeLibraryLoader)
00427 {$IFDEF ENABLE_INTERBASE_CRYPT}
00428 private
00429 FPreLocations: TStringDynArray;
00430 FPreHandle: LongWord;
00431 FPreLoaded: Boolean;
00432 FPreRequared: boolean;
00433 protected
00434 function LoadNativeLibrary: Boolean; override;
00435 procedure FreeNativeLibrary; override;
00436
00437 public
00438 constructor Create(PreLocations, Locations: array of string;
00439 PreRequared: boolean = False); overload;
00440
00441 property PreHandle: LongWord read FPreHandle write FPreHandle;
00442 property PreLoaded: Boolean read FPreLoaded write FPreLoaded;
00443 {$ENDIF}
00444 public
00445 function Load: Boolean; override;
00446 end;
00447
00448 { TZFirebirdNativeLibraryLoader }
00449
00450 {**
00451 Creates this loader class and assignes main properties.
00452 @param Locations locations of native library on windows platform.
00453 }
00454 {$IFDEF ENABLE_INTERBASE_CRYPT}
00455 constructor TZFirebirdNativeLibraryLoader.Create(PreLocations,
00456 Locations: array of string; PreRequared: boolean);
00457 var
00458 I: Integer;
00459 begin
00460 inherited Create(Locations);
00461 SetLength(FPreLocations, Length(PreLocations));
00462 for I := 0 to High(PreLocations) do
00463 FPreLocations[I] := PreLocations[I];
00464 FPreRequared := PreRequared;
00465 end;
00466 {$ENDIF}
00467
00468 {**
00469 Frees a previously loaded library.
00470 }
00471 {$IFDEF ENABLE_INTERBASE_CRYPT}
00472 procedure TZFirebirdNativeLibraryLoader.FreeNativeLibrary;
00473 begin
00474 inherited FreeNativeLibrary;
00475 if (PreHandle <> 0) and Loaded then
00476 FreeLibrary(PreHandle);
00477 PreHandle := 0;
00478 PreLoaded := False;
00479 end;
00480 {$ENDIF}
00481
00482 {**
00483 Loads a library module.
00484 @return <code>True</code> if library was successfully loaded.
00485 }
00486 function TZFirebirdNativeLibraryLoader.Load: Boolean;
00487 begin
00488 Result := inherited Load;
00489
00490 isc_sqlcode := GetAddress('isc_sqlcode');
00491 isc_sql_interprete := GetAddress('isc_sql_interprete');
00492 isc_interprete := GetAddress('isc_interprete');
00493 isc_vax_integer := GetAddress('isc_vax_integer');
00494
00495 isc_array_gen_sdl := GetAddress( 'isc_array_gen_sdl');
00496 isc_array_get_slice := GetAddress( 'isc_array_get_slice');
00497 isc_array_lookup_bounds := GetAddress( 'isc_array_lookup_bounds');
00498 isc_array_lookup_desc := GetAddress( 'isc_array_lookup_desc');
00499 isc_array_set_desc := GetAddress( 'isc_array_set_desc');
00500 isc_array_put_slice := GetAddress( 'isc_array_put_slice');
00501
00502 isc_blob_info := GetAddress('isc_blob_info');
00503 isc_open_blob2 := GetAddress('isc_open_blob2');
00504 isc_close_blob := GetAddress('isc_close_blob');
00505 isc_cancel_blob := GetAddress('isc_cancel_blob');
00506 isc_get_segment := GetAddress('isc_get_segment');
00507 isc_put_segment := GetAddress('isc_put_segment');
00508 isc_create_blob2 := GetAddress('isc_create_blob2');
00509 isc_decode_date := GetAddress('isc_decode_date');
00510 isc_encode_date := GetAddress('isc_encode_date');
00511 isc_dsql_free_statement := GetAddress('isc_dsql_free_statement');
00512 isc_dsql_execute2 := GetAddress('isc_dsql_execute2');
00513 isc_dsql_execute := GetAddress('isc_dsql_execute');
00514 isc_dsql_set_cursor_name := GetAddress('isc_dsql_set_cursor_name');
00515 isc_dsql_fetch := GetAddress('isc_dsql_fetch');
00516 isc_dsql_sql_info := GetAddress('isc_dsql_sql_info');
00517 isc_dsql_allocate_statement := GetAddress('isc_dsql_allocate_statement');
00518 isc_dsql_alloc_statement2 := GetAddress('isc_dsql_alloc_statement2');
00519 isc_dsql_prepare := GetAddress('isc_dsql_prepare');
00520 isc_dsql_describe_bind := GetAddress('isc_dsql_describe_bind');
00521 isc_dsql_describe := GetAddress('isc_dsql_describe');
00522 isc_dsql_execute_immediate := GetAddress('isc_dsql_execute_immediate');
00523 isc_drop_database := GetAddress('isc_drop_database');
00524 isc_detach_database := GetAddress('isc_detach_database');
00525 isc_attach_database := GetAddress('isc_attach_database');
00526 isc_database_info := GetAddress('isc_database_info');
00527 isc_transaction_info := GetAddress('isc_transaction_info');
00528 isc_start_multiple := GetAddress('isc_start_multiple');
00529 isc_start_transaction := GetAddress('isc_start_transaction');
00530 isc_commit_transaction := GetAddress('isc_commit_transaction');
00531
00532 isc_commit_retaining := GetAddress('isc_commit_retaining');
00533 isc_rollback_transaction := GetAddress('isc_rollback_transaction');
00534 isc_cancel_events := GetAddress('isc_cancel_events');
00535 isc_que_events := GetAddress('isc_que_events');
00536 isc_event_counts := GetAddress('isc_event_counts');
00537 isc_event_block := GetAddress('isc_event_block');
00538 isc_free := GetAddress('isc_free');
00539
00540 isc_rollback_retaining := GetAddress( 'isc_rollback_retaining');
00541 isc_decode_sql_date := GetAddress('isc_decode_sql_date');
00542 isc_decode_sql_time := GetAddress('isc_decode_sql_time');
00543 isc_decode_timestamp := GetAddress('isc_decode_timestamp');
00544 isc_encode_sql_date := GetAddress('isc_encode_sql_date');
00545 isc_encode_sql_time := GetAddress('isc_encode_sql_time');
00546 isc_encode_timestamp := GetAddress('isc_encode_timestamp');
00547 end;
00548
00549 {**
00550 Loads a library module and initializes the handle.
00551 @return <code>True</code> is library was successfully loaded.
00552 }
00553 {$IFDEF ENABLE_INTERBASE_CRYPT}
00554 function TZFirebirdNativeLibraryLoader.LoadNativeLibrary: Boolean;
00555 var
00556 I: Integer;
00557 Location: string;
00558 TriedLocations: string;
00559 begin
00560 if Length(FPreLocations) <> 0 then
00561 begin
00562 PreLoaded := False;
00563 Location := '';
00564 TriedLocations := '';
00565 if PreHandle = 0 then
00566 begin
00567 for I := 0 to High(FPreLocations) do
00568 begin
00569 Location := FPreLocations[I];
00570
00571
00572
00573 {$IFDEF UNIX}
00574 {$IFDEF FPC}
00575 PreHandle := ZCompatibility.LoadLibrary(PChar(Location));
00576 {$ELSE}
00577 PreHandle := HMODULE(dlopen(PChar(Location), RTLD_GLOBAL));
00578 {$ENDIF}
00579 {$ELSE}
00580 PreHandle := LoadLibrary(PChar(Location));
00581 {$ENDIF}
00582
00583 if PreHandle <> 0 then
00584 begin
00585 PreLoaded := True;
00586 Break;
00587 end;
00588 if TriedLocations <> '' then
00589 TriedLocations := TriedLocations + ', ';
00590 TriedLocations := TriedLocations + Location;
00591 end;
00592 end;
00593
00594 if (not PreLoaded) and (FPreRequared) then
00595 raise Exception.Create(Format(SLibraryNotFound, [TriedLocations]));
00596 end;
00597
00598 Result := inherited LoadNativeLibrary;
00599 end;
00600 {$ENDIF}
00601
00602 initialization
00603 {$IFNDEF UNIX}
00604 LibraryLoader := TZFirebirdNativeLibraryLoader.Create(
00605 [WINDOWS1_DLL_LOCATION
00606 {$IFNDEF FIREBIRD_STRICT_DLL_LOADING}
00607 , WINDOWS2_DLL_LOCATION
00608 {$ENDIF}
00609 ]);
00610 LibraryLoaderEmbedded := TZFirebirdNativeLibraryLoader.Create(
00611 [WINDOWS1_DLL_LOCATION_EMBEDDED
00612 {$IFNDEF FIREBIRD_STRICT_DLL_LOADING}
00613 ,WINDOWS2_DLL_LOCATION_EMBEDDED
00614 {$ENDIF}
00615 ]);
00616
00617 {$ELSE}
00618 {$IFDEF ENABLE_INTERBASE_CRYPT}
00619 LibraryLoader := TZFirebirdNativeLibraryLoader.Create(
00620 [LINUX1_IB_CRYPT_LOCATION
00621 {$IFNDEF FIREBIRD_STRICT_DLL_LOADING}
00622 , LINUX2_IB_CRYPT_LOCATION
00623 {$ENDIF}
00624 ],[LINUX1_DLL_LOCATION
00625
00626 {$IFNDEF FIREBIRD_STRICT_DLL_LOADING}
00627 ,LINUX2_DLL_LOCATION
00628 {$ENDIF}
00629 ]);
00630
00631 LibraryLoaderEmbedded := TZFirebirdNativeLibraryLoader.Create(
00632 [LINUX1_IB_CRYPT_LOCATION
00633 {$IFNDEF FIREBIRD_STRICT_DLL_LOADING}
00634 ,LINUX2_IB_CRYPT_LOCATION
00635 {$ENDIF}
00636 ], [LINUX1_DLL_LOCATION_EMBEDDED
00637 {$IFNDEF FIREBIRD_STRICT_DLL_LOADING}
00638 ,LINUX2_DLL_LOCATION_EMBEDDED
00639 {$ENDIF}
00640 ]);
00641 {$ELSE}
00642 LibraryLoader := TZFirebirdNativeLibraryLoader.Create(
00643 [LINUX1_DLL_LOCATION
00644 {$IFNDEF FIREBIRD_STRICT_DLL_LOADING}
00645 ,LINUX2_DLL_LOCATION
00646 {$ENDIF}
00647 ]);
00648 LibraryLoaderEmbedded := TZFirebirdNativeLibraryLoader.Create(
00649 [LINUX1_DLL_LOCATION_EMBEDDED
00650 {$IFNDEF FIREBIRD_STRICT_DLL_LOADING}
00651 ,LINUX2_DLL_LOCATION_EMBEDDED
00652 {$ENDIF}
00653 ]);
00654 {$ENDIF}
00655 {$ENDIF}
00656 finalization
00657 if Assigned(LibraryLoader) then
00658 LibraryLoader.Free;
00659 if Assigned(LibraryLoaderEmbedded) then
00660 LibraryLoaderEmbedded.Free;
00661 end.