blob: 4dd0480621f27dfd9b5cdbfd4550ff735e122134 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
unit sqldblib;
{$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(AValue: String);
procedure SetEnabled(AValue: Boolean);
procedure SetLibraryName(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 Enabled then
DatabaseError(SErrConnnected,Self);
end;
procedure TSQLDBLibraryLoader.SetCType(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(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.
|