23 |
|
{ Portions created by Inprise Corporation are Copyright (C) Inprise } |
24 |
|
{ Corporation. All Rights Reserved. } |
25 |
|
{ Contributor(s): Jeff Overcash } |
26 |
< |
{ Tony Whyman, MWA Software (Ported to Lazarus) } |
27 |
< |
{ http://www.mwasoftware.co.uk } |
26 |
> |
{ } |
27 |
> |
{ IBX For Lazarus (Firebird Express) } |
28 |
> |
{ Contributor: Tony Whyman, MWA Software http://www.mwasoftware.co.uk } |
29 |
> |
{ Portions created by MWA Software are copyright McCallum Whyman } |
30 |
> |
{ Associates Ltd 2011 } |
31 |
|
{ } |
32 |
|
{************************************************************************} |
33 |
|
|
38 |
|
interface |
39 |
|
|
40 |
|
uses |
41 |
< |
{$IFDEF LINUX } |
39 |
< |
unix, |
40 |
< |
{$ELSE} |
41 |
> |
{$IFDEF WINDOWS } |
42 |
|
Windows, |
43 |
+ |
{$ELSE} |
44 |
+ |
unix, |
45 |
|
{$ENDIF} |
46 |
|
IBHeader,IBExternals; |
47 |
|
|
52 |
|
isc_sql_interprete: Tisc_sql_interprete; |
53 |
|
isc_interprete: Tisc_interprete; |
54 |
|
isc_vax_integer: Tisc_vax_integer; |
55 |
+ |
isc_portable_integer: Tisc_portable_integer; |
56 |
|
isc_blob_info: Tisc_blob_info; |
57 |
|
isc_open_blob2: Tisc_open_blob2; |
58 |
|
isc_close_blob: Tisc_close_blob; |
110 |
|
{ Stubs for 6.0 only functions } |
111 |
|
function isc_rollback_retaining_stub(status_vector : PISC_STATUS; |
112 |
|
tran_handle : PISC_TR_HANDLE): |
113 |
< |
ISC_STATUS; {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} |
113 |
> |
ISC_STATUS; {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} |
114 |
|
function isc_service_attach_stub(status_vector : PISC_STATUS; |
115 |
|
isc_arg2 : UShort; |
116 |
|
isc_arg3 : PChar; |
117 |
|
service_handle : PISC_SVC_HANDLE; |
118 |
|
isc_arg5 : UShort; |
119 |
|
isc_arg6 : PChar): |
120 |
< |
ISC_STATUS; {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} |
120 |
> |
ISC_STATUS; {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} |
121 |
|
function isc_service_detach_stub(status_vector : PISC_STATUS; |
122 |
|
service_handle : PISC_SVC_HANDLE): |
123 |
< |
ISC_STATUS; {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} |
123 |
> |
ISC_STATUS; {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} |
124 |
|
function isc_service_query_stub(status_vector : PISC_STATUS; |
125 |
|
service_handle : PISC_SVC_HANDLE; |
126 |
|
recv_handle : PISC_SVC_HANDLE; |
130 |
|
isc_arg7 : PChar; |
131 |
|
isc_arg8 : UShort; |
132 |
|
isc_arg9 : PChar): |
133 |
< |
ISC_STATUS; {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} |
133 |
> |
ISC_STATUS; {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} |
134 |
|
function isc_service_start_stub(status_vector : PISC_STATUS; |
135 |
|
service_handle : PISC_SVC_HANDLE; |
136 |
|
recv_handle : PISC_SVC_HANDLE; |
137 |
|
isc_arg4 : UShort; |
138 |
|
isc_arg5 : PChar): |
139 |
< |
ISC_STATUS; {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} |
139 |
> |
ISC_STATUS; {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} |
140 |
|
|
141 |
|
procedure isc_encode_sql_date_stub(tm_date : PCTimeStructure; |
142 |
|
ib_date : PISC_DATE); |
143 |
< |
{$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} |
143 |
> |
{$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} |
144 |
|
|
145 |
|
procedure isc_encode_sql_time_stub(tm_date : PCTimeStructure; |
146 |
|
ib_time : PISC_TIME); |
147 |
< |
{$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} |
147 |
> |
{$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} |
148 |
|
|
149 |
|
procedure isc_encode_timestamp_stub(tm_date : PCTimeStructure; |
150 |
|
ib_timestamp : PISC_TIMESTAMP); |
151 |
< |
{$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} |
151 |
> |
{$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} |
152 |
|
|
153 |
|
procedure isc_decode_sql_date_stub(ib_date : PISC_DATE; |
154 |
|
tm_date : PCTimeStructure); |
155 |
< |
{$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} |
155 |
> |
{$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} |
156 |
|
|
157 |
|
procedure isc_decode_sql_time_stub(ib_time : PISC_TIME; |
158 |
|
tm_date : PCTimeStructure); |
159 |
< |
{$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} |
159 |
> |
{$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} |
160 |
|
|
161 |
|
procedure isc_decode_timestamp_stub(ib_timestamp : PISC_TIMESTAMP; |
162 |
|
tm_date : PCTimeStructure); |
163 |
< |
{$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} |
163 |
> |
{$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} |
164 |
|
|
165 |
|
|
166 |
|
var IBServiceAPIPresent: boolean; |
167 |
|
|
168 |
+ |
type |
169 |
+ |
TOnGetLibraryName = procedure(var libname: string); |
170 |
+ |
|
171 |
+ |
const |
172 |
+ |
OnGetLibraryName: TOnGetLibraryName = nil; |
173 |
+ |
|
174 |
+ |
|
175 |
|
implementation |
176 |
|
|
177 |
< |
uses Sysutils, IB, Dynlibs; |
177 |
> |
uses Sysutils, IB, Dynlibs |
178 |
> |
{$IFDEF WINDOWS} |
179 |
> |
,Forms, Registry |
180 |
> |
{$ENDIF} |
181 |
> |
; |
182 |
|
|
183 |
|
var |
184 |
|
IBLibrary: TLibHandle; |
191 |
|
if not Assigned(Result) then |
192 |
|
raise Exception.Create('Unable to load Firebird Client Library'); |
193 |
|
end; |
194 |
< |
{$IFDEF LINUX } |
194 |
> |
{$IFDEF UNIX } |
195 |
|
function InternalLoadLibrary: TLibHandle; |
196 |
|
var LibName: string; |
197 |
|
begin |
198 |
|
//Use default unless FBLIB overrides |
199 |
|
LibName := GetEnvironmentVariable('FBLIB'); |
200 |
< |
if LibName = '' then LibName := FIREBIRD_SO; |
200 |
> |
if LibName = '' then |
201 |
> |
begin |
202 |
> |
if assigned(OnGetLibraryName) then |
203 |
> |
OnGetLibraryName(LibName) |
204 |
> |
else |
205 |
> |
LibName := FIREBIRD_SO2; |
206 |
> |
end; |
207 |
|
Result := LoadLibrary(LibName); |
208 |
+ |
{$IFDEF DARWIN} |
209 |
+ |
if Result = NilHandle then |
210 |
+ |
begin |
211 |
+ |
{See http://paulbeachsblog.blogspot.co.uk/2008/03/where-is-libfbclientdylib-on-macosx.html |
212 |
+ |
Try loading direct from Firebird Framework} |
213 |
+ |
|
214 |
+ |
LibName := '/Library/Frameworks/Firebird.framework/Firebird'; |
215 |
+ |
Result := LoadLibrary(LibName); |
216 |
+ |
end |
217 |
+ |
{$ENDIF} |
218 |
|
end; |
219 |
< |
{$ELSE} |
220 |
< |
// "Else" is currently Windozze |
219 |
> |
{$ENDIF} |
220 |
> |
{$IFDEF WINDOWS} |
221 |
|
function InternalLoadLibrary: TLibHandle; |
222 |
|
var InstallDir: string; |
223 |
|
dllPathName: string; |
224 |
|
begin |
225 |
+ |
if assigned(OnGetLibraryName) then |
226 |
+ |
begin |
227 |
+ |
OnGetLibraryName(dllPathName); |
228 |
+ |
Result := LoadLibrary(dllPathName); |
229 |
+ |
Exit |
230 |
+ |
end; |
231 |
+ |
|
232 |
|
//First look for Firebird Embedded Server in installation dir |
233 |
|
InstallDir := ExtractFilePath(Application.ExeName); |
234 |
|
if FileExists(InstallDir + FIREBIRD_EMBEDDED) then |
241 |
|
if FileExists(InstallDir + FIREBIRD_CLIENT) then |
242 |
|
begin |
243 |
|
//assume firebird.conf and firebird.msg in same dir |
244 |
< |
SetEnvironmentVariable('FIREBIRD',InstallDir); |
244 |
> |
SetEnvironmentVariable('FIREBIRD',PChar(InstallDir)); |
245 |
|
dllPathName := InstallDir +FIREBIRD_CLIENT; |
246 |
|
Result := LoadLibrary(dllPathName) |
247 |
|
end |
248 |
|
else |
249 |
< |
//Otherwise see if Firebird client is in path |
212 |
< |
//and rely on registry for location of firebird.conf and firebird.msg |
249 |
> |
//Use Registry key if it exists to locate library |
250 |
|
begin |
251 |
+ |
with TRegistry.Create do |
252 |
+ |
try |
253 |
+ |
RootKey := HKEY_LOCAL_MACHINE; |
254 |
+ |
if OpenKey('SOFTWARE\Firebird Project\Firebird Server\Instances',false) then |
255 |
+ |
begin |
256 |
+ |
if ValueExists('DefaultInstance') then |
257 |
+ |
begin |
258 |
+ |
dllPathName := ReadString('DefaultInstance') + 'bin' + DirectorySeparator + FIREBIRD_CLIENT; |
259 |
+ |
if FileExists(dllPathName) then |
260 |
+ |
begin |
261 |
+ |
Result := LoadLibrary(dllPathName); |
262 |
+ |
Exit |
263 |
+ |
end |
264 |
+ |
end |
265 |
+ |
end |
266 |
+ |
finally |
267 |
+ |
Free |
268 |
+ |
end; |
269 |
+ |
|
270 |
+ |
//Otherwise see if Firebird client is in path |
271 |
+ |
//and rely on registry for location of firebird.conf and firebird.msg |
272 |
|
Result := LoadLibrary(FIREBIRD_CLIENT); |
273 |
|
if Result <= HINSTANCE_ERROR then |
274 |
|
//well maybe InterBase is present... |
287 |
|
isc_sql_interprete := GetProcAddr('isc_sql_interprete'); {do not localize} |
288 |
|
isc_interprete := GetProcAddr('isc_interprete'); {do not localize} |
289 |
|
isc_vax_integer := GetProcAddr('isc_vax_integer'); {do not localize} |
290 |
+ |
isc_portable_integer := GetProcAddr('isc_portable_integer'); {do not localize} |
291 |
|
isc_blob_info := GetProcAddr('isc_blob_info'); {do not localize} |
292 |
|
isc_open_blob2 := GetProcAddr('isc_open_blob2'); {do not localize} |
293 |
|
isc_close_blob := GetProcAddr('isc_close_blob'); {do not localize} |
384 |
|
|
385 |
|
function isc_rollback_retaining_stub(status_vector : PISC_STATUS; |
386 |
|
tran_handle : PISC_TR_HANDLE): |
387 |
< |
ISC_STATUS; {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} |
387 |
> |
ISC_STATUS; {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} |
388 |
|
begin |
389 |
|
Result := 0; |
390 |
|
IBError(ibxeIB60feature, ['isc_rollback_retaining']); {do not localize} |
396 |
|
service_handle : PISC_SVC_HANDLE; |
397 |
|
isc_arg5 : UShort; |
398 |
|
isc_arg6 : PChar): |
399 |
< |
ISC_STATUS; {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} |
399 |
> |
ISC_STATUS; {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} |
400 |
|
begin |
401 |
|
Result := 0; |
402 |
|
IBError(ibxeIB60feature, ['isc_service_attach']); {do not localize} |
404 |
|
|
405 |
|
function isc_service_detach_stub(status_vector : PISC_STATUS; |
406 |
|
service_handle : PISC_SVC_HANDLE): |
407 |
< |
ISC_STATUS; {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} |
407 |
> |
ISC_STATUS; {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} |
408 |
|
begin |
409 |
|
Result := 0; |
410 |
|
IBError(ibxeIB60feature, ['isc_service_detach']); {do not localize} |
419 |
|
isc_arg7 : PChar; |
420 |
|
isc_arg8 : UShort; |
421 |
|
isc_arg9 : PChar): |
422 |
< |
ISC_STATUS; {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} |
422 |
> |
ISC_STATUS; {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} |
423 |
|
begin |
424 |
|
Result := 0; |
425 |
|
IBError(ibxeIB60feature, ['isc_service_query']); {do not localize} |
430 |
|
recv_handle : PISC_SVC_HANDLE; |
431 |
|
isc_arg4 : UShort; |
432 |
|
isc_arg5 : PChar): |
433 |
< |
ISC_STATUS; {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} |
433 |
> |
ISC_STATUS; {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} |
434 |
|
begin |
435 |
|
Result := 0; |
436 |
|
IBError(ibxeIB60feature, ['isc_service_start']); {do not localize} |
438 |
|
|
439 |
|
procedure isc_encode_sql_date_stub(tm_date : PCTimeStructure; |
440 |
|
ib_date : PISC_DATE); |
441 |
< |
{$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} |
441 |
> |
{$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} |
442 |
|
begin |
443 |
|
IBError(ibxeIB60feature, ['isc_encode_sql_date']); {do not localize} |
444 |
|
end; |
445 |
|
|
446 |
|
procedure isc_encode_sql_time_stub(tm_date : PCTimeStructure; |
447 |
|
ib_time : PISC_TIME); |
448 |
< |
{$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} |
448 |
> |
{$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} |
449 |
|
begin |
450 |
|
IBError(ibxeIB60feature, ['isc_encode_sql_time']); {do not localize} |
451 |
|
end; |
452 |
|
|
453 |
|
procedure isc_encode_timestamp_stub(tm_date : PCTimeStructure; |
454 |
|
ib_timestamp : PISC_TIMESTAMP); |
455 |
< |
{$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} |
455 |
> |
{$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} |
456 |
|
begin |
457 |
|
IBError(ibxeIB60feature, ['isc_encode_sql_timestamp']); {do not localize} |
458 |
|
end; |
459 |
|
|
460 |
|
procedure isc_decode_sql_date_stub(ib_date : PISC_DATE; |
461 |
|
tm_date : PCTimeStructure); |
462 |
< |
{$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} |
462 |
> |
{$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} |
463 |
|
begin |
464 |
|
IBError(ibxeIB60feature, ['isc_decode_sql_date']); {do not localize} |
465 |
|
end; |
466 |
|
|
467 |
|
procedure isc_decode_sql_time_stub(ib_time : PISC_TIME; |
468 |
|
tm_date : PCTimeStructure); |
469 |
< |
{$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} |
469 |
> |
{$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} |
470 |
|
begin |
471 |
|
IBError(ibxeIB60feature, ['isc_decode_sql_time']); {do not localize} |
472 |
|
end; |
473 |
|
|
474 |
|
procedure isc_decode_timestamp_stub(ib_timestamp : PISC_TIMESTAMP; |
475 |
|
tm_date : PCTimeStructure); |
476 |
< |
{$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} |
476 |
> |
{$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} |
477 |
|
begin |
478 |
|
IBError(ibxeIB60feature, ['isc_decode_timestamp']); {do not localize} |
479 |
|
end; |