:?: Patch for ZConnection.Connect
Posted: 12.05.2009, 10:58
Currently the username and password properties are not updated if they were changed in the login dialog. So I've modified
to
In this way the username and password are set to the username and password which are typed into the login dialog.
Code: Select all
procedure TZConnection.Connect;
var
//Local variables declared in order to preserve the original property value
//and to avoid the storage of password
Username, Password: string;
begin
if FConnection = nil then
begin
// Fixes Zeos Bug 00056
// try
DoBeforeConnect;
// except
//This is here to support aborting the Connection in BeforeConnect event without fatal errors
// on E: EAbort do
// Exit;
// end;
UserName := FUser;
Password := FPassword;
if FLoginPrompt then
begin
{ Defines user name }
if UserName = '' then
UserName := FProperties.Values['UID'];
if UserName = '' then
UserName := FProperties.Values['username'];
{ Defines user password }
if Password = '' then
Password := FProperties.Values['PWD'];
if Password = '' then
Password := FProperties.Values['password'];
if Assigned(FOnLogin) then
FOnLogin(Self, UserName, Password)
else
begin
if Assigned(LoginDialogProc) then
begin
if not LoginDialogProc(FDatabase, UserName, Password) then
Exit
end
else
raise Exception.Create(SLoginPromptFailure);
end;
end;
ShowSqlHourGlass;
try
FConnection := DriverManager.GetConnectionWithParams(
ConstructURL(UserName, Password), FProperties);
try
with FConnection do
begin
SetAutoCommit(FAutoCommit);
SetReadOnly(FReadOnly);
SetCatalog(FCatalog);
SetTransactionIsolation(FTransactIsolationLevel);
Open;
end;
except
FConnection := nil;
raise;
end;
finally
HideSqlHourGlass;
end;
if not FConnection.IsClosed then
DoAfterConnect;
end;
end;
Code: Select all
procedure TZConnection.Connect;
var
//Local variables declared in order to preserve the original property value
//and to avoid the storage of password
Username, Password: string;
begin
if FConnection = nil then
begin
// Fixes Zeos Bug 00056
// try
DoBeforeConnect;
// except
//This is here to support aborting the Connection in BeforeConnect event without fatal errors
// on E: EAbort do
// Exit;
// end;
UserName := FUser;
Password := FPassword;
if FLoginPrompt then
begin
{ Defines user name }
if UserName = '' then
UserName := FProperties.Values['UID'];
if UserName = '' then
UserName := FProperties.Values['username'];
{ Defines user password }
if Password = '' then
Password := FProperties.Values['PWD'];
if Password = '' then
Password := FProperties.Values['password'];
if Assigned(FOnLogin) then
FOnLogin(Self, UserName, Password)
else
begin
if Assigned(LoginDialogProc) then
begin
if not LoginDialogProc(FDatabase, UserName, Password) then
Exit
else
//HA 090512 Update username and password after login dialog closed
begin
FUser := UserName;
FPassword := Password;
end;
end
else
raise Exception.Create(SLoginPromptFailure);
end;
end;
ShowSqlHourGlass;
try
FConnection := DriverManager.GetConnectionWithParams(
ConstructURL(UserName, Password), FProperties);
try
with FConnection do
begin
SetAutoCommit(FAutoCommit);
SetReadOnly(FReadOnly);
SetCatalog(FCatalog);
SetTransactionIsolation(FTransactIsolationLevel);
Open;
end;
except
FConnection := nil;
raise;
end;
finally
HideSqlHourGlass;
end;
if not FConnection.IsClosed then
DoAfterConnect;
end;
end;