--- ibx/trunk/runtime/IBIntf.pas 2000/07/31 16:43:00 4 +++ ibx/trunk/runtime/IBIntf.pas 2011/02/18 16:26:16 5 @@ -23,14 +23,24 @@ { Portions created by Inprise Corporation are Copyright (C) Inprise } { Corporation. All Rights Reserved. } { Contributor(s): Jeff Overcash } +{ Tony Whyman, MWA Software (Ported to Lazarus) } +{ http://www.mwasoftware.co.uk } { } {************************************************************************} unit IBIntf; +{$Mode Delphi} + interface -uses Windows, IBHeader, IBInstallHeader, IBExternals; +uses +{$IFDEF LINUX } + unix, +{$ELSE} + Windows, +{$ENDIF} + IBHeader,IBExternals; var BLOB_get: TBLOB_get; @@ -86,41 +96,27 @@ var isc_delete_user: Tisc_delete_user; isc_modify_user: Tisc_modify_user; - isc_install_clear_options: Tisc_install_clear_options; - isc_install_execute: Tisc_install_execute; - isc_install_get_info: Tisc_install_get_info; - isc_install_get_message: Tisc_install_get_message; - isc_install_load_external_text: Tisc_install_load_external_text; - isc_install_precheck: Tisc_install_precheck; - isc_install_set_option: Tisc_install_set_option; - isc_uninstall_execute: Tisc_uninstall_execute; - isc_uninstall_precheck: Tisc_uninstall_precheck; - isc_install_unset_option: Tisc_install_unset_option; { Library Initialization } procedure LoadIBLibrary; procedure FreeIBLibrary; -procedure LoadIBInstallLibrary; -procedure FreeIBInstallLibrary; function TryIBLoad: Boolean; procedure CheckIBLoaded; -function GetIBClientVersion: Integer; -procedure CheckIBInstallLoaded; { Stubs for 6.0 only functions } function isc_rollback_retaining_stub(status_vector : PISC_STATUS; tran_handle : PISC_TR_HANDLE): - ISC_STATUS; stdcall; + ISC_STATUS; {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} function isc_service_attach_stub(status_vector : PISC_STATUS; isc_arg2 : UShort; isc_arg3 : PChar; service_handle : PISC_SVC_HANDLE; isc_arg5 : UShort; isc_arg6 : PChar): - ISC_STATUS; stdcall; + ISC_STATUS; {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} function isc_service_detach_stub(status_vector : PISC_STATUS; service_handle : PISC_SVC_HANDLE): - ISC_STATUS; stdcall; + ISC_STATUS; {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} function isc_service_query_stub(status_vector : PISC_STATUS; service_handle : PISC_SVC_HANDLE; recv_handle : PISC_SVC_HANDLE; @@ -130,79 +126,47 @@ function isc_service_query_stub(status_v isc_arg7 : PChar; isc_arg8 : UShort; isc_arg9 : PChar): - ISC_STATUS; stdcall; + ISC_STATUS; {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} function isc_service_start_stub(status_vector : PISC_STATUS; service_handle : PISC_SVC_HANDLE; recv_handle : PISC_SVC_HANDLE; isc_arg4 : UShort; isc_arg5 : PChar): - ISC_STATUS; stdcall; + ISC_STATUS; {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} procedure isc_encode_sql_date_stub(tm_date : PCTimeStructure; ib_date : PISC_DATE); - stdcall; + {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} procedure isc_encode_sql_time_stub(tm_date : PCTimeStructure; ib_time : PISC_TIME); - stdcall; + {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} procedure isc_encode_timestamp_stub(tm_date : PCTimeStructure; ib_timestamp : PISC_TIMESTAMP); - stdcall; + {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} procedure isc_decode_sql_date_stub(ib_date : PISC_DATE; tm_date : PCTimeStructure); - stdcall; + {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} procedure isc_decode_sql_time_stub(ib_time : PISC_TIME; tm_date : PCTimeStructure); - stdcall; + {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} procedure isc_decode_timestamp_stub(ib_timestamp : PISC_TIMESTAMP; tm_date : PCTimeStructure); - stdcall; + {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} + -{ stubs for install functions } -function isc_install_clear_options_stub(hOption: POPTIONS_HANDLE):MSG_NO; stdcall; -function isc_install_execute_stub(hOption: OPTIONS_HANDLE; - src_dir: TEXT; - dest_dir: TEXT; - status_func: FP_STATUS; - status_data: pointer; - error_func: FP_ERROR; - error_data: pointer; - uninstal_file_name: TEXT):MSG_NO; stdcall; -function isc_install_get_info_stub(info_type :integer; - option :OPT; - info_buffer : Pointer; - buf_len : Cardinal): MSG_NO; stdcall; -function isc_install_get_message_stub(hOption: OPTIONS_HANDLE; - message_no: MSG_NO; - message_txt: Pointer; - message_len: Cardinal):MSG_NO; stdcall; -function isc_install_load_external_text_stub(msg_file_name: TEXT):MSG_NO; stdcall; -function isc_install_precheck_stub(hOption: OPTIONS_HANDLE; - src_dir: TEXT; - dest_dir: TEXT):MSG_NO; stdcall; -function isc_install_set_option_stub(hOption: POPTIONS_HANDLE; - option: OPT):MSG_NO; stdcall; -function isc_uninstall_execute_stub(uninstall_file_name: TEXT; - status_func: FP_STATUS; - status_data: pointer; - error_func: FP_ERROR; - error_data: pointer):MSG_NO; stdcall; -function isc_uninstall_precheck_stub(uninstall_file_name: TEXT):MSG_NO; stdcall; -function isc_install_unset_option_stub(hOption: POPTIONS_HANDLE; - option: OPT):MSG_NO; stdcall; +var IBServiceAPIPresent: boolean; implementation -uses Sysutils, IB; +uses Sysutils, IB, Dynlibs; var - IBLibrary: THandle; - IBInstallLibrary: THandle; - IBClientVersion: Integer; + IBLibrary: TLibHandle; procedure LoadIBLibrary; @@ -210,12 +174,54 @@ procedure LoadIBLibrary; begin Result := GetProcAddress(IBLibrary, ProcName); if not Assigned(Result) then - RaiseLastWin32Error; + raise Exception.Create('Unable to load Firebird Client Library'); + end; +{$IFDEF LINUX } + function InternalLoadLibrary: TLibHandle; + var LibName: string; + begin + //Use default unless FBLIB overrides + LibName := GetEnvironmentVariable('FBLIB'); + if LibName = '' then LibName := FIREBIRD_SO; + Result := LoadLibrary(LibName); + end; +{$ELSE} +// "Else" is currently Windozze + function InternalLoadLibrary: TLibHandle; + var InstallDir: string; + dllPathName: string; + begin + //First look for Firebird Embedded Server in installation dir + InstallDir := ExtractFilePath(Application.ExeName); + if FileExists(InstallDir + FIREBIRD_EMBEDDED) then + begin + dllPathName := InstallDir + FIREBIRD_EMBEDDED; + Result := LoadLibrary(dllPathName) + end + else + //Otherwise look for Firebird Client in installation dir + if FileExists(InstallDir + FIREBIRD_CLIENT) then + begin + //assume firebird.conf and firebird.msg in same dir + SetEnvironmentVariable('FIREBIRD',InstallDir); + dllPathName := InstallDir +FIREBIRD_CLIENT; + Result := LoadLibrary(dllPathName) + end + else + //Otherwise see if Firebird client is in path + //and rely on registry for location of firebird.conf and firebird.msg + begin + Result := LoadLibrary(FIREBIRD_CLIENT); + if Result <= HINSTANCE_ERROR then + //well maybe InterBase is present... + Result := LoadLibrary(IBASE_DLL); + end end; +{$ENDIF} begin - IBLibrary := LoadLibrary(PChar(IBASE_DLL)); - if (IBLibrary > HINSTANCE_ERROR) then + IBLibrary := InternalLoadLibrary; + if (IBLibrary <> NilHandle) then begin BLOB_get := GetProcAddr('BLOB_get'); {do not localize} BLOB_put := GetProcAddr('BLOB_put'); {do not localize} @@ -259,7 +265,7 @@ begin isc_delete_user := GetProcAddr('isc_delete_user'); {do not localize} isc_modify_user := GetProcAddr('isc_modify_user'); {do not localize} - IBClientVersion := 6; + IBServiceAPIPresent := true; isc_rollback_retaining := GetProcAddress(IBLibrary, 'isc_rollback_retaining'); {do not localize} if Assigned(isc_rollback_retaining) then begin @@ -275,7 +281,7 @@ begin isc_encode_timestamp := GetProcAddr('isc_encode_timestamp'); {do not localize} end else begin - IBClientVersion := 5; + IBServiceAPIPresent := false; isc_rollback_retaining := isc_rollback_retaining_stub; isc_service_attach := isc_service_attach_stub; isc_service_detach := isc_service_detach_stub; @@ -293,64 +299,18 @@ end; procedure FreeIBLibrary; begin - if IBLibrary > HINSTANCE_ERROR then + if IBLibrary <> NilHandle then begin FreeLibrary(IBLibrary); IBLibrary := 0; end; end; -procedure LoadIBInstallLibrary; - - function GetProcAddr(ProcName: PChar): Pointer; - begin - Result := GetProcAddress(IBInstallLibrary, ProcName); - if not Assigned(Result) then RaiseLastWin32Error; - end; - -begin - IBInstallLibrary := LoadLibrary(PChar(IB_INSTALL_DLL)); - if (IBInstallLibrary > HINSTANCE_ERROR) then - begin - isc_install_clear_options := GetProcAddr('isc_install_clear_options'); {do not localize} - isc_install_execute := GetProcAddr('isc_install_execute'); {do not localize} - isc_install_get_info := GetProcAddr('isc_install_get_info'); {do not localize} - isc_install_get_message := GetProcAddr('isc_install_get_message'); {do not localize} - isc_install_load_external_text := GetProcAddr('isc_install_load_external_text'); {do not localize} - isc_install_precheck := GetProcAddr('isc_install_precheck'); {do not localize} - isc_install_set_option := GetProcAddr('isc_install_set_option'); {do not localize} - isc_uninstall_execute := GetProcAddr('isc_uninstall_execute'); {do not localize} - isc_uninstall_precheck := GetProcAddr('isc_uninstall_precheck'); {do not localize} - isc_install_unset_option := GetProcAddr('isc_install_unset_option'); {do not localize} - end - else begin - isc_install_clear_options := isc_install_clear_options_stub; - isc_install_execute := isc_install_execute_stub; - isc_install_get_info := isc_install_get_info_stub; - isc_install_get_message := isc_install_get_message_stub; - isc_install_load_external_text := isc_install_load_external_text_stub; - isc_install_precheck := isc_install_precheck_stub; - isc_install_set_option := isc_install_set_option_stub; - isc_uninstall_execute := isc_uninstall_execute_stub; - isc_uninstall_precheck := isc_uninstall_precheck_stub; - isc_install_unset_option := isc_install_unset_option_stub; - end; -end; - -procedure FreeIBInstallLibrary; -begin - if IBInstallLibrary > HINSTANCE_ERROR then - begin - FreeLibrary(IBInstallLibrary); - IBInstallLibrary := 0; - end; -end; - function TryIBLoad: Boolean; begin - if (IBLibrary <= HINSTANCE_ERROR) then + if (IBLibrary = NilHandle) then LoadIBLibrary; - if (IBLibrary <= HINSTANCE_ERROR) then + if (IBLibrary = NilHandle) then result := False else result := True; @@ -362,23 +322,10 @@ begin IBError(ibxeInterBaseMissing, [nil]); end; -function GetIBClientVersion: Integer; -begin - CheckIBLoaded; - result := IBClientVersion; -end; - -procedure CheckIBInstallLoaded; -begin - if (IBInstallLibrary <= HINSTANCE_ERROR) then - LoadIBInstallLibrary; - if (IBInstallLibrary <= HINSTANCE_ERROR) then - IBError(ibxeInterBaseInstallMissing, [nil]); -end; function isc_rollback_retaining_stub(status_vector : PISC_STATUS; tran_handle : PISC_TR_HANDLE): - ISC_STATUS; stdcall; + ISC_STATUS; {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} begin Result := 0; IBError(ibxeIB60feature, ['isc_rollback_retaining']); {do not localize} @@ -390,7 +337,7 @@ function isc_service_attach_stub(status_ service_handle : PISC_SVC_HANDLE; isc_arg5 : UShort; isc_arg6 : PChar): - ISC_STATUS; stdcall; + ISC_STATUS; {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} begin Result := 0; IBError(ibxeIB60feature, ['isc_service_attach']); {do not localize} @@ -398,7 +345,7 @@ end; function isc_service_detach_stub(status_vector : PISC_STATUS; service_handle : PISC_SVC_HANDLE): - ISC_STATUS; stdcall; + ISC_STATUS; {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} begin Result := 0; IBError(ibxeIB60feature, ['isc_service_detach']); {do not localize} @@ -413,7 +360,7 @@ function isc_service_query_stub(status_v isc_arg7 : PChar; isc_arg8 : UShort; isc_arg9 : PChar): - ISC_STATUS; stdcall; + ISC_STATUS; {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} begin Result := 0; IBError(ibxeIB60feature, ['isc_service_query']); {do not localize} @@ -424,7 +371,7 @@ function isc_service_start_stub(status_v recv_handle : PISC_SVC_HANDLE; isc_arg4 : UShort; isc_arg5 : PChar): - ISC_STATUS; stdcall; + ISC_STATUS; {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} begin Result := 0; IBError(ibxeIB60feature, ['isc_service_start']); {do not localize} @@ -432,130 +379,47 @@ end; procedure isc_encode_sql_date_stub(tm_date : PCTimeStructure; ib_date : PISC_DATE); - stdcall; + {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} begin IBError(ibxeIB60feature, ['isc_encode_sql_date']); {do not localize} end; procedure isc_encode_sql_time_stub(tm_date : PCTimeStructure; ib_time : PISC_TIME); - stdcall; + {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} begin IBError(ibxeIB60feature, ['isc_encode_sql_time']); {do not localize} end; procedure isc_encode_timestamp_stub(tm_date : PCTimeStructure; ib_timestamp : PISC_TIMESTAMP); - stdcall; + {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} begin IBError(ibxeIB60feature, ['isc_encode_sql_timestamp']); {do not localize} end; procedure isc_decode_sql_date_stub(ib_date : PISC_DATE; tm_date : PCTimeStructure); - stdcall; + {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} begin IBError(ibxeIB60feature, ['isc_decode_sql_date']); {do not localize} end; procedure isc_decode_sql_time_stub(ib_time : PISC_TIME; tm_date : PCTimeStructure); - stdcall; + {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} begin IBError(ibxeIB60feature, ['isc_decode_sql_time']); {do not localize} end; procedure isc_decode_timestamp_stub(ib_timestamp : PISC_TIMESTAMP; tm_date : PCTimeStructure); - stdcall; + {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} begin IBError(ibxeIB60feature, ['isc_decode_timestamp']); {do not localize} end; - -function isc_install_clear_options_stub(hOption: POPTIONS_HANDLE):MSG_NO; stdcall; -begin - Result := 0; - IBError(ibxeIB60feature, ['isc_install_xxx ']); {do not localize} -end; - -function isc_install_execute_stub(hOption: OPTIONS_HANDLE; - src_dir: TEXT; - dest_dir: TEXT; - status_func: FP_STATUS; - status_data: pointer; - error_func: FP_ERROR; - error_data: pointer; - uninstal_file_name: TEXT):MSG_NO; stdcall; -begin - Result := 0; - IBError(ibxeIB60feature, ['isc_install_xxx ']); {do not localize} -end; - -function isc_install_get_info_stub(info_type :integer; - option :OPT; - info_buffer : Pointer; - buf_len : Cardinal): MSG_NO; stdcall; -begin - Result := 0; - IBError(ibxeIB60feature, ['isc_install_xxx ']); {do not localize} -end; - -function isc_install_get_message_stub(hOption: OPTIONS_HANDLE; - message_no: MSG_NO; - message_txt: Pointer; - message_len: Cardinal):MSG_NO; stdcall; -begin - Result := 0; - IBError(ibxeIB60feature, ['isc_install_xxx ']); {do not localize} -end; - -function isc_install_load_external_text_stub(msg_file_name: TEXT):MSG_NO; stdcall; -begin - Result := 0; - IBError(ibxeIB60feature, ['isc_install_xxx ']); {do not localize} -end; - -function isc_install_precheck_stub(hOption: OPTIONS_HANDLE; - src_dir: TEXT; - dest_dir: TEXT):MSG_NO; stdcall; -begin - Result := 0; - IBError(ibxeIB60feature, ['isc_install_xxx ']); {do not localize} -end; - -function isc_install_set_option_stub(hOption: POPTIONS_HANDLE; - option: OPT):MSG_NO; stdcall; -begin - Result := 0; - IBError(ibxeIB60feature, ['isc_install_xxx ']); {do not localize} -end; - -function isc_uninstall_execute_stub(uninstall_file_name: TEXT; - status_func: FP_STATUS; - status_data: pointer; - error_func: FP_ERROR; - error_data: pointer):MSG_NO; stdcall; -begin - Result := 0; - IBError(ibxeIB60feature, ['isc_install_xxx ']); {do not localize} -end; - -function isc_uninstall_precheck_stub(uninstall_file_name: TEXT):MSG_NO; stdcall; -begin - Result := 0; - IBError(ibxeIB60feature, ['isc_install_xxx ']); {do not localize} -end; - -function isc_install_unset_option_stub(hOption: POPTIONS_HANDLE; - option: OPT):MSG_NO; stdcall; -begin - Result := 0; - IBError(ibxeIB60feature, ['isc_install_xxx ']); {do not localize} -end; - initialization finalization FreeIBLibrary; - FreeIBInstallLibrary; end.