-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGenericConnection.pas
More file actions
138 lines (111 loc) · 3.76 KB
/
GenericConnection.pas
File metadata and controls
138 lines (111 loc) · 3.76 KB
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
130
131
132
133
134
135
136
137
138
unit GenericConnection;
interface
uses
System.JSON,
System.Generics.Collections,
FireDAC.Stan.Intf,
FireDAC.Stan.Option,
FireDAC.Stan.Error,
FireDAC.UI.Intf,
FireDAC.Phys.Intf,
FireDAC.Stan.Def,
FireDAC.Stan.Pool,
FireDAC.Stan.Async,
FireDAC.Phys,
Data.DB,
FireDAC.Comp.Client,
Firedac.DApt,
Firedac.Phys.FB,
Firedac.Phys.SQLite,
Firedac.Phys.SQLiteDef,
Firedac.Phys.FBDef,
Firedac.Phys.MySQLDef,
Firedac.Phys.MySQL,
FireDAC.Comp.UI,
GenericTypes;
var
FConnList : TObjectList<TFDConnection>;
FServer : String;
FDatabase : String;
FTypeConnection : TSQLType;
FUserName : String;
FPort : String;
FPassword : String;
function Connected : Integer;
procedure Disconnected(IndexConn : Integer);
implementation
uses
System.SysUtils;
function Connected : Integer;
var
IndexConn : Integer;
begin
if not Assigned(FConnList) then
FConnList := TObjectList<TFDConnection>.Create;
FConnList.Add(TFDConnection.Create(nil));
IndexConn := Pred(FConnList.Count);
FConnList.Items[IndexConn].Params.Database := FDatabase;
if FDatabase = '' then
raise Exception.Create('variable FDatabase must be informed!');
case FTypeConnection of
FireBird :
begin
if FUsername = '' then FUsername := 'sysdba';
if FPassword = '' then FPassword := 'masterkey';
if FPort = '' then FPort := '3050';
if FServer = '' then
raise Exception.Create('variable FServer must be informed!');
FConnList.Items[IndexConn].Params.DriverID := 'FB';
FConnList.Items[IndexConn].Params.UserName := FUsername;
FConnList.Items[IndexConn].Params.Password := FPassword;
FConnList.Items[IndexConn].Params.Add('Server='+FServer);
FConnList.Items[IndexConn].Params.Add('Port='+FPort);
FConnList.Items[IndexConn].Params.Add('Protocol=TCPIP');
FConnList.Items[IndexConn].Params.Add('CharacterSet=UTF8');
end;
SQLite :
begin
FConnList.Items[IndexConn].Params.DriverID := 'SQLite';
FConnList.Items[IndexConn].Params.Add('LockingMode=Normal');
end;
MySQL :
begin
if FServer = '' then
raise Exception.Create('variable FServer must be informed!');
if FUsername = '' then
raise Exception.Create('variable FUsername must be informed!');
if FPassword = '' then
raise Exception.Create('variable FPassword must be informed!');
if FPort = '' then FPort := '3306';
FConnList.Items[IndexConn].Params.DriverID := 'MySQL';
FConnList.Items[IndexConn].Params.UserName := FUserName;
FConnList.Items[IndexConn].Params.Password := FPassword;
FConnList.Items[IndexConn].Params.Add('Database='+FDatabase);
FConnList.Items[IndexConn].Params.Add('Server='+FServer);
FConnList.Items[IndexConn].Params.Add('Port='+FPort);
end;
Oracle :
begin
if FServer = '' then
raise Exception.Create('variable FServer must be informed!');
if FUsername = '' then
raise Exception.Create('variable FUsername must be informed!');
if FPassword = '' then
raise Exception.Create('variable FPassword must be informed!');
FConnList.Items[IndexConn].Params.DriverID := 'Ora';
FConnList.Items[IndexConn].Params.UserName := FUsername;
FConnList.Items[IndexConn].Params.Password := FPassword;
FConnList.Items[IndexConn].Params.Database := FServer+'/'+FDatabase;
FConnList.Items[IndexConn].Params.Add('CharacterSet=UTF8');
end;
end;
FConnList.Items[IndexConn].Connected;
Result := IndexConn;
end;
procedure Disconnected(IndexConn : Integer);
begin
FConnList.Items[IndexConn].Connected := false;
FConnList.Items[IndexConn].Free;
FConnList.TrimExcess;
end;
end.