123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- unit SQLDBLib;
- {
- This file is part of the Free Pascal run time library.
- Copyright (c) 1999-2022 by Michael van Canney and other members of the
- Free Pascal development team
- SQLDB Library Loader
- See the file COPYING.FPC, included in this distribution,
- for details about the copyright.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- **********************************************************************}
- {$mode objfpc}{$H+}
- interface
- uses
- Classes, SysUtils, db, sqldb;
- Type
- { TSQLDBLibraryLoader }
- TSQLDBLibraryLoader = Class(TComponent)
- private
- FCType: String;
- FEnabled: Boolean;
- FLibraryName: String;
- procedure CheckDisabled;
- procedure SetCType(const AValue: String);
- procedure SetEnabled(AValue: Boolean);
- procedure SetLibraryName(const AValue: String);
- Protected
- Function GetConnectionDef : TConnectionDef;
- Procedure Loaded; override;
- Procedure SetDefaultLibraryName; virtual;
- Public
- Procedure LoadLibrary;
- Procedure UnloadLibrary;
- Published
- Property Enabled : Boolean Read FEnabled Write SetEnabled;
- Property ConnectionType : String Read FCType Write SetCType;
- Property LibraryName : String Read FLibraryName Write SetLibraryName;
- end;
- implementation
- Resourcestring
- SErrConnnected = 'This operation is not allowed while the datatabase is loaded';
- SErrInvalidConnectionType = 'Invalid connection type : "%s"';
- { TSQLDBLibraryLoader }
- procedure TSQLDBLibraryLoader.CheckDisabled;
- begin
- If not (csLoading in ComponentState) and Enabled then
- DatabaseError(SErrConnnected,Self);
- end;
- procedure TSQLDBLibraryLoader.SetCType(const AValue: String);
- begin
- if FCType=AValue then Exit;
- CheckDisabled;
- FCType:=AValue;
- if (FCType<>'') then
- SetDefaultLibraryName;
- end;
- procedure TSQLDBLibraryLoader.SetEnabled(aValue: Boolean);
- begin
- if FEnabled=AValue then Exit;
- if (csLoading in ComponentState) then
- FEnabled:=AValue
- else
- If AValue then
- LoadLibrary
- else
- UnloadLibrary;
- end;
- procedure TSQLDBLibraryLoader.SetLibraryName(const AValue: String);
- begin
- if FLibraryName=AValue then Exit;
- CheckDisabled;
- FLibraryName:=AValue;
- end;
- function TSQLDBLibraryLoader.GetConnectionDef: TConnectionDef;
- begin
- Result:=sqldb.GetConnectionDef(ConnectionType);
- if (Result=Nil) then
- DatabaseErrorFmt(SErrInvalidConnectionType,[FCType],Self)
- end;
- procedure TSQLDBLibraryLoader.Loaded;
- begin
- inherited;
- If FEnabled and (FCType<>'') and (FLibraryName<>'') then
- LoadLibrary;
- end;
- procedure TSQLDBLibraryLoader.SetDefaultLibraryName;
- Var
- D : TConnectionDef;
- begin
- D:=GetConnectionDef;
- LibraryName:=D.DefaultLibraryName;
- end;
- procedure TSQLDBLibraryLoader.LoadLibrary;
- Var
- D : TConnectionDef;
- l : TLibraryLoadFunction;
- begin
- D:=GetConnectionDef;
- L:=D.LoadFunction();
- if (L<>Nil) then
- L(LibraryName);
- FEnabled:=True;
- end;
- procedure TSQLDBLibraryLoader.UnloadLibrary;
- Var
- D : TConnectionDef;
- l : TLibraryUnLoadFunction;
- begin
- D:=GetConnectionDef;
- L:=D.UnLoadFunction;
- if L<>Nil then
- L;
- FEnabled:=False;
- end;
- end.
|