procedure TSQLConnection.DoConnect;
var
ConnectionProps: TDBXProperties;
Ind: Integer;
ConnectionFactory: TDBXConnectionFactory;
LoginParams: TStrings;
SchemaOverride:
string;
SchemaOverrideList: TStringList;
Password:
string;
MemoryConnectionFactory: TDBXMemoryConnectionFactory;
begin
ConnectionProps :=
nil;
LoginParams := TStringList.Create;
MemoryConnectionFactory :=
nil;
try
if LoadParamsOnConnect
then
begin
ConnectionFactory := TDBXConnectionFactory.GetConnectionFactory;
TDBXConnectionFactory.Lock;
try
ConnectionProps := ConnectionFactory.GetConnectionProperties(ConnectionName);
ConnectionProps := ConnectionProps.Clone;
finally
TDBXConnectionFactory.Unlock;
end;
end else
begin
ConnectionProps := TDBXProperties.Create;
try
ConnectionFactory := TDBXConnectionFactory.GetConnectionFactory;
except
MemoryConnectionFactory := TDBXMemoryConnectionFactory.Create;
ConnectionFactory := MemoryConnectionFactory;
ConnectionFactory.Open;
end;
ConnectionProps.AddProperties(FParams);
if ConnectionProps.Properties.IndexOfName(TDBXPropertyNames.DriverName) = -1
then
ConnectionProps.Add(TDBXPropertyNames.DriverName, DriverName);
end;
CheckLoginParams;
ConnectionState := csStateConnecting;
GetLoginParams(LoginParams);
if LoginParams.Values[TDBXPropertyNames.Database] <> ConnectionProps[TDBXPropertyNames.Database]
then
begin
ConnectionProps[TDBXPropertyNames.Database] := LoginParams.Values[TDBXPropertyNames.Database];
end;
SetCursor(HourGlassCursor);
ConnectionProps.Add('
UNLICENSED_DRIVERS', IntToStr(GDAL));
// Do not translate.
FLoginUsername := LoginParams.Values[TDBXPropertyNames.UserName];
if FLoginUserName <> '
'
then
ConnectionProps[TDBXPropertyNames.UserName] := FLoginUsername;
Password := LoginParams.Values[TDBXPropertyNames.Password];
if Password <> '
'
then
ConnectionProps[TDBXPropertyNames.Password] := Password;
ConnectionProps.SetComponentOwner(self);
ConnectionProps.Events.Events[sValidatePeerCertificate] := TEventPointer(ValidatePeerCertificate);
ConnectionFactory.Lock;
try
FDBXConnection := ConnectionFactory.GetConnection(ConnectionProps);
finally
ConnectionFactory.Unlock;
end;
for Ind := 0
to FMonitorUsers.Count -1
do
FMonitorUsers[Ind].UpdateTraceCallBack;
SetCursor(HourGlassCursor);
RegisterTraceCallback(True);
FDefaultSchema := '
';
if (FDBXConnection.ProductName = '
BlackfishSQL')
then {Do not localize}
begin
FDefaultSchema := '
DEFAULT_SCHEMA';
{ Do not localize }
end;
SchemaOverride := ConnectionProps[TDBXPropertyNames.SchemaOverride];
if (SchemaOverride = '
')
and LoadParamsOnConnect
then
begin
TDBXConnectionFactory.Lock;
try
SchemaOverride := ConnectionFactory.GetDriverProperties(ConnectionProps[TDBXPropertyNames.DriverName])
[TDBXPropertyNames.SchemaOverride];
finally
TDBXConnectionFactory.Unlock;
end;
end;
if SchemaOverride <> '
'
then
begin
SchemaOverrideList := TStringList.Create;
try
SchemaOverrideList.Delimiter := '
.';
SchemaOverrideList.DelimitedText := SchemaOverride;
if SchemaOverrideList.Count = 2
then
begin
if (SchemaOverrideList[0] = '
%')
or (SchemaOverrideList[0] = FLoginUsername)
then
FDefaultSchema := SchemaOverrideList[1];
end;
finally
SchemaOverrideList.Free;
end;
end;
ConnectionOptions;
ConnectionState := csStateOpen;
finally
FreeAndNil(MemoryConnectionFactory);
// If allocated, free it.
SetCursor(DefaultCursor);
LoginParams.Free;
ConnectionProps.Free;
if ConnectionState = csStateConnecting
then // an exception occurred
begin
ConnectionState := csStateClosed;
if Assigned(FDBXConnection)
then
FreeAndNil(FDBXConnection)
end;
end;
end;