-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConnections.pas
178 lines (144 loc) · 4.6 KB
/
Connections.pas
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
unit Connections;
interface
uses
System.SysUtils;
type
TCustomConnection = class;
ICustomConnection = interface(IInvokable)
['{27FB5485-E027-4679-8F6B-F72F975B1766}']
function GetDatabase: string;
procedure SetDatabase(const Value: string);
function GetUsername: string;
procedure SetUSername(const Value: string);
function GetPassword: string;
procedure SetPassword(const Value: string);
function GetConnectionString: string;
procedure SetConnectionString(const Value: string);
function GetServer: string;
procedure SetServer(const Value: string);
property Database: string read GetDatabase write SetDatabase;
property Username: string read GetUsername write SetUsername;
property Password: string read GetPassword write SetPassword;
property Server: string read GetServer write SetServer;
end;
TCustomConnection = class(TInterfacedObject, ICustomConnection)
fDatabase: string;
fUsername: string;
fPassword: string;
fConnectionString: string;
fServer: string;
private
function GetDatabase: string;
procedure SetDatabase(const Value: string);
function GetUsername: string;
procedure SetUSername(const Value: string);
function GetPassword: string;
procedure SetPassword(const Value: string);
function GetConnectionString: string;
procedure SetConnectionString(const Value: string);
function GetServer: string;
procedure SetServer(const Value: string);
public
property Database: string read GetDatabase write SetDatabase;
property Username: string read GetUsername write SetUsername;
property Password: string read GetPassword write SetPassword;
property Server: string read GetServer write SetServer;
property ConnectionString: string read GetConnectionString write SetConnectionString;
end;
IConnection = interface(ICustomConnection)
['{F6643BD2-6392-47EE-8C3A-7306A293842E}']
function GetConnectionString: string;
end;
TMsSqlConnection = class(TCustomConnection, IConnection)
function GetConnectionString: string;
end;
TSqlLiteConnection = class(TCustomConnection, IConnection)
function GetConnectionString: string;
end;
TMySqlConnection = class(TCustomConnection, IConnection)
function GetConnectionString: string;
end;
TPostgreSqlConnection = class(TCustomConnection, IConnection)
private
ftimeout: integer;
function GetTimeout: integer;
procedure SetTimeout(const Value: integer);
public
property Timeout: integer read GetTimeout write SetTimeout;
function GetConnectionString: string;
end;
implementation
{ TCustomConnection }
function TCustomConnection.GetConnectionString: string;
begin
Result := fConnectionString;
end;
function TCustomConnection.GetDatabase: string;
begin
Result := fDatabase;
end;
function TCustomConnection.GetPassword: string;
begin
Result := fPassword;
end;
function TCustomConnection.GetServer: string;
begin
Result := fServer;
end;
function TCustomConnection.GetUsername: string;
begin
Result := fUsername;
end;
procedure TCustomConnection.SetConnectionString(const Value: string);
begin
fConnectionString := Value;
end;
procedure TCustomConnection.SetDatabase(const Value: string);
begin
fDatabase := Value;
end;
procedure TCustomConnection.SetPassword(const Value: string);
begin
fpassword := Value;
end;
procedure TCustomConnection.SetServer(const Value: string);
begin
Fserver := Value;
end;
procedure TCustomConnection.SetUsername(const Value: string);
begin
fUsername := Value;
end;
{ TMsSqlConnection }
function TMsSqlConnection.GetConnectionString: string;
begin
result := 'Provider=SQLOLEDB.1;Password=' + Password + ';Persist Security Info=True;User ID=' + username +
';Initial Catalog=' + database + ';Data Source=' + Server;
end;
{ TSqlLiteConnection }
function TSqlLiteConnection.GetConnectionString: string;
begin
result := 'Data Source=' + Database + ';Version=3;Password=' + Password + ';';
end;
{ TMySqlConnection }
function TMySqlConnection.GetConnectionString: string;
begin
result := 'Server=' + Server + ';Database=' + Database + ';Uid=' + Username + ';Pwd=' + Password + ';';
end;
{ TPostgreSqlConnection }
function TPostgreSqlConnection.GetConnectionString: string;
begin
Result := 'Provider;Data Source=' + Server + ';location=' + Database + ';User ID=' + username + ';password=' +
password + ';timeout=' + Timeout.tostring + ';';
end;
function TPostgreSqlConnection.GetTimeout: integer;
begin
if fTimeout = 0 then
fTimeout := 1000;
result := fTimeout;
end;
procedure TPostgreSqlConnection.SetTimeout(const Value: integer);
begin
fTimeout := Value;
end;
end.