1 |
{************************************************************************} |
2 |
{ } |
3 |
{ Borland Delphi Visual Component Library } |
4 |
{ InterBase Express core components } |
5 |
{ } |
6 |
{ Copyright (c) 1998-2000 Inprise Corporation } |
7 |
{ } |
8 |
{ InterBase Express is based in part on the product } |
9 |
{ Free IB Components, written by Gregory H. Deatz for } |
10 |
{ Hoagland, Longo, Moran, Dunst & Doukas Company. } |
11 |
{ Free IB Components is used under license. } |
12 |
{ } |
13 |
{ The contents of this file are subject to the InterBase } |
14 |
{ Public License Version 1.0 (the "License"); you may not } |
15 |
{ use this file except in compliance with the License. You } |
16 |
{ may obtain a copy of the License at http://www.Inprise.com/IPL.html } |
17 |
{ Software distributed under the License is distributed on } |
18 |
{ an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either } |
19 |
{ express or implied. See the License for the specific language } |
20 |
{ governing rights and limitations under the License. } |
21 |
{ The Original Code was created by InterBase Software Corporation } |
22 |
{ and its successors. } |
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 } |
28 |
{ } |
29 |
{************************************************************************} |
30 |
|
31 |
unit IBIntf; |
32 |
|
33 |
{$Mode Delphi} |
34 |
|
35 |
interface |
36 |
|
37 |
uses |
38 |
{$IFDEF LINUX } |
39 |
unix, |
40 |
{$ELSE} |
41 |
Windows, |
42 |
{$ENDIF} |
43 |
IBHeader,IBExternals; |
44 |
|
45 |
var |
46 |
BLOB_get: TBLOB_get; |
47 |
BLOB_put: TBLOB_put; |
48 |
isc_sqlcode: Tisc_sqlcode; |
49 |
isc_sql_interprete: Tisc_sql_interprete; |
50 |
isc_interprete: Tisc_interprete; |
51 |
isc_vax_integer: Tisc_vax_integer; |
52 |
isc_blob_info: Tisc_blob_info; |
53 |
isc_open_blob2: Tisc_open_blob2; |
54 |
isc_close_blob: Tisc_close_blob; |
55 |
isc_get_segment: Tisc_get_segment; |
56 |
isc_put_segment: Tisc_put_segment; |
57 |
isc_create_blob2: Tisc_create_blob2; |
58 |
isc_service_attach: Tisc_service_attach; |
59 |
isc_service_detach: Tisc_service_detach; |
60 |
isc_service_query: Tisc_service_query; |
61 |
isc_service_start: Tisc_service_start; |
62 |
isc_decode_date: Tisc_decode_date; |
63 |
isc_decode_sql_date: Tisc_decode_sql_date; |
64 |
isc_decode_sql_time: Tisc_decode_sql_time; |
65 |
isc_decode_timestamp: Tisc_decode_timestamp; |
66 |
isc_encode_date: Tisc_encode_date; |
67 |
isc_encode_sql_date: Tisc_encode_sql_date; |
68 |
isc_encode_sql_time: Tisc_encode_sql_time; |
69 |
isc_encode_timestamp: Tisc_encode_timestamp; |
70 |
isc_dsql_free_statement: Tisc_dsql_free_statement; |
71 |
isc_dsql_execute2: Tisc_dsql_execute2; |
72 |
isc_dsql_execute: Tisc_dsql_execute; |
73 |
isc_dsql_set_cursor_name: Tisc_dsql_set_cursor_name; |
74 |
isc_dsql_fetch: Tisc_dsql_fetch; |
75 |
isc_dsql_sql_info: Tisc_dsql_sql_info; |
76 |
isc_dsql_alloc_statement2: Tisc_dsql_alloc_statement2; |
77 |
isc_dsql_prepare: Tisc_dsql_prepare; |
78 |
isc_dsql_describe_bind: Tisc_dsql_describe_bind; |
79 |
isc_dsql_describe: Tisc_dsql_describe; |
80 |
isc_dsql_execute_immediate: Tisc_dsql_execute_immediate; |
81 |
isc_drop_database: Tisc_drop_database; |
82 |
isc_detach_database: Tisc_detach_database; |
83 |
isc_attach_database: Tisc_attach_database; |
84 |
isc_database_info: Tisc_database_info; |
85 |
isc_start_multiple: Tisc_start_multiple; |
86 |
isc_commit_transaction: Tisc_commit_transaction; |
87 |
isc_commit_retaining: Tisc_commit_retaining; |
88 |
isc_rollback_transaction: Tisc_rollback_transaction; |
89 |
isc_rollback_retaining: Tisc_rollback_retaining; |
90 |
isc_cancel_events: Tisc_cancel_events; |
91 |
isc_que_events: Tisc_que_events; |
92 |
isc_event_counts: Tisc_event_counts; |
93 |
isc_event_block: Tisc_event_block; |
94 |
isc_free: Tisc_free; |
95 |
isc_add_user : Tisc_add_user; |
96 |
isc_delete_user: Tisc_delete_user; |
97 |
isc_modify_user: Tisc_modify_user; |
98 |
|
99 |
|
100 |
{ Library Initialization } |
101 |
procedure LoadIBLibrary; |
102 |
procedure FreeIBLibrary; |
103 |
function TryIBLoad: Boolean; |
104 |
procedure CheckIBLoaded; |
105 |
|
106 |
{ Stubs for 6.0 only functions } |
107 |
function isc_rollback_retaining_stub(status_vector : PISC_STATUS; |
108 |
tran_handle : PISC_TR_HANDLE): |
109 |
ISC_STATUS; {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} |
110 |
function isc_service_attach_stub(status_vector : PISC_STATUS; |
111 |
isc_arg2 : UShort; |
112 |
isc_arg3 : PChar; |
113 |
service_handle : PISC_SVC_HANDLE; |
114 |
isc_arg5 : UShort; |
115 |
isc_arg6 : PChar): |
116 |
ISC_STATUS; {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} |
117 |
function isc_service_detach_stub(status_vector : PISC_STATUS; |
118 |
service_handle : PISC_SVC_HANDLE): |
119 |
ISC_STATUS; {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} |
120 |
function isc_service_query_stub(status_vector : PISC_STATUS; |
121 |
service_handle : PISC_SVC_HANDLE; |
122 |
recv_handle : PISC_SVC_HANDLE; |
123 |
isc_arg4 : UShort; |
124 |
isc_arg5 : PChar; |
125 |
isc_arg6 : UShort; |
126 |
isc_arg7 : PChar; |
127 |
isc_arg8 : UShort; |
128 |
isc_arg9 : PChar): |
129 |
ISC_STATUS; {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} |
130 |
function isc_service_start_stub(status_vector : PISC_STATUS; |
131 |
service_handle : PISC_SVC_HANDLE; |
132 |
recv_handle : PISC_SVC_HANDLE; |
133 |
isc_arg4 : UShort; |
134 |
isc_arg5 : PChar): |
135 |
ISC_STATUS; {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} |
136 |
|
137 |
procedure isc_encode_sql_date_stub(tm_date : PCTimeStructure; |
138 |
ib_date : PISC_DATE); |
139 |
{$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} |
140 |
|
141 |
procedure isc_encode_sql_time_stub(tm_date : PCTimeStructure; |
142 |
ib_time : PISC_TIME); |
143 |
{$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} |
144 |
|
145 |
procedure isc_encode_timestamp_stub(tm_date : PCTimeStructure; |
146 |
ib_timestamp : PISC_TIMESTAMP); |
147 |
{$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} |
148 |
|
149 |
procedure isc_decode_sql_date_stub(ib_date : PISC_DATE; |
150 |
tm_date : PCTimeStructure); |
151 |
{$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} |
152 |
|
153 |
procedure isc_decode_sql_time_stub(ib_time : PISC_TIME; |
154 |
tm_date : PCTimeStructure); |
155 |
{$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} |
156 |
|
157 |
procedure isc_decode_timestamp_stub(ib_timestamp : PISC_TIMESTAMP; |
158 |
tm_date : PCTimeStructure); |
159 |
{$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} |
160 |
|
161 |
|
162 |
var IBServiceAPIPresent: boolean; |
163 |
|
164 |
implementation |
165 |
|
166 |
uses Sysutils, IB, Dynlibs; |
167 |
|
168 |
var |
169 |
IBLibrary: TLibHandle; |
170 |
|
171 |
procedure LoadIBLibrary; |
172 |
|
173 |
function GetProcAddr(ProcName: PChar): Pointer; |
174 |
begin |
175 |
Result := GetProcAddress(IBLibrary, ProcName); |
176 |
if not Assigned(Result) then |
177 |
raise Exception.Create('Unable to load Firebird Client Library'); |
178 |
end; |
179 |
{$IFDEF LINUX } |
180 |
function InternalLoadLibrary: TLibHandle; |
181 |
var LibName: string; |
182 |
begin |
183 |
//Use default unless FBLIB overrides |
184 |
LibName := GetEnvironmentVariable('FBLIB'); |
185 |
if LibName = '' then LibName := FIREBIRD_SO; |
186 |
Result := LoadLibrary(LibName); |
187 |
end; |
188 |
{$ELSE} |
189 |
// "Else" is currently Windozze |
190 |
function InternalLoadLibrary: TLibHandle; |
191 |
var InstallDir: string; |
192 |
dllPathName: string; |
193 |
begin |
194 |
//First look for Firebird Embedded Server in installation dir |
195 |
InstallDir := ExtractFilePath(Application.ExeName); |
196 |
if FileExists(InstallDir + FIREBIRD_EMBEDDED) then |
197 |
begin |
198 |
dllPathName := InstallDir + FIREBIRD_EMBEDDED; |
199 |
Result := LoadLibrary(dllPathName) |
200 |
end |
201 |
else |
202 |
//Otherwise look for Firebird Client in installation dir |
203 |
if FileExists(InstallDir + FIREBIRD_CLIENT) then |
204 |
begin |
205 |
//assume firebird.conf and firebird.msg in same dir |
206 |
SetEnvironmentVariable('FIREBIRD',InstallDir); |
207 |
dllPathName := InstallDir +FIREBIRD_CLIENT; |
208 |
Result := LoadLibrary(dllPathName) |
209 |
end |
210 |
else |
211 |
//Otherwise see if Firebird client is in path |
212 |
//and rely on registry for location of firebird.conf and firebird.msg |
213 |
begin |
214 |
Result := LoadLibrary(FIREBIRD_CLIENT); |
215 |
if Result <= HINSTANCE_ERROR then |
216 |
//well maybe InterBase is present... |
217 |
Result := LoadLibrary(IBASE_DLL); |
218 |
end |
219 |
end; |
220 |
{$ENDIF} |
221 |
|
222 |
begin |
223 |
IBLibrary := InternalLoadLibrary; |
224 |
if (IBLibrary <> NilHandle) then |
225 |
begin |
226 |
BLOB_get := GetProcAddr('BLOB_get'); {do not localize} |
227 |
BLOB_put := GetProcAddr('BLOB_put'); {do not localize} |
228 |
isc_sqlcode := GetProcAddr('isc_sqlcode'); {do not localize} |
229 |
isc_sql_interprete := GetProcAddr('isc_sql_interprete'); {do not localize} |
230 |
isc_interprete := GetProcAddr('isc_interprete'); {do not localize} |
231 |
isc_vax_integer := GetProcAddr('isc_vax_integer'); {do not localize} |
232 |
isc_blob_info := GetProcAddr('isc_blob_info'); {do not localize} |
233 |
isc_open_blob2 := GetProcAddr('isc_open_blob2'); {do not localize} |
234 |
isc_close_blob := GetProcAddr('isc_close_blob'); {do not localize} |
235 |
isc_get_segment := GetProcAddr('isc_get_segment'); {do not localize} |
236 |
isc_put_segment := GetProcAddr('isc_put_segment'); {do not localize} |
237 |
isc_create_blob2 := GetProcAddr('isc_create_blob2'); {do not localize} |
238 |
isc_decode_date := GetProcAddr('isc_decode_date'); {do not localize} |
239 |
isc_encode_date := GetProcAddr('isc_encode_date'); {do not localize} |
240 |
isc_dsql_free_statement := GetProcAddr('isc_dsql_free_statement'); {do not localize} |
241 |
isc_dsql_execute2 := GetProcAddr('isc_dsql_execute2'); {do not localize} |
242 |
isc_dsql_execute := GetProcAddr('isc_dsql_execute'); {do not localize} |
243 |
isc_dsql_set_cursor_name := GetProcAddr('isc_dsql_set_cursor_name'); {do not localize} |
244 |
isc_dsql_fetch := GetProcAddr('isc_dsql_fetch'); {do not localize} |
245 |
isc_dsql_sql_info := GetProcAddr('isc_dsql_sql_info'); {do not localize} |
246 |
isc_dsql_alloc_statement2 := GetProcAddr('isc_dsql_alloc_statement2'); {do not localize} |
247 |
isc_dsql_prepare := GetProcAddr('isc_dsql_prepare'); {do not localize} |
248 |
isc_dsql_describe_bind := GetProcAddr('isc_dsql_describe_bind'); {do not localize} |
249 |
isc_dsql_describe := GetProcAddr('isc_dsql_describe'); {do not localize} |
250 |
isc_dsql_execute_immediate := GetProcAddr('isc_dsql_execute_immediate'); {do not localize} |
251 |
isc_drop_database := GetProcAddr('isc_drop_database'); {do not localize} |
252 |
isc_detach_database := GetProcAddr('isc_detach_database'); {do not localize} |
253 |
isc_attach_database := GetProcAddr('isc_attach_database'); {do not localize} |
254 |
isc_database_info := GetProcAddr('isc_database_info'); {do not localize} |
255 |
isc_start_multiple := GetProcAddr('isc_start_multiple'); {do not localize} |
256 |
isc_commit_transaction := GetProcAddr('isc_commit_transaction'); {do not localize} |
257 |
isc_commit_retaining := GetProcAddr('isc_commit_retaining'); {do not localize} |
258 |
isc_rollback_transaction := GetProcAddr('isc_rollback_transaction'); {do not localize} |
259 |
isc_cancel_events := GetProcAddr('isc_cancel_events'); {do not localize} |
260 |
isc_que_events := GetProcAddr('isc_que_events'); {do not localize} |
261 |
isc_event_counts := GetProcAddr('isc_event_counts'); {do not localize} |
262 |
isc_event_block := GetProcAddr('isc_event_block'); {do not localize} |
263 |
isc_free := GetProcAddr('isc_free'); {do not localize} |
264 |
isc_add_user := GetProcAddr('isc_add_user'); {do not localize} |
265 |
isc_delete_user := GetProcAddr('isc_delete_user'); {do not localize} |
266 |
isc_modify_user := GetProcAddr('isc_modify_user'); {do not localize} |
267 |
|
268 |
IBServiceAPIPresent := true; |
269 |
isc_rollback_retaining := GetProcAddress(IBLibrary, 'isc_rollback_retaining'); {do not localize} |
270 |
if Assigned(isc_rollback_retaining) then |
271 |
begin |
272 |
isc_service_attach := GetProcAddr('isc_service_attach'); {do not localize} |
273 |
isc_service_detach := GetProcAddr('isc_service_detach'); {do not localize} |
274 |
isc_service_query := GetProcAddr('isc_service_query'); {do not localize} |
275 |
isc_service_start := GetProcAddr('isc_service_start'); {do not localize} |
276 |
isc_decode_sql_date := GetProcAddr('isc_decode_sql_date'); {do not localize} |
277 |
isc_decode_sql_time := GetProcAddr('isc_decode_sql_time'); {do not localize} |
278 |
isc_decode_timestamp := GetProcAddr('isc_decode_timestamp'); {do not localize} |
279 |
isc_encode_sql_date := GetProcAddr('isc_encode_sql_date'); {do not localize} |
280 |
isc_encode_sql_time := GetProcAddr('isc_encode_sql_time'); {do not localize} |
281 |
isc_encode_timestamp := GetProcAddr('isc_encode_timestamp'); {do not localize} |
282 |
end else |
283 |
begin |
284 |
IBServiceAPIPresent := false; |
285 |
isc_rollback_retaining := isc_rollback_retaining_stub; |
286 |
isc_service_attach := isc_service_attach_stub; |
287 |
isc_service_detach := isc_service_detach_stub; |
288 |
isc_service_query := isc_service_query_stub; |
289 |
isc_service_start := isc_service_start_stub; |
290 |
isc_decode_sql_date := isc_decode_sql_date_stub; |
291 |
isc_decode_sql_time := isc_decode_sql_time_stub; |
292 |
isc_decode_timestamp := isc_decode_timestamp_stub; |
293 |
isc_encode_sql_date := isc_encode_sql_date_stub; |
294 |
isc_encode_sql_time := isc_encode_sql_time_stub; |
295 |
isc_encode_timestamp := isc_encode_timestamp_stub; |
296 |
end; |
297 |
end; |
298 |
end; |
299 |
|
300 |
procedure FreeIBLibrary; |
301 |
begin |
302 |
if IBLibrary <> NilHandle then |
303 |
begin |
304 |
FreeLibrary(IBLibrary); |
305 |
IBLibrary := 0; |
306 |
end; |
307 |
end; |
308 |
|
309 |
function TryIBLoad: Boolean; |
310 |
begin |
311 |
if (IBLibrary = NilHandle) then |
312 |
LoadIBLibrary; |
313 |
if (IBLibrary = NilHandle) then |
314 |
result := False |
315 |
else |
316 |
result := True; |
317 |
end; |
318 |
|
319 |
procedure CheckIBLoaded; |
320 |
begin |
321 |
if not TryIBLoad then |
322 |
IBError(ibxeInterBaseMissing, [nil]); |
323 |
end; |
324 |
|
325 |
|
326 |
function isc_rollback_retaining_stub(status_vector : PISC_STATUS; |
327 |
tran_handle : PISC_TR_HANDLE): |
328 |
ISC_STATUS; {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} |
329 |
begin |
330 |
Result := 0; |
331 |
IBError(ibxeIB60feature, ['isc_rollback_retaining']); {do not localize} |
332 |
end; |
333 |
|
334 |
function isc_service_attach_stub(status_vector : PISC_STATUS; |
335 |
isc_arg2 : UShort; |
336 |
isc_arg3 : PChar; |
337 |
service_handle : PISC_SVC_HANDLE; |
338 |
isc_arg5 : UShort; |
339 |
isc_arg6 : PChar): |
340 |
ISC_STATUS; {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} |
341 |
begin |
342 |
Result := 0; |
343 |
IBError(ibxeIB60feature, ['isc_service_attach']); {do not localize} |
344 |
end; |
345 |
|
346 |
function isc_service_detach_stub(status_vector : PISC_STATUS; |
347 |
service_handle : PISC_SVC_HANDLE): |
348 |
ISC_STATUS; {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} |
349 |
begin |
350 |
Result := 0; |
351 |
IBError(ibxeIB60feature, ['isc_service_detach']); {do not localize} |
352 |
end; |
353 |
|
354 |
function isc_service_query_stub(status_vector : PISC_STATUS; |
355 |
service_handle : PISC_SVC_HANDLE; |
356 |
recv_handle : PISC_SVC_HANDLE; |
357 |
isc_arg4 : UShort; |
358 |
isc_arg5 : PChar; |
359 |
isc_arg6 : UShort; |
360 |
isc_arg7 : PChar; |
361 |
isc_arg8 : UShort; |
362 |
isc_arg9 : PChar): |
363 |
ISC_STATUS; {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} |
364 |
begin |
365 |
Result := 0; |
366 |
IBError(ibxeIB60feature, ['isc_service_query']); {do not localize} |
367 |
end; |
368 |
|
369 |
function isc_service_start_stub(status_vector : PISC_STATUS; |
370 |
service_handle : PISC_SVC_HANDLE; |
371 |
recv_handle : PISC_SVC_HANDLE; |
372 |
isc_arg4 : UShort; |
373 |
isc_arg5 : PChar): |
374 |
ISC_STATUS; {$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} |
375 |
begin |
376 |
Result := 0; |
377 |
IBError(ibxeIB60feature, ['isc_service_start']); {do not localize} |
378 |
end; |
379 |
|
380 |
procedure isc_encode_sql_date_stub(tm_date : PCTimeStructure; |
381 |
ib_date : PISC_DATE); |
382 |
{$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} |
383 |
begin |
384 |
IBError(ibxeIB60feature, ['isc_encode_sql_date']); {do not localize} |
385 |
end; |
386 |
|
387 |
procedure isc_encode_sql_time_stub(tm_date : PCTimeStructure; |
388 |
ib_time : PISC_TIME); |
389 |
{$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} |
390 |
begin |
391 |
IBError(ibxeIB60feature, ['isc_encode_sql_time']); {do not localize} |
392 |
end; |
393 |
|
394 |
procedure isc_encode_timestamp_stub(tm_date : PCTimeStructure; |
395 |
ib_timestamp : PISC_TIMESTAMP); |
396 |
{$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} |
397 |
begin |
398 |
IBError(ibxeIB60feature, ['isc_encode_sql_timestamp']); {do not localize} |
399 |
end; |
400 |
|
401 |
procedure isc_decode_sql_date_stub(ib_date : PISC_DATE; |
402 |
tm_date : PCTimeStructure); |
403 |
{$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} |
404 |
begin |
405 |
IBError(ibxeIB60feature, ['isc_decode_sql_date']); {do not localize} |
406 |
end; |
407 |
|
408 |
procedure isc_decode_sql_time_stub(ib_time : PISC_TIME; |
409 |
tm_date : PCTimeStructure); |
410 |
{$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} |
411 |
begin |
412 |
IBError(ibxeIB60feature, ['isc_decode_sql_time']); {do not localize} |
413 |
end; |
414 |
|
415 |
procedure isc_decode_timestamp_stub(ib_timestamp : PISC_TIMESTAMP; |
416 |
tm_date : PCTimeStructure); |
417 |
{$IFDEF LINUX} cdecl; {$ELSE} stdcall; {$ENDIF} |
418 |
begin |
419 |
IBError(ibxeIB60feature, ['isc_decode_timestamp']); {do not localize} |
420 |
end; |
421 |
initialization |
422 |
|
423 |
finalization |
424 |
FreeIBLibrary; |
425 |
end. |