49 |
|
|
50 |
|
uses |
51 |
|
SysUtils, Classes, Graphics, Controls, Forms, Dialogs, |
52 |
< |
StdCtrls, ExtCtrls, IBDataBase, IB, LResources; |
52 |
> |
StdCtrls, ExtCtrls, IBDatabase, IB, LResources; |
53 |
|
|
54 |
|
type |
55 |
|
|
56 |
|
{ TIBDatabaseEditForm } |
57 |
|
|
58 |
|
TIBDatabaseEditForm = class(TForm) |
59 |
+ |
Browse: TButton; |
60 |
+ |
UseWireCompression: TCheckBox; |
61 |
+ |
DatabasePath: TEdit; |
62 |
+ |
Label1: TLabel; |
63 |
+ |
Label10: TLabel; |
64 |
+ |
Label7: TLabel; |
65 |
+ |
Label8: TLabel; |
66 |
+ |
Label9: TLabel; |
67 |
+ |
ConfigOverrides: TMemo; |
68 |
+ |
PortNo: TEdit; |
69 |
+ |
Protocol: TComboBox; |
70 |
+ |
ConnectionTypeBtn: TRadioGroup; |
71 |
+ |
ServerName: TEdit; |
72 |
|
UseSystemDefaultCS: TCheckBox; |
60 |
– |
GroupBox2: TGroupBox; |
73 |
|
Panel1: TPanel; |
62 |
– |
DatabaseName: TEdit; |
63 |
– |
Label1: TLabel; |
64 |
– |
LocalRbtn: TRadioButton; |
65 |
– |
RemoteRbtn: TRadioButton; |
66 |
– |
Browse: TButton; |
74 |
|
GroupBox1: TGroupBox; |
75 |
|
UserName: TEdit; |
76 |
|
Password: TEdit; |
85 |
|
LoginPrompt: TCheckBox; |
86 |
|
Label6: TLabel; |
87 |
|
CharacterSet: TComboBox; |
81 |
– |
ServerName: TEdit; |
82 |
– |
Protocol: TComboBox; |
83 |
– |
Label7: TLabel; |
84 |
– |
Label8: TLabel; |
88 |
|
Test: TButton; |
86 |
– |
procedure RemoteRbtnClick(Sender: TObject); |
89 |
|
procedure BrowseClick(Sender: TObject); |
90 |
< |
procedure LocalRbtnClick(Sender: TObject); |
90 |
> |
procedure ConfigOverridesEditingDone(Sender: TObject); |
91 |
> |
procedure DatabaseParamsEditingDone(Sender: TObject); |
92 |
|
procedure OKBtnClick(Sender: TObject); |
93 |
|
procedure FormCreate(Sender: TObject); |
94 |
|
procedure HelpBtnClick(Sender: TObject); |
95 |
< |
procedure UserNameChange(Sender: TObject); |
96 |
< |
procedure PasswordChange(Sender: TObject); |
97 |
< |
procedure SQLRoleChange(Sender: TObject); |
95 |
> |
procedure PasswordEditingDone(Sender: TObject); |
96 |
> |
procedure ProtocolCloseUp(Sender: TObject); |
97 |
> |
procedure ConnectionTypeBtnSelectionChanged(Sender: TObject); |
98 |
> |
procedure SQLRoleEditingDone(Sender: TObject); |
99 |
|
procedure CharacterSetChange(Sender: TObject); |
100 |
|
procedure TestClick(Sender: TObject); |
101 |
+ |
procedure UserNameEditingDone(Sender: TObject); |
102 |
|
procedure UseSystemDefaultCSChange(Sender: TObject); |
103 |
+ |
procedure UseWireCompressionEditingDone(Sender: TObject); |
104 |
|
private |
105 |
|
{ Private declarations } |
106 |
|
Database: TIBDatabase; |
107 |
+ |
FChanging: boolean; |
108 |
|
function Edit: Boolean; |
109 |
< |
function GetParam(Name: string): string; |
110 |
< |
procedure AddParam(Name, Value: string); |
111 |
< |
procedure DeleteParam(Name: string); |
109 |
> |
procedure AddParam(aName, aValue: string); |
110 |
> |
procedure DeleteParam(aName: string); |
111 |
> |
procedure UpdateParamEditBoxes; |
112 |
|
public |
113 |
|
{ Public declarations } |
114 |
|
end; |
122 |
|
|
123 |
|
{$R *.lfm} |
124 |
|
|
125 |
< |
uses TypInfo, FBMessages; |
125 |
> |
uses TypInfo, IBMessages, IBUtils; |
126 |
|
|
127 |
|
function EditIBDatabase(ADatabase: TIBDatabase): Boolean; |
128 |
|
begin |
135 |
|
end; |
136 |
|
end; |
137 |
|
|
138 |
< |
function TIBDatabaseEditForm.GetParam(Name: string): string; |
132 |
< |
var |
133 |
< |
i: Integer; |
138 |
> |
procedure TIBDatabaseEditForm.AddParam(aName, aValue: string); |
139 |
|
begin |
140 |
< |
Result := ''; |
141 |
< |
for i := 0 to DatabaseParams.Lines.Count - 1 do |
142 |
< |
begin |
143 |
< |
if (Pos(Name, LowerCase(DatabaseParams.Lines.Names[i])) = 1) then {mbcs ok} |
139 |
< |
begin |
140 |
< |
Result := DatabaseParams.Lines.Values[DatabaseParams.Lines.Names[i]]; |
141 |
< |
break; |
142 |
< |
end; |
143 |
< |
end; |
140 |
> |
if Trim(aValue) = '' then |
141 |
> |
DeleteParam(aName) |
142 |
> |
else |
143 |
> |
DatabaseParams.Lines.Values[aName] := Trim(aValue); |
144 |
|
end; |
145 |
|
|
146 |
< |
procedure TIBDatabaseEditForm.AddParam(Name, Value: string); |
146 |
> |
procedure TIBDatabaseEditForm.DeleteParam(aName: string); |
147 |
|
var |
148 |
|
i: Integer; |
149 |
– |
found: boolean; |
149 |
|
begin |
151 |
– |
found := False; |
152 |
– |
if Trim(Value) <> '' then |
153 |
– |
begin |
154 |
– |
DatabaseParams.Lines.NameValueSeparator := '='; |
150 |
|
for i := 0 to DatabaseParams.Lines.Count - 1 do |
151 |
|
begin |
152 |
< |
if (Pos(Name, LowerCase(DatabaseParams.Lines.Names[i])) = 1) then {mbcs ok} |
152 |
> |
if (Pos(aName, LowerCase(DatabaseParams.Lines.Names[i])) = 1) then {mbcs ok} |
153 |
|
begin |
154 |
< |
DatabaseParams.Lines.Values[DatabaseParams.Lines.Names[i]] := Value; |
160 |
< |
found := True; |
154 |
> |
DatabaseParams.Lines.Delete(i); |
155 |
|
break; |
156 |
|
end; |
157 |
|
end; |
164 |
– |
if not found then |
165 |
– |
DatabaseParams.Lines.Add(Name + '=' + Value); |
166 |
– |
end |
167 |
– |
else |
168 |
– |
DeleteParam(Name); |
158 |
|
end; |
159 |
|
|
160 |
< |
procedure TIBDatabaseEditForm.DeleteParam(Name: string); |
161 |
< |
var |
173 |
< |
i: Integer; |
160 |
> |
procedure TIBDatabaseEditForm.UpdateParamEditBoxes; |
161 |
> |
var st: string; |
162 |
|
begin |
163 |
< |
for i := 0 to DatabaseParams.Lines.Count - 1 do |
164 |
< |
begin |
165 |
< |
if (Pos(Name, LowerCase(DatabaseParams.Lines.Names[i])) = 1) then {mbcs ok} |
166 |
< |
begin |
167 |
< |
DatabaseParams.Lines.Delete(i); |
168 |
< |
break; |
169 |
< |
end; |
170 |
< |
end; |
163 |
> |
UserName.Text := DatabaseParams.Lines.Values['user_name']; |
164 |
> |
Password.Text := DatabaseParams.Lines.Values['password']; |
165 |
> |
SQLRole.Text := DatabaseParams.Lines.Values['sql_role_name']; |
166 |
> |
st := DatabaseParams.Lines.Values['lc_ctype']; |
167 |
> |
if (st <> '') then |
168 |
> |
CharacterSet.ItemIndex := CharacterSet.Items.IndexOf(st) |
169 |
> |
else |
170 |
> |
CharacterSet.ItemIndex := -1; |
171 |
|
end; |
172 |
|
|
173 |
|
function TIBDatabaseEditForm.Edit: Boolean; |
174 |
|
var |
175 |
< |
st: string; |
175 |
> |
aServerName: string; |
176 |
> |
aDatabaseName: string; |
177 |
> |
aProtocol: TProtocolAll; |
178 |
> |
aPortNo: string; |
179 |
|
|
180 |
< |
procedure DecomposeDatabaseName; |
181 |
< |
var |
191 |
< |
Idx1, Idx2: Integer; |
192 |
< |
st: string; |
180 |
> |
begin |
181 |
> |
if ParseConnectString(Database.DatabaseName, aServerName, aDatabaseName, aProtocol, aPortNo) then |
182 |
|
begin |
183 |
< |
if Pos('\\', Database.DatabaseName) <> 0 then {do not localize} |
184 |
< |
begin |
185 |
< |
LocalRBtn.Checked := False; |
186 |
< |
RemoteRbtn.Checked := True; |
198 |
< |
Protocol.ItemIndex := 1; |
199 |
< |
st := copy(Database.DatabaseName, 3, Length(Database.DatabaseName)); |
200 |
< |
Idx1 := Pos('\', st); {do not localize} |
201 |
< |
if Idx1 = 0 then |
202 |
< |
IBError(ibxeUnknownError, [nil]) |
203 |
< |
else begin |
204 |
< |
ServerName.Text := Copy(st, 1, Idx1 - 1); |
205 |
< |
DatabaseName.Text:= Copy(st, Idx1 + 1, Length(st)); |
206 |
< |
end; |
207 |
< |
end |
208 |
< |
else begin |
209 |
< |
Idx1 := Pos(':', Database.DatabaseName ); {do not localize} |
210 |
< |
If (Idx1 = 0) or (Idx1 = 2) then |
211 |
< |
begin |
212 |
< |
DatabaseName.Text := Database.DatabaseName; |
213 |
< |
end |
214 |
< |
else |
215 |
< |
begin |
216 |
< |
LocalRBtn.Checked := False; |
217 |
< |
RemoteRbtn.Checked := True; |
218 |
< |
Idx2 := Pos('@', Database.DatabaseName); {do not localize} |
219 |
< |
if Idx2 = 0 then |
220 |
< |
begin |
221 |
< |
Protocol.ItemIndex := 0; |
222 |
< |
ServerName.Text := copy(Database.DatabaseName, 1, Idx1 - 1); |
223 |
< |
DatabaseName.Text := copy(Database.DatabaseName, Idx1 + 1, |
224 |
< |
Length(Database.DatabaseName)); |
225 |
< |
end |
226 |
< |
else begin |
227 |
< |
Protocol.ItemIndex := 2; |
228 |
< |
ServerName.Text := copy(Database.DatabaseName, 1, Idx2 - 1); |
229 |
< |
DatabaseName.Text := copy(Database.DatabaseName, Idx2 + 1, |
230 |
< |
Length(Database.DatabaseName)); |
231 |
< |
end; |
232 |
< |
end; |
233 |
< |
end; |
183 |
> |
ServerName.Text := aServerName; |
184 |
> |
DatabasePath.Text := aDatabaseName; |
185 |
> |
Protocol.ItemIndex := ord(aProtocol); |
186 |
> |
PortNo.Text := aPortNo; |
187 |
|
end; |
188 |
< |
begin |
189 |
< |
DecomposeDatabaseName; |
190 |
< |
if Trim(Database.Params.Text) = '' then |
191 |
< |
DatabaseParams.Clear |
239 |
< |
else |
240 |
< |
DatabaseParams.Lines.Assign(Database.Params); |
188 |
> |
ProtocolCloseUp(nil); |
189 |
> |
ConnectionTypeBtnSelectionChanged(nil); |
190 |
> |
DatabaseParams.Lines.Assign(Database.Params); |
191 |
> |
ConfigOverrides.Lines.Assign(Database.ConfigOverrides); |
192 |
|
LoginPrompt.Checked := Database.LoginPrompt; |
193 |
< |
UserName.Text := GetParam('user_name'); |
194 |
< |
Password.Text := GetParam('password'); |
195 |
< |
SQLRole.Text := GetParam('sql_role'); |
245 |
< |
st := GetParam('lc_ctype'); |
246 |
< |
if (st <> '') then |
247 |
< |
CharacterSet.ItemIndex := CharacterSet.Items.IndexOf(st); |
248 |
< |
if Database.UseDefaultSystemCodePage then |
249 |
< |
UseSystemDefaultCS.Checked := true |
250 |
< |
else |
251 |
< |
UseSystemDefaultCS.Checked := false; |
193 |
> |
UpdateParamEditBoxes; |
194 |
> |
UseSystemDefaultCS.Checked := Database.UseDefaultSystemCodePage; |
195 |
> |
UseWireCompression.Checked := Database.WireCompression; |
196 |
|
Result := False; |
197 |
|
if ShowModal = mrOk then |
198 |
|
begin |
199 |
< |
Database.DatabaseName := DatabaseName.Text; |
200 |
< |
if LocalRbtn.Checked then |
201 |
< |
DatabaseName.Text := Database.DatabaseName |
202 |
< |
else |
259 |
< |
case Protocol.ItemIndex of |
260 |
< |
0: Database.DatabaseName := Format('%s:%s', [ServerName.Text, DatabaseName.Text]); {do not localize} |
261 |
< |
1: Database.DatabaseName := Format('\\%s\%s', [ServerName.Text, DatabaseName.Text]); {do not localize} |
262 |
< |
2: Database.DatabaseName := Format('%s@%s', [ServerName.Text, DatabaseName.Text]); {do not localize} |
263 |
< |
end; |
264 |
< |
Database.Params := DatabaseParams.Lines; |
199 |
> |
Database.DatabaseName := MakeConnectString(ServerName.Text, DatabasePath.Text, |
200 |
> |
TProtocolAll(Protocol.ItemIndex), PortNo.Text); |
201 |
> |
Database.Params.Assign(DatabaseParams.Lines); |
202 |
> |
Database.ConfigOverrides.Assign(ConfigOverrides.Lines); |
203 |
|
Database.LoginPrompt := LoginPrompt.Checked; |
204 |
|
Database.UseDefaultSystemCodePage := UseSystemDefaultCS.Checked; |
205 |
|
Result := True; |
206 |
|
end; |
207 |
|
end; |
208 |
|
|
271 |
– |
procedure TIBDatabaseEditForm.RemoteRbtnClick(Sender: TObject); |
272 |
– |
begin |
273 |
– |
Browse.Enabled := False; |
274 |
– |
Label7.Enabled := True; |
275 |
– |
Label8.Enabled := True; |
276 |
– |
Protocol.Enabled := True; |
277 |
– |
ServerName.Enabled := True; |
278 |
– |
if Protocol.Text = '' then |
279 |
– |
Protocol.Text := 'TCP'; |
280 |
– |
end; |
281 |
– |
|
209 |
|
procedure TIBDatabaseEditForm.BrowseClick(Sender: TObject); |
210 |
|
begin |
211 |
|
with TOpenDialog.Create(Application) do |
212 |
|
try |
213 |
< |
InitialDir := ExtractFilePath(DatabaseName.Text); |
213 |
> |
InitialDir := ExtractFilePath(DatabasePath.Text); |
214 |
|
Filter := SDatabaseFilter; |
215 |
|
if Execute then |
216 |
< |
DatabaseName.Text := FileName; |
216 |
> |
DatabasePath.Text := FileName; |
217 |
|
finally |
218 |
|
Free |
219 |
|
end; |
220 |
|
end; |
221 |
|
|
222 |
< |
procedure TIBDatabaseEditForm.LocalRbtnClick(Sender: TObject); |
222 |
> |
procedure TIBDatabaseEditForm.ConfigOverridesEditingDone(Sender: TObject); |
223 |
> |
begin |
224 |
> |
FChanging := true; |
225 |
> |
try |
226 |
> |
UseWireCompression.Checked := CompareText(ConfigOverrides.Lines.Values['WireCompression'],'true') = 0; |
227 |
> |
finally |
228 |
> |
FChanging := false; |
229 |
> |
end; |
230 |
> |
end; |
231 |
> |
|
232 |
> |
procedure TIBDatabaseEditForm.DatabaseParamsEditingDone(Sender: TObject); |
233 |
|
begin |
234 |
< |
Browse.Enabled := True; |
298 |
< |
Label7.Enabled := False; |
299 |
< |
Label8.Enabled := False; |
300 |
< |
ServerName.Enabled := False; |
301 |
< |
Protocol.Enabled := False; |
234 |
> |
UpdateParamEditBoxes; |
235 |
|
end; |
236 |
|
|
237 |
|
procedure TIBDatabaseEditForm.OKBtnClick(Sender: TObject); |
256 |
|
Application.HelpContext(HelpContext); |
257 |
|
end; |
258 |
|
|
259 |
< |
procedure TIBDatabaseEditForm.UserNameChange(Sender: TObject); |
259 |
> |
procedure TIBDatabaseEditForm.PasswordEditingDone(Sender: TObject); |
260 |
|
begin |
261 |
< |
AddParam('user_name', UserName.Text); |
261 |
> |
AddParam('password', Password.Text); |
262 |
|
end; |
263 |
|
|
264 |
< |
procedure TIBDatabaseEditForm.PasswordChange(Sender: TObject); |
264 |
> |
procedure TIBDatabaseEditForm.ProtocolCloseUp(Sender: TObject); |
265 |
|
begin |
266 |
< |
AddParam('password', Password.Text); |
266 |
> |
if Protocol.ItemIndex = 3 then |
267 |
> |
ConnectionTypeBtn.ItemIndex := 0 |
268 |
> |
else |
269 |
> |
ConnectionTypeBtn.ItemIndex := 1; |
270 |
|
end; |
271 |
|
|
272 |
< |
procedure TIBDatabaseEditForm.SQLRoleChange(Sender: TObject); |
272 |
> |
procedure TIBDatabaseEditForm.ConnectionTypeBtnSelectionChanged(Sender: TObject); |
273 |
> |
begin |
274 |
> |
if ConnectionTypeBtn.ItemIndex > 0 then |
275 |
> |
begin |
276 |
> |
Browse.Enabled := False; |
277 |
> |
Label7.Enabled := True; |
278 |
> |
Label8.Enabled := True; |
279 |
> |
Protocol.Enabled := True; |
280 |
> |
ServerName.Enabled := True; |
281 |
> |
if Protocol.ItemIndex = 3 then |
282 |
> |
Protocol.ItemIndex := 4; |
283 |
> |
end |
284 |
> |
else |
285 |
> |
begin |
286 |
> |
Browse.Enabled := True; |
287 |
> |
Label7.Enabled := False; |
288 |
> |
Label8.Enabled := true; |
289 |
> |
ServerName.Text := ''; |
290 |
> |
ServerName.Enabled := False; |
291 |
> |
Protocol.Enabled := true; |
292 |
> |
Protocol.ItemIndex := 3; |
293 |
> |
end; |
294 |
> |
end; |
295 |
> |
|
296 |
> |
procedure TIBDatabaseEditForm.SQLRoleEditingDone(Sender: TObject); |
297 |
|
begin |
298 |
|
AddParam('sql_role_name', SQLRole.Text); |
299 |
|
end; |
300 |
|
|
301 |
|
procedure TIBDatabaseEditForm.CharacterSetChange(Sender: TObject); |
302 |
|
begin |
303 |
< |
if (CharacterSet.Text <> 'None') then {do not localize} |
303 |
> |
if (CharacterSet.ItemIndex <> -1 ) then {do not localize} |
304 |
|
AddParam('lc_ctype', CharacterSet.Text) |
305 |
|
else |
306 |
|
DeleteParam('lc_ctype'); |
313 |
|
Test.Enabled := false; |
314 |
|
tempDB := TIBDatabase.Create(nil); |
315 |
|
try |
316 |
< |
if LocalRbtn.Checked then |
317 |
< |
tempDB.DatabaseName := DatabaseName.Text |
358 |
< |
else |
359 |
< |
case Protocol.ItemIndex of |
360 |
< |
0: tempDB.DatabaseName := Format('%s:%s', [ServerName.Text, DatabaseName.Text]); {do not localize} |
361 |
< |
1: tempDB.DatabaseName := Format('\\%s\%s', [ServerName.Text, DatabaseName.Text]); {do not localize} |
362 |
< |
2: tempDB.DatabaseName := Format('%s@%s', [ServerName.Text, DatabaseName.Text]); {do not localize} |
363 |
< |
end; |
316 |
> |
tempDB.DatabaseName := MakeConnectString(ServerName.Text, DatabasePath.Text, |
317 |
> |
TProtocolAll(Protocol.ItemIndex), PortNo.Text); |
318 |
|
tempDB.Params.Assign(DatabaseParams.Lines); |
319 |
|
tempDB.LoginPrompt := LoginPrompt.Checked; |
320 |
|
try |
329 |
|
end; |
330 |
|
end; |
331 |
|
|
332 |
+ |
procedure TIBDatabaseEditForm.UserNameEditingDone(Sender: TObject); |
333 |
+ |
begin |
334 |
+ |
AddParam('user_name', UserName.Text); |
335 |
+ |
end; |
336 |
+ |
|
337 |
|
procedure TIBDatabaseEditForm.UseSystemDefaultCSChange(Sender: TObject); |
338 |
|
begin |
339 |
|
CharacterSet.Enabled := not UseSystemDefaultCS.Checked; |
344 |
|
AddParam('lc_ctype', CharacterSet.Text) |
345 |
|
end; |
346 |
|
|
347 |
+ |
procedure TIBDatabaseEditForm.UseWireCompressionEditingDone(Sender: TObject); |
348 |
+ |
var Index: integer; |
349 |
+ |
begin |
350 |
+ |
if FChanging then Exit; |
351 |
+ |
if UseWireCompression.Checked then |
352 |
+ |
ConfigOverrides.Lines.Values['WireCompression'] := 'true' |
353 |
+ |
else |
354 |
+ |
begin |
355 |
+ |
Index := ConfigOverrides.Lines.IndexOfName('WireCompression'); |
356 |
+ |
if Index <> -1 then |
357 |
+ |
ConfigOverrides.Lines.Delete(Index); |
358 |
+ |
end; |
359 |
+ |
end; |
360 |
+ |
|
361 |
|
|
362 |
|
end. |