ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/branches/udr/client/FBClientAPI.pas
(Generate patch)

Comparing ibx/trunk/fbintf/client/FBClientAPI.pas (file contents):
Revision 56 by tony, Mon Mar 6 10:20:02 2017 UTC vs.
Revision 263 by tony, Thu Dec 6 15:55:01 2018 UTC

# Line 90 | Line 90 | FIREBIRD_CLIENT = 'fbclient.dll'; {do no
90   FIREBIRD_EMBEDDED = 'fbembed.dll';
91   {$ENDIF}
92  
93 {$IFNDEF FPC}
94 type
95  TLibHandle = THandle;
96
97 const
98  NilHandle = 0;
99  DirectorySeparator = '\';
100 {$ENDIF}
101
93   type
94    TStatusVector              = array[0..19] of NativeInt;
95    PStatusVector              = ^TStatusVector;
# Line 125 | Line 116 | type
116      procedure SetIBDataBaseErrorMessages(Value: TIBDataBaseErrorMessages);
117    end;
118  
119 +  { TFBLibrary }
120 +
121 +  TFBLibrary = class(TFBInterfacedObject,IFirebirdLibrary)
122 +  private
123 +    class var FEnvSetupDone: boolean;
124 +    class var FLibraryList: array of IFirebirdLibrary;
125 +    FFirebirdAPI: IFirebirdAPI;
126 +    FRequestedLibName: string;
127 +    function LoadIBLibrary: boolean;
128 +  protected
129 +    FFBLibraryName: string;
130 +    FIBLibrary: TLibHandle;
131 +    procedure FreeFBLibrary;
132 +    function GetOverrideLibName: string;
133 +    class procedure SetupEnvironment;
134 +  protected
135 +    function GetFirebird3API: IFirebirdAPI; virtual; abstract;
136 +    function GetLegacyFirebirdAPI: IFirebirdAPI; virtual; abstract;
137 +  public
138 +    constructor Create(aLibPathName: string='');
139 +    destructor Destroy; override;
140 +    class function GetFBLibrary(aLibPathName: string): IFirebirdLibrary;
141 +    class procedure FreeLibraries;
142 +
143 +    {IFirebirdLibrary}
144 +    function GetHandle: TLibHandle;
145 +    function GetLibraryName: string;
146 +    function GetLibraryFilePath: string;
147 +    function GetFirebirdAPI: IFirebirdAPI;
148 +    property IBLibrary: TLibHandle read FIBLibrary;
149 +  end;
150 +
151    { TFBClientAPI }
152  
153    TFBClientAPI = class(TFBInterfacedObject)
154    private
132    FOwnsIBLibrary: boolean;
155      class var FIBCS: TRTLCriticalSection;
134    procedure LoadIBLibrary;
156    protected
157 <    class var FFBLibraryName: string;
137 <    class var IBLibrary: TLibHandle;
138 <    {$IFDEF WINDOWS}
139 <    class var FFBLibraryPath: string;
140 <    {$ENDIF}
157 >    FFBLibrary: TFBLibrary;
158      function GetProcAddr(ProcName: PAnsiChar): Pointer;
142    function GetOverrideLibName: string;
143    {$IFDEF UNIX}
144    function GetFirebirdLibList: string; virtual; abstract;
145    {$ENDIF}
146    procedure LoadInterface; virtual;
159    public
160      {Taken from legacy API}
161      isc_sqlcode: Tisc_sqlcode;
# Line 153 | Line 165 | type
165      isc_event_block: Tisc_event_block;
166      isc_free: Tisc_free;
167  
168 <    constructor Create;
157 <    destructor Destroy; override;
168 >    constructor Create(aFBLibrary: TFBLibrary);
169      procedure IBAlloc(var P; OldSize, NewSize: Integer);
170      procedure IBDataBaseError;
171 <    procedure SetupEnvironment;
171 >    function LoadInterface: boolean; virtual;
172 >    function GetAPI: IFirebirdAPI; virtual; abstract;
173 >    {$IFDEF UNIX}
174 >    function GetFirebirdLibList: string; virtual; abstract;
175 >    {$ENDIF}
176  
177      {Encode/Decode}
178      procedure EncodeInteger(aValue: integer; len: integer; buffer: PByte);
# Line 174 | Line 189 | type
189      function GetStatus: IStatus; virtual; abstract;
190      function IsLibraryLoaded: boolean;
191      function IsEmbeddedServer: boolean; virtual; abstract;
192 <    function GetLibraryName: string;
193 <    function GetCharsetName(CharSetID: integer): AnsiString;
179 <    function CharSetID2CodePage(CharSetID: integer; var CodePage: TSystemCodePage): boolean;
180 <    function CodePage2CharSetID(CodePage: TSystemCodePage; var CharSetID: integer): boolean;
181 <    function CharSetName2CharSetID(CharSetName: AnsiString; var CharSetID: integer): boolean;
182 <    function CharSetWidth(CharSetID: integer; var Width: integer): boolean;
183 <  end;
184 <
185 < var FirebirdClientAPI: TFBClientAPI = nil;
192 >    function GetFBLibrary: IFirebirdLibrary;
193 > end;
194  
195   implementation
196  
197 < uses IBUtils, Registry, {$IFDEF Unix} initc, {$ENDIF}
197 > uses IBUtils, Registry,
198 >  {$IFDEF Unix} initc, dl, {$ENDIF}
199   {$IFDEF FPC}
200   {$IFDEF WINDOWS }
201   WinDirs,
# Line 196 | Line 205 | WinDirs,
205   {$ENDIF}
206   SysUtils;
207  
208 + const
209 +  IBLocalBufferLength = 512;
210 +  IBBigLocalBufferLength = IBLocalBufferLength * 2;
211 +  IBHugeLocalBufferLength = IBBigLocalBufferLength * 20;
212 +
213   {$IFDEF UNIX}
214   {$I 'include/uloadlibrary.inc'}
215   {$ELSE}
216   {$I 'include/wloadlibrary.inc'}
217   {$ENDIF}
218  
219 < type
220 <  TCharsetMap = record
221 <    CharsetID: integer;
222 <    CharSetName: AnsiString;
223 <    CharSetWidth: integer;
224 <    CodePage: TSystemCodePage;
219 >
220 > { TFBLibrary }
221 >
222 > function TFBLibrary.GetOverrideLibName: string;
223 > begin
224 >  Result := FFBLibraryName;
225 >  if (Result = '') and AllowUseOfFBLIB then
226 >    Result := GetEnvironmentVariable('FBLIB');
227 >  if Result = '' then
228 >  begin
229 >    if assigned(OnGetLibraryName) then
230 >      OnGetLibraryName(Result)
231    end;
232 + end;
233  
234 < const
235 <  CharSetMap: array [0..69] of TCharsetMap = (
236 <  (CharsetID: 0; CharSetName: 'NONE'; CharSetWidth: 1; CodePage: CP_ACP),
237 <  (CharsetID: 1; CharSetName: 'OCTETS'; CharSetWidth: 1; CodePage: CP_NONE),
238 <  (CharsetID: 2; CharSetName: 'ASCII'; CharSetWidth: 1; CodePage: CP_ASCII),
239 <  (CharsetID: 3; CharSetName: 'UNICODE_FSS'; CharSetWidth: 3; CodePage: CP_UTF8),
240 <  (CharsetID: 4; CharSetName: 'UTF8'; CharSetWidth: 4; CodePage: CP_UTF8),
241 <  (CharsetID: 5; CharSetName: 'SJIS_0208'; CharSetWidth: 2; CodePage: 20932),
242 <  (CharsetID: 6; CharSetName: 'EUCJ_0208'; CharSetWidth: 2; CodePage: 20932),
243 <  (CharsetID: 7; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE),
244 <  (CharsetID: 8; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE),
245 <  (CharsetID: 9; CharSetName: 'DOS737'; CharSetWidth: 1; CodePage: 737),
246 <  (CharsetID: 10; CharSetName: 'DOS437'; CharSetWidth: 1; CodePage: 437),
247 <  (CharsetID: 11; CharSetName: 'DOS850'; CharSetWidth: 1; CodePage: 850),
248 <  (CharsetID: 12; CharSetName: 'DOS865'; CharSetWidth: 1; CodePage: 865),
249 <  (CharsetID: 13; CharSetName: 'DOS860'; CharSetWidth: 1; CodePage: 860),
250 <  (CharsetID: 14; CharSetName: 'DOS863'; CharSetWidth: 1; CodePage: 863),
251 <  (CharsetID: 15; CharSetName: 'DOS775'; CharSetWidth: 1; CodePage: 775),
252 <  (CharsetID: 16; CharSetName: 'DOS858'; CharSetWidth: 1; CodePage: 858),
253 <  (CharsetID: 17; CharSetName: 'DOS862'; CharSetWidth: 1; CodePage: 862),
254 <  (CharsetID: 18; CharSetName: 'DOS864'; CharSetWidth: 1; CodePage: 864),
255 <  (CharsetID: 19; CharSetName: 'NEXT'; CharSetWidth: 1; CodePage: CP_NONE),
256 <  (CharsetID: 20; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE),
257 <  (CharsetID: 21; CharSetName: 'ISO8859_1'; CharSetWidth: 1; CodePage: 28591),
258 <  (CharsetID: 22; CharSetName: 'ISO8859_2'; CharSetWidth: 1; CodePage: 28592),
259 <  (CharsetID: 23; CharSetName: 'ISO8859_3'; CharSetWidth: 1; CodePage: 28593),
239 <  (CharsetID: 24; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE),
240 <  (CharsetID: 25; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE),
241 <  (CharsetID: 26; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE),
242 <  (CharsetID: 27; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE),
243 <  (CharsetID: 28; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE),
244 <  (CharsetID: 29; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE),
245 <  (CharsetID: 30; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE),
246 <  (CharsetID: 31; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE),
247 <  (CharsetID: 32; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE),
248 <  (CharsetID: 33; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE),
249 <  (CharsetID: 34; CharSetName: 'ISO8859_4'; CharSetWidth: 1; CodePage: 28594),
250 <  (CharsetID: 35; CharSetName: 'ISO8859_5'; CharSetWidth: 1; CodePage: 28595),
251 <  (CharsetID: 36; CharSetName: 'ISO8859_6'; CharSetWidth: 1; CodePage: 28596),
252 <  (CharsetID: 37; CharSetName: 'ISO8859_7'; CharSetWidth: 1; CodePage: 28597),
253 <  (CharsetID: 38; CharSetName: 'ISO8859_8'; CharSetWidth: 1; CodePage: 28598),
254 <  (CharsetID: 39; CharSetName: 'ISO8859_9'; CharSetWidth: 1; CodePage: 28599),
255 <  (CharsetID: 40; CharSetName: 'ISO8859_13'; CharSetWidth: 1; CodePage: 28603),
256 <  (CharsetID: 41; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE),
257 <  (CharsetID: 42; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE),
258 <  (CharsetID: 43; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE),
259 <  (CharsetID: 44; CharSetName: 'KSC_5601'; CharSetWidth: 2; CodePage: 949),
260 <  (CharsetID: 45; CharSetName: 'DOS852'; CharSetWidth: 1; CodePage: 852),
261 <  (CharsetID: 46; CharSetName: 'DOS857'; CharSetWidth: 1; CodePage: 857),
262 <  (CharsetID: 47; CharSetName: 'DOS861'; CharSetWidth: 1; CodePage: 861),
263 <  (CharsetID: 48; CharSetName: 'DOS866'; CharSetWidth: 1; CodePage: 866),
264 <  (CharsetID: 49; CharSetName: 'DOS869'; CharSetWidth: 1; CodePage: 869),
265 <  (CharsetID: 50; CharSetName: 'CYRL'; CharSetWidth: 1; CodePage: 1251),
266 <  (CharsetID: 51; CharSetName: 'WIN1250'; CharSetWidth: 1; CodePage: 1250),
267 <  (CharsetID: 52; CharSetName: 'WIN1251'; CharSetWidth: 1; CodePage: 1251),
268 <  (CharsetID: 53; CharSetName: 'WIN1252'; CharSetWidth: 1; CodePage: 1252),
269 <  (CharsetID: 54; CharSetName: 'WIN1253'; CharSetWidth: 1; CodePage: 1253),
270 <  (CharsetID: 55; CharSetName: 'WIN1254'; CharSetWidth: 1; CodePage: 1254),
271 <  (CharsetID: 56; CharSetName: 'BIG_5'; CharSetWidth: 2; CodePage: 950),
272 <  (CharsetID: 57; CharSetName: 'GB_2312'; CharSetWidth: 2; CodePage: 936),
273 <  (CharsetID: 58; CharSetName: 'WIN1255'; CharSetWidth: 1; CodePage: 1255),
274 <  (CharsetID: 59; CharSetName: 'WIN1256'; CharSetWidth: 1; CodePage: 1256),
275 <  (CharsetID: 60; CharSetName: 'WIN1257'; CharSetWidth: 1; CodePage: 1257),
276 <  (CharsetID: 61; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE),
277 <  (CharsetID: 62; CharSetName: 'Unknown'; CharSetWidth: 0; CodePage: CP_NONE),
278 <  (CharsetID: 63; CharSetName: 'KOI8R'; CharSetWidth: 1; CodePage: 20866),
279 <  (CharsetID: 64; CharSetName: 'KOI8U'; CharSetWidth: 1; CodePage: 21866),
280 <  (CharsetID: 65; CharSetName: 'WIN1258'; CharSetWidth: 1; CodePage: 1258),
281 <  (CharsetID: 66; CharSetName: 'TIS620'; CharSetWidth: 1; CodePage: 874),
282 <  (CharsetID: 67; CharSetName: 'GBK'; CharSetWidth: 2; CodePage: 936),
283 <  (CharsetID: 68; CharSetName: 'CP943C'; CharSetWidth: 2; CodePage: 943),
284 <  (CharsetID: 69; CharSetName: 'GB18030'; CharSetWidth: 4; CodePage: 54936)
285 < );
286 <
287 <  {$IFDEF Unix}
288 <  {SetEnvironmentVariable doesn't exist so we have to use C Library}
289 <  function setenv(name:Pchar; value:Pchar; replace:integer):integer;cdecl;external clib name 'setenv';
290 <  function unsetenv(name:Pchar):integer;cdecl;external clib name 'unsetenv';
291 <  function SetEnvironmentVariable(name:PAnsiChar; value:PAnsiChar):boolean;
292 <  // Set environment variable; if empty string given, remove it.
234 > procedure TFBLibrary.FreeFBLibrary;
235 > begin
236 >  if FIBLibrary <> NilHandle then
237 >    FreeLibrary(FIBLibrary);
238 >  FIBLibrary := NilHandle;
239 > end;
240 >
241 > function TFBLibrary.GetLibraryName: string;
242 > begin
243 >  Result := ExtractFileName(FFBLibraryName);
244 > end;
245 >
246 > function TFBLibrary.GetFirebirdAPI: IFirebirdAPI;
247 > begin
248 >  Result := FFirebirdAPI;
249 > end;
250 >
251 > constructor TFBLibrary.Create(aLibPathName: string);
252 > begin
253 >  inherited Create;
254 >  SetupEnvironment;
255 >  FFBLibraryName := aLibPathName;
256 >  FIBLibrary := NilHandle;
257 >  FFirebirdAPI := GetFirebird3API;
258 >  FRequestedLibName := aLibPathName;
259 >  if aLibPathName <> '' then
260    begin
261 <    result:=false; //assume failure
262 <    if value = '' then
263 <    begin
264 <      // Assume user wants to remove variable.
265 <      if unsetenv(name)=0 then result:=true;
266 <    end
267 <    else
261 >    SetLength(FLibraryList,Length(FLibraryList)+1);
262 >    FLibraryList[Length(FLibraryList)-1] := self;
263 >  end;
264 >  if FFirebirdAPI <> nil then
265 >  begin
266 >    {First try Firebird 3}
267 >    if not LoadIBLibrary or not (FFirebirdAPI as TFBClientAPI).LoadInterface then
268 >      FFirebirdAPI := nil;
269 >  end;
270 >
271 >  if FFirebirdAPI = nil then
272 >  begin
273 >    {now try Firebird 2.5. Under Unix we need to reload the library in case we
274 >     are to use the embedded library}
275 >    FFirebirdAPI := GetLegacyFirebirdAPI;
276 >    if FFirebirdAPI <> nil then
277      begin
278 <      // Non empty so set the variable
279 <      if setenv(name, value, 1)=0 then result:=true;
278 >      {$IFDEF UNIX}
279 >      FreeFBLibrary;
280 >      {$ENDIF}
281 >      if not LoadIBLibrary or not (FFirebirdAPI as TFBClientAPI).LoadInterface then
282 >        FFirebirdAPI := nil;
283      end;
284    end;
285 <  {$ENDIF}
285 >  {Note: FFirebirdAPI will be set to nil if the Firebird API fails to load}
286 > end;
287  
288 < { TFBClientAPI }
288 > destructor TFBLibrary.Destroy;
289 > begin
290 >  FFirebirdAPI := nil;
291 >  FreeFBLibrary;
292 >  inherited Destroy;
293 > end;
294  
295 < constructor TFBClientAPI.Create;
295 > class function TFBLibrary.GetFBLibrary(aLibPathName: string): IFirebirdLibrary;
296 > var i: integer;
297   begin
298 <  inherited Create;
299 <  LoadIBLibrary;
314 <  if (IBLibrary <> NilHandle) then
298 >  Result := nil;
299 >  if aLibPathName <> '' then
300    begin
301 <    SetupEnvironment;
302 <    LoadInterface;
301 >    for i := 0 to Length(FLibraryList) - 1 do
302 >      if (FLibraryList[i] as TFBLibrary).FRequestedLibName = aLibPathName then
303 >      begin
304 >        Result := FLibraryList[i];
305 >        Exit;
306 >      end;
307 >    Result := Create(aLibPathName);
308    end;
309 <  FirebirdClientAPI := self;
309 >
310   end;
311  
312 < destructor TFBClientAPI.Destroy;
312 > class procedure TFBLibrary.FreeLibraries;
313 > var i: integer;
314   begin
315 <  FirebirdClientAPI := nil;
316 <  if FOwnsIBLibrary and (IBLibrary <> NilHandle) then
317 <    FreeLibrary(IBLibrary);
318 <  IBLibrary := NilHandle;
319 <  inherited Destroy;
315 >  for i := 0 to Length(FLibraryList) - 1 do
316 >    FLibraryList[i] := nil;
317 >  SetLength(FLibraryList,0);
318 > end;
319 >
320 > function TFBLibrary.GetHandle: TLibHandle;
321 > begin
322 >  Result := FIBLibrary;
323 > end;
324 >
325 > { TFBClientAPI }
326 >
327 > constructor TFBClientAPI.Create(aFBLibrary: TFBLibrary);
328 > begin
329 >  inherited Create;
330 >  FFBLibrary := aFBLibrary;
331   end;
332  
333   procedure TFBClientAPI.IBAlloc(var P; OldSize, NewSize: Integer);
# Line 343 | Line 345 | end;
345  
346   {Under Unixes, if using an embedded server then set up local TMP and LOCK Directories}
347  
346 procedure TFBClientAPI.SetupEnvironment;
347 var TmpDir: AnsiString;
348 begin
349  {$IFDEF UNIX}
350    TmpDir := GetTempDir +
351        DirectorySeparator + 'firebird_' + sysutils.GetEnvironmentVariable('USER');
352    if sysutils.GetEnvironmentVariable('FIREBIRD_TMP') = '' then
353    begin
354      if not DirectoryExists(tmpDir) then
355        mkdir(tmpDir);
356      SetEnvironmentVariable('FIREBIRD_TMP',PAnsiChar(TmpDir));
357    end;
358    if sysutils.GetEnvironmentVariable('FIREBIRD_LOCK') = '' then
359    begin
360      if not DirectoryExists(tmpDir) then
361        mkdir(tmpDir);
362      SetEnvironmentVariable('FIREBIRD_LOCK',PAnsiChar(TmpDir));
363    end;
364  {$ENDIF}
365 end;
366
348   procedure TFBClientAPI.EncodeInteger(aValue: integer; len: integer; buffer: PByte);
349   begin
350    while len > 0 do
# Line 377 | Line 358 | end;
358  
359   function TFBClientAPI.IsLibraryLoaded: boolean;
360   begin
361 <  Result := IBLibrary <> NilHandle;
361 >  Result := FFBLibrary.IBLibrary <> NilHandle;
362   end;
363  
364 < function TFBClientAPI.GetProcAddr(ProcName: PAnsiChar): Pointer;
364 > function TFBClientAPI.GetFBLibrary: IFirebirdLibrary;
365   begin
366 <  Result := GetProcAddress(IBLibrary, ProcName);
386 <  if not Assigned(Result) then
387 <    raise Exception.CreateFmt(SFirebirdAPIFuncNotFound,[ProcName]);
366 >  Result := FFBLibrary;
367   end;
368  
369 < function TFBClientAPI.GetOverrideLibName: string;
369 > function TFBClientAPI.GetProcAddr(ProcName: PAnsiChar): Pointer;
370   begin
371 <  Result := '';
372 <  if AllowUseOfFBLIB then
373 <    Result := GetEnvironmentVariable('FBLIB');
395 <  if Result = '' then
396 <  begin
397 <    if assigned(OnGetLibraryName) then
398 <      OnGetLibraryName(Result)
399 <  end;
371 >  Result := GetProcAddress(FFBLibrary.IBLibrary, ProcName);
372 >  if not Assigned(Result) then
373 >    raise Exception.CreateFmt(SFirebirdAPIFuncNotFound,[ProcName]);
374   end;
375  
376 < procedure TFBClientAPI.LoadInterface;
376 > function TFBClientAPI.LoadInterface: boolean;
377   begin
378    isc_sqlcode := GetProcAddr('isc_sqlcode'); {do not localize}
379    isc_sql_interprete := GetProcAddr('isc_sql_interprete'); {do not localize}
# Line 407 | Line 381 | begin
381    isc_event_counts := GetProcAddr('isc_event_counts'); {do not localize}
382    isc_event_block := GetProcAddr('isc_event_block'); {do not localize}
383    isc_free := GetProcAddr('isc_free'); {do not localize}
384 +  Result := assigned(isc_free);
385   end;
386  
412 function TFBClientAPI.GetLibraryName: string;
413 begin
414  Result := FFBLibraryName;
415 end;
416
417 function TFBClientAPI.GetCharsetName(CharSetID: integer): AnsiString;
418 begin
419  Result := '';
420  if (CharSetID >= Low(CharSetMap)) and (CharSetID <= High(CharSetMap)) and
421                                  (CharSetMap[CharSetID].CharSetID = CharSetID) then
422    begin
423      Result := CharSetMap[CharSetID].CharSetName;
424      Exit;
425    end;
426 end;
427
428 function TFBClientAPI.CharSetID2CodePage(CharSetID: integer;
429  var CodePage: TSystemCodePage): boolean;
430 begin
431  Result := (CharSetID >= Low(CharSetMap)) and (CharSetID <= High(CharSetMap))
432               and (CharSetMap[CharSetID].CharSetID = CharSetID);
433  if Result then
434    begin
435      CodePage := CharSetMap[CharSetID].CodePage;
436      Result := true;
437      Exit;
438    end;
439 end;
440
441 function TFBClientAPI.CodePage2CharSetID(CodePage: TSystemCodePage;
442  var CharSetID: integer): boolean;
443 var i: integer;
444 begin
445  Result := false;
446  for i := Low(CharSetMap) to High(CharSetMap) do
447    if CharSetMap[i].CodePage = CodePage then
448    begin
449      CharSetID := CharSetMap[i].CharSetID;
450      Result := true;
451      Exit;
452    end;
453 end;
454
455 function TFBClientAPI.CharSetName2CharSetID(CharSetName: AnsiString;
456  var CharSetID: integer): boolean;
457 var i: integer;
458 begin
459  Result := false;
460  for i := Low(CharSetMap) to High(CharSetMap) do
461    if AnsiCompareStr(CharSetMap[i].CharSetName, CharSetName) = 0 then
462    begin
463      CharSetID := CharSetMap[i].CharSetID;
464      Result := true;
465      Exit;
466    end;
467 end;
468
469 function TFBClientAPI.CharSetWidth(CharSetID: integer; var Width: integer
470  ): boolean;
471 begin
472  Result := (CharSetID >= Low(CharSetMap)) and (CharSetID <= High(CharSetMap))
473               and (CharSetMap[CharSetID].CharSetID = CharSetID);
474  if Result then
475    begin
476      Width := CharSetMap[CharSetID].CharSetWidth;
477      Result := true;
478      Exit;
479    end;
480 end;
481
482 const
483  IBLocalBufferLength = 512;
484  IBBigLocalBufferLength = IBLocalBufferLength * 2;
485  IBHugeLocalBufferLength = IBBigLocalBufferLength * 20;
486
387   { TFBStatus }
388  
389   constructor TFBStatus.Create(aOwner: TFBClientAPI);
# Line 594 | Line 494 | begin
494      LeaveCriticalSection(TFBClientAPI.FIBCS);
495    end;
496   end;
497 +
498   initialization
499 <  TFBClientAPI.IBLibrary := NilHandle;
499 >  TFBLibrary.FEnvSetupDone := false;
500    {$IFNDEF FPC}
501    InitializeCriticalSection(TFBClientAPI.FIBCS);
502    {$ELSE}
# Line 603 | Line 504 | initialization
504    {$ENDIF}
505  
506   finalization
507 +  TFBLibrary.FreeLibraries;
508    {$IFNDEF FPC}
509    DeleteCriticalSection(TFBClientAPI.FIBCS);
510    {$ELSE}
511    DoneCriticalSection(TFBClientAPI.FIBCS);
512    {$ENDIF}
611  if TFBClientAPI.IBLibrary <> NilHandle then
612  begin
613    FreeLibrary(TFBClientAPI.IBLibrary);
614    TFBClientAPI.IBLibrary := NilHandle;
615    TFBClientAPI.FFBLibraryName := '';
616  end;
617
513   end.
514  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines