ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/runtime/IBIntf.pas
Revision: 31
Committed: Tue Jul 14 15:31:25 2015 UTC (8 years, 9 months ago) by tony
Content type: text/x-pascal
File size: 22215 byte(s)
Log Message:
Committing updates for Release R1-3-0

File Contents

# User Rev Content
1 tony 17 {************************************************************************}
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     { }
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    
34     unit IBIntf;
35    
36     {$Mode Delphi}
37    
38     interface
39    
40     uses
41     {$IFDEF WINDOWS }
42     Windows,
43     {$ELSE}
44     unix,
45     {$ENDIF}
46     IBHeader,IBExternals;
47    
48     var
49     BLOB_get: TBLOB_get;
50     BLOB_put: TBLOB_put;
51     isc_sqlcode: Tisc_sqlcode;
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;
59     isc_get_segment: Tisc_get_segment;
60     isc_put_segment: Tisc_put_segment;
61     isc_create_blob2: Tisc_create_blob2;
62     isc_service_attach: Tisc_service_attach;
63     isc_service_detach: Tisc_service_detach;
64     isc_service_query: Tisc_service_query;
65     isc_service_start: Tisc_service_start;
66     isc_decode_date: Tisc_decode_date;
67     isc_decode_sql_date: Tisc_decode_sql_date;
68     isc_decode_sql_time: Tisc_decode_sql_time;
69     isc_decode_timestamp: Tisc_decode_timestamp;
70     isc_encode_date: Tisc_encode_date;
71     isc_encode_sql_date: Tisc_encode_sql_date;
72     isc_encode_sql_time: Tisc_encode_sql_time;
73     isc_encode_timestamp: Tisc_encode_timestamp;
74     isc_dsql_free_statement: Tisc_dsql_free_statement;
75     isc_dsql_execute2: Tisc_dsql_execute2;
76     isc_dsql_execute: Tisc_dsql_execute;
77     isc_dsql_set_cursor_name: Tisc_dsql_set_cursor_name;
78     isc_dsql_fetch: Tisc_dsql_fetch;
79     isc_dsql_sql_info: Tisc_dsql_sql_info;
80     isc_dsql_alloc_statement2: Tisc_dsql_alloc_statement2;
81     isc_dsql_prepare: Tisc_dsql_prepare;
82     isc_dsql_describe_bind: Tisc_dsql_describe_bind;
83     isc_dsql_describe: Tisc_dsql_describe;
84     isc_dsql_execute_immediate: Tisc_dsql_execute_immediate;
85     isc_drop_database: Tisc_drop_database;
86     isc_detach_database: Tisc_detach_database;
87     isc_attach_database: Tisc_attach_database;
88     isc_database_info: Tisc_database_info;
89     isc_start_multiple: Tisc_start_multiple;
90     isc_commit_transaction: Tisc_commit_transaction;
91     isc_commit_retaining: Tisc_commit_retaining;
92     isc_rollback_transaction: Tisc_rollback_transaction;
93     isc_rollback_retaining: Tisc_rollback_retaining;
94     isc_cancel_events: Tisc_cancel_events;
95     isc_que_events: Tisc_que_events;
96     isc_event_counts: Tisc_event_counts;
97     isc_event_block: Tisc_event_block;
98     isc_free: Tisc_free;
99     isc_add_user : Tisc_add_user;
100     isc_delete_user: Tisc_delete_user;
101     isc_modify_user: Tisc_modify_user;
102    
103    
104     { Library Initialization }
105     procedure LoadIBLibrary;
106     procedure FreeIBLibrary;
107     function TryIBLoad: Boolean;
108     procedure CheckIBLoaded;
109    
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 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 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 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;
127     isc_arg4 : UShort;
128     isc_arg5 : PChar;
129     isc_arg6 : UShort;
130     isc_arg7 : PChar;
131     isc_arg8 : UShort;
132     isc_arg9 : PChar):
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 WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
140    
141     procedure isc_encode_sql_date_stub(tm_date : PCTimeStructure;
142     ib_date : PISC_DATE);
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 WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
148    
149     procedure isc_encode_timestamp_stub(tm_date : PCTimeStructure;
150     ib_timestamp : PISC_TIMESTAMP);
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 WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
156    
157     procedure isc_decode_sql_time_stub(ib_time : PISC_TIME;
158     tm_date : PCTimeStructure);
159     {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
160    
161     procedure isc_decode_timestamp_stub(ib_timestamp : PISC_TIMESTAMP;
162     tm_date : PCTimeStructure);
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 tony 27 uses Sysutils, IB, Dynlibs, Classes
178 tony 17 {$IFDEF WINDOWS}
179 tony 31 , Registry
180 tony 17 {$ENDIF}
181     ;
182    
183     var
184     IBLibrary: TLibHandle;
185    
186     procedure LoadIBLibrary;
187    
188     function GetProcAddr(ProcName: PChar): Pointer;
189     begin
190     Result := GetProcAddress(IBLibrary, ProcName);
191     if not Assigned(Result) then
192     raise Exception.Create('Unable to load Firebird Client Library');
193     end;
194     {$IFDEF UNIX }
195 tony 27 function FindLibrary(LibNameList: string): TLibHandle;
196     var LibNames: TStringList;
197     i: integer;
198     begin
199     Result := NilHandle;
200     LibNames := TStringList.Create;
201     try
202     LibNames.Delimiter := ':';
203     LibNames.StrictDelimiter := true;
204     LibNames.DelimitedText := LibNameList; {Split list on semi-colon}
205     for i := 0 to LibNames.Count - 1 do
206     begin
207     Result := LoadLibrary(LibNames[i]);
208     if Result <> NilHandle then Exit;
209     end;
210     finally
211     LibNames.Free;
212     end;
213     end;
214    
215 tony 17 function InternalLoadLibrary: TLibHandle;
216     var LibName: string;
217     begin
218     //Use default unless FBLIB overrides
219     LibName := GetEnvironmentVariable('FBLIB');
220     if LibName = '' then
221     begin
222     if assigned(OnGetLibraryName) then
223     OnGetLibraryName(LibName)
224     else
225     LibName := FIREBIRD_SO2;
226     end;
227 tony 27 Result := FindLibrary(LibName);
228 tony 17 {$IFDEF DARWIN}
229     if Result = NilHandle then
230     begin
231     {See http://paulbeachsblog.blogspot.co.uk/2008/03/where-is-libfbclientdylib-on-macosx.html
232     Try loading direct from Firebird Framework}
233    
234     LibName := '/Library/Frameworks/Firebird.framework/Firebird';
235     Result := LoadLibrary(LibName);
236     end
237     {$ENDIF}
238     end;
239     {$ENDIF}
240     {$IFDEF WINDOWS}
241     function InternalLoadLibrary: TLibHandle;
242     var InstallDir: string;
243     dllPathName: string;
244     begin
245     if assigned(OnGetLibraryName) then
246     begin
247     OnGetLibraryName(dllPathName);
248     Result := LoadLibrary(dllPathName);
249     Exit
250     end;
251    
252     //First look for Firebird Embedded Server in installation dir
253 tony 31 InstallDir := ExtractFilePath(Paramstr(0)); {Using ParamStr(0) assumes windows conventions}
254 tony 17 if FileExists(InstallDir + FIREBIRD_EMBEDDED) then
255     begin
256     dllPathName := InstallDir + FIREBIRD_EMBEDDED;
257     Result := LoadLibrary(dllPathName)
258     end
259     else
260     //Otherwise look for Firebird Client in installation dir
261     if FileExists(InstallDir + FIREBIRD_CLIENT) then
262     begin
263     //assume firebird.conf and firebird.msg in same dir
264     SetEnvironmentVariable('FIREBIRD',PChar(InstallDir));
265     dllPathName := InstallDir +FIREBIRD_CLIENT;
266     Result := LoadLibrary(dllPathName)
267     end
268     else
269     //Use Registry key if it exists to locate library
270     begin
271     with TRegistry.Create do
272     try
273     RootKey := HKEY_LOCAL_MACHINE;
274     if OpenKey('SOFTWARE\Firebird Project\Firebird Server\Instances',false) then
275     begin
276     if ValueExists('DefaultInstance') then
277     begin
278     dllPathName := ReadString('DefaultInstance') + 'bin' + DirectorySeparator + FIREBIRD_CLIENT;
279     if FileExists(dllPathName) then
280     begin
281     Result := LoadLibrary(dllPathName);
282     Exit
283     end
284     end
285     end
286     finally
287     Free
288     end;
289    
290     //Otherwise see if Firebird client is in path
291     //and rely on registry for location of firebird.conf and firebird.msg
292     Result := LoadLibrary(FIREBIRD_CLIENT);
293     if Result <= HINSTANCE_ERROR then
294     //well maybe InterBase is present...
295     Result := LoadLibrary(IBASE_DLL);
296     end
297     end;
298     {$ENDIF}
299    
300     begin
301     IBLibrary := InternalLoadLibrary;
302     if (IBLibrary <> NilHandle) then
303     begin
304     BLOB_get := GetProcAddr('BLOB_get'); {do not localize}
305     BLOB_put := GetProcAddr('BLOB_put'); {do not localize}
306     isc_sqlcode := GetProcAddr('isc_sqlcode'); {do not localize}
307     isc_sql_interprete := GetProcAddr('isc_sql_interprete'); {do not localize}
308     isc_interprete := GetProcAddr('isc_interprete'); {do not localize}
309     isc_vax_integer := GetProcAddr('isc_vax_integer'); {do not localize}
310     isc_portable_integer := GetProcAddr('isc_portable_integer'); {do not localize}
311     isc_blob_info := GetProcAddr('isc_blob_info'); {do not localize}
312     isc_open_blob2 := GetProcAddr('isc_open_blob2'); {do not localize}
313     isc_close_blob := GetProcAddr('isc_close_blob'); {do not localize}
314     isc_get_segment := GetProcAddr('isc_get_segment'); {do not localize}
315     isc_put_segment := GetProcAddr('isc_put_segment'); {do not localize}
316     isc_create_blob2 := GetProcAddr('isc_create_blob2'); {do not localize}
317     isc_decode_date := GetProcAddr('isc_decode_date'); {do not localize}
318     isc_encode_date := GetProcAddr('isc_encode_date'); {do not localize}
319     isc_dsql_free_statement := GetProcAddr('isc_dsql_free_statement'); {do not localize}
320     isc_dsql_execute2 := GetProcAddr('isc_dsql_execute2'); {do not localize}
321     isc_dsql_execute := GetProcAddr('isc_dsql_execute'); {do not localize}
322     isc_dsql_set_cursor_name := GetProcAddr('isc_dsql_set_cursor_name'); {do not localize}
323     isc_dsql_fetch := GetProcAddr('isc_dsql_fetch'); {do not localize}
324     isc_dsql_sql_info := GetProcAddr('isc_dsql_sql_info'); {do not localize}
325     isc_dsql_alloc_statement2 := GetProcAddr('isc_dsql_alloc_statement2'); {do not localize}
326     isc_dsql_prepare := GetProcAddr('isc_dsql_prepare'); {do not localize}
327     isc_dsql_describe_bind := GetProcAddr('isc_dsql_describe_bind'); {do not localize}
328     isc_dsql_describe := GetProcAddr('isc_dsql_describe'); {do not localize}
329     isc_dsql_execute_immediate := GetProcAddr('isc_dsql_execute_immediate'); {do not localize}
330     isc_drop_database := GetProcAddr('isc_drop_database'); {do not localize}
331     isc_detach_database := GetProcAddr('isc_detach_database'); {do not localize}
332     isc_attach_database := GetProcAddr('isc_attach_database'); {do not localize}
333     isc_database_info := GetProcAddr('isc_database_info'); {do not localize}
334     isc_start_multiple := GetProcAddr('isc_start_multiple'); {do not localize}
335     isc_commit_transaction := GetProcAddr('isc_commit_transaction'); {do not localize}
336     isc_commit_retaining := GetProcAddr('isc_commit_retaining'); {do not localize}
337     isc_rollback_transaction := GetProcAddr('isc_rollback_transaction'); {do not localize}
338     isc_cancel_events := GetProcAddr('isc_cancel_events'); {do not localize}
339     isc_que_events := GetProcAddr('isc_que_events'); {do not localize}
340     isc_event_counts := GetProcAddr('isc_event_counts'); {do not localize}
341     isc_event_block := GetProcAddr('isc_event_block'); {do not localize}
342     isc_free := GetProcAddr('isc_free'); {do not localize}
343     isc_add_user := GetProcAddr('isc_add_user'); {do not localize}
344     isc_delete_user := GetProcAddr('isc_delete_user'); {do not localize}
345     isc_modify_user := GetProcAddr('isc_modify_user'); {do not localize}
346    
347     IBServiceAPIPresent := true;
348     isc_rollback_retaining := GetProcAddress(IBLibrary, 'isc_rollback_retaining'); {do not localize}
349     if Assigned(isc_rollback_retaining) then
350     begin
351     isc_service_attach := GetProcAddr('isc_service_attach'); {do not localize}
352     isc_service_detach := GetProcAddr('isc_service_detach'); {do not localize}
353     isc_service_query := GetProcAddr('isc_service_query'); {do not localize}
354     isc_service_start := GetProcAddr('isc_service_start'); {do not localize}
355     isc_decode_sql_date := GetProcAddr('isc_decode_sql_date'); {do not localize}
356     isc_decode_sql_time := GetProcAddr('isc_decode_sql_time'); {do not localize}
357     isc_decode_timestamp := GetProcAddr('isc_decode_timestamp'); {do not localize}
358     isc_encode_sql_date := GetProcAddr('isc_encode_sql_date'); {do not localize}
359     isc_encode_sql_time := GetProcAddr('isc_encode_sql_time'); {do not localize}
360     isc_encode_timestamp := GetProcAddr('isc_encode_timestamp'); {do not localize}
361     end else
362     begin
363     IBServiceAPIPresent := false;
364     isc_rollback_retaining := isc_rollback_retaining_stub;
365     isc_service_attach := isc_service_attach_stub;
366     isc_service_detach := isc_service_detach_stub;
367     isc_service_query := isc_service_query_stub;
368     isc_service_start := isc_service_start_stub;
369     isc_decode_sql_date := isc_decode_sql_date_stub;
370     isc_decode_sql_time := isc_decode_sql_time_stub;
371     isc_decode_timestamp := isc_decode_timestamp_stub;
372     isc_encode_sql_date := isc_encode_sql_date_stub;
373     isc_encode_sql_time := isc_encode_sql_time_stub;
374     isc_encode_timestamp := isc_encode_timestamp_stub;
375     end;
376     end;
377     end;
378    
379     procedure FreeIBLibrary;
380     begin
381     if IBLibrary <> NilHandle then
382     begin
383     FreeLibrary(IBLibrary);
384     IBLibrary := 0;
385     end;
386     end;
387    
388     function TryIBLoad: Boolean;
389     begin
390     if (IBLibrary = NilHandle) then
391     LoadIBLibrary;
392     if (IBLibrary = NilHandle) then
393     result := False
394     else
395     result := True;
396     end;
397    
398     procedure CheckIBLoaded;
399     begin
400     if not TryIBLoad then
401     IBError(ibxeInterBaseMissing, [nil]);
402     end;
403    
404    
405     function isc_rollback_retaining_stub(status_vector : PISC_STATUS;
406     tran_handle : PISC_TR_HANDLE):
407     ISC_STATUS; {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
408     begin
409     Result := 0;
410     IBError(ibxeIB60feature, ['isc_rollback_retaining']); {do not localize}
411     end;
412    
413     function isc_service_attach_stub(status_vector : PISC_STATUS;
414     isc_arg2 : UShort;
415     isc_arg3 : PChar;
416     service_handle : PISC_SVC_HANDLE;
417     isc_arg5 : UShort;
418     isc_arg6 : PChar):
419     ISC_STATUS; {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
420     begin
421     Result := 0;
422     IBError(ibxeIB60feature, ['isc_service_attach']); {do not localize}
423     end;
424    
425     function isc_service_detach_stub(status_vector : PISC_STATUS;
426     service_handle : PISC_SVC_HANDLE):
427     ISC_STATUS; {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
428     begin
429     Result := 0;
430     IBError(ibxeIB60feature, ['isc_service_detach']); {do not localize}
431     end;
432    
433     function isc_service_query_stub(status_vector : PISC_STATUS;
434     service_handle : PISC_SVC_HANDLE;
435     recv_handle : PISC_SVC_HANDLE;
436     isc_arg4 : UShort;
437     isc_arg5 : PChar;
438     isc_arg6 : UShort;
439     isc_arg7 : PChar;
440     isc_arg8 : UShort;
441     isc_arg9 : PChar):
442     ISC_STATUS; {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
443     begin
444     Result := 0;
445     IBError(ibxeIB60feature, ['isc_service_query']); {do not localize}
446     end;
447    
448     function isc_service_start_stub(status_vector : PISC_STATUS;
449     service_handle : PISC_SVC_HANDLE;
450     recv_handle : PISC_SVC_HANDLE;
451     isc_arg4 : UShort;
452     isc_arg5 : PChar):
453     ISC_STATUS; {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
454     begin
455     Result := 0;
456     IBError(ibxeIB60feature, ['isc_service_start']); {do not localize}
457     end;
458    
459     procedure isc_encode_sql_date_stub(tm_date : PCTimeStructure;
460     ib_date : PISC_DATE);
461     {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
462     begin
463     IBError(ibxeIB60feature, ['isc_encode_sql_date']); {do not localize}
464     end;
465    
466     procedure isc_encode_sql_time_stub(tm_date : PCTimeStructure;
467     ib_time : PISC_TIME);
468     {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
469     begin
470     IBError(ibxeIB60feature, ['isc_encode_sql_time']); {do not localize}
471     end;
472    
473     procedure isc_encode_timestamp_stub(tm_date : PCTimeStructure;
474     ib_timestamp : PISC_TIMESTAMP);
475     {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
476     begin
477     IBError(ibxeIB60feature, ['isc_encode_sql_timestamp']); {do not localize}
478     end;
479    
480     procedure isc_decode_sql_date_stub(ib_date : PISC_DATE;
481     tm_date : PCTimeStructure);
482     {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
483     begin
484     IBError(ibxeIB60feature, ['isc_decode_sql_date']); {do not localize}
485     end;
486    
487     procedure isc_decode_sql_time_stub(ib_time : PISC_TIME;
488     tm_date : PCTimeStructure);
489     {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
490     begin
491     IBError(ibxeIB60feature, ['isc_decode_sql_time']); {do not localize}
492     end;
493    
494     procedure isc_decode_timestamp_stub(ib_timestamp : PISC_TIMESTAMP;
495     tm_date : PCTimeStructure);
496     {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
497     begin
498     IBError(ibxeIB60feature, ['isc_decode_timestamp']); {do not localize}
499     end;
500     initialization
501    
502     finalization
503     FreeIBLibrary;
504     end.