@@ -22,6 +22,8 @@ interface
2222 procedure SetDatabaseName (const ADatabaseName: string);
2323 function GetLogEvent : TLogEvent;
2424 procedure SetLogEvent (const ALogEvent: TLogEvent);
25+ function GetServerHostName : string;
26+ procedure SetServerHostName (const AServerHostName: string);
2527 end ;
2628
2729 TMiniRESTSQLConnectionParamsSQLDb = class (TMiniRESTSQLConnectionFactoryParams, IMiniRESTSQLConnectionFactoryParamsSQLDb)
@@ -32,6 +34,7 @@ TMiniRESTSQLConnectionParamsSQLDb = class(TMiniRESTSQLConnectionFactoryParams,
3234 FDatabaseType: TMiniRESTSQLDatabaseType;
3335 FDatabaseName: string;
3436 FLogEvent: TLogEvent;
37+ FServerHostName: string;
3538 public
3639 function GetConnectionString : string;
3740 procedure SetConnectionString (const AConnectionString: string);
@@ -45,6 +48,8 @@ TMiniRESTSQLConnectionParamsSQLDb = class(TMiniRESTSQLConnectionFactoryParams,
4548 procedure SetDatabaseName (const ADatabaseName: string);
4649 function GetLogEvent : TLogEvent;
4750 procedure SetLogEvent (const ALogEvent: TLogEvent);
51+ function GetServerHostName : string;
52+ procedure SetServerHostName (const AServerHostName: string);
4853 end ;
4954
5055 TMiniRESTSQLConnectionFactorySQLDb = class (TMiniRESTSQLConnectionFactoryBase)
@@ -64,6 +69,7 @@ TMiniRESTSQLConnectionFactorySQLDb = class(TMiniRESTSQLConnectionFactoryBase)
6469 TMiniRESTSQLConnectionSQLDb = class (TMiniRESTSQLConnectionBase)
6570 private
6671 function GetConnectorType (const ADatabaseType: TMiniRESTSQLDatabaseType): String;
72+ procedure OnBeforeConnect (Sender: TObject);
6773 protected
6874 FSQLConnection: TSQLConnector;
6975 // FTransaction: TDBXTransaction;
@@ -76,6 +82,7 @@ TMiniRESTSQLConnectionSQLDb = class(TMiniRESTSQLConnectionBase)
7682 procedure Log (Sender : TSQLConnection; EventType : TDBEventType; Const Msg : String);
7783 procedure SetMiniRESTSQLParamToSQLParam (AMiniRESTSQLParam: IMiniRESTSQLParam; ASQLParam: TParam);
7884 procedure CheckConnectionIsValid ;
85+ procedure SetConnectionParams ;
7986 public
8087 constructor Create(AOwner: IMiniRESTSQLConnectionFactory; AParams: IMiniRESTSQLConnectionFactoryParamsSQLDb);
8188 destructor Destroy; override;
@@ -209,7 +216,8 @@ constructor TMiniRESTSQLConnectionSQLDb.Create(AOwner: IMiniRESTSQLConnectionFac
209216 FTransaction.Action := caCommit;
210217 FConnectionParams := AParams;
211218 FInExplicitTransaction := False;
212- FLogEvent := AParams.GetLogEvent;
219+ FLogEvent := AParams.GetLogEvent;
220+ FSQLConnection.BeforeConnect := OnBeforeConnect;
213221 inherited Create(AOwner);
214222end ;
215223
@@ -221,31 +229,11 @@ destructor TMiniRESTSQLConnectionSQLDb.Destroy;
221229end ;
222230
223231procedure TMiniRESTSQLConnectionSQLDb.Connect ;
224- var
225- LStringList: TStringList;
226- LName: string;
227- I: Integer;
228232begin
229233 CheckConnectionIsValid;
230- LStringList := TStringList.Create;
231- try
232- if FSQLConnection.Connected then
233- Exit;
234- FSQLConnection.ConnectorType := GetConnectorType(FConnectionParams.GetDatabaseType);
235- FSQLConnection.LoginPrompt := False;
236- FSQLConnection.UserName := FConnectionParams.GetUserName;
237- FSQLConnection.Password := FConnectionParams.GetPassword;
238- FSQLConnection.DatabaseName := FConnectionParams.GetDatabaseName;
239- LStringList.Text := FConnectionParams.GetConnectionString;
240- for I := 0 to LStringList.Count - 1 do
241- begin
242- LName := LStringList.Names[I];
243- FSQLConnection.Params.Values[LName] := LStringList.Values[LName];
244- end ;
245- FSQLConnection.Connected := True;
246- finally
247- LStringList.Free;
248- end ;
234+ if FSQLConnection.Connected then
235+ Exit;
236+ FSQLConnection.Connected := True;
249237end ;
250238
251239procedure TMiniRESTSQLConnectionSQLDb.StartTransaction ;
@@ -482,6 +470,11 @@ function TMiniRESTSQLConnectionSQLDb.GetConnectorType(const ADatabaseType: TMini
482470 end ;
483471end ;
484472
473+ procedure TMiniRESTSQLConnectionSQLDb.OnBeforeConnect (Sender: TObject);
474+ begin
475+ SetConnectionParams;
476+ end ;
477+
485478function TMiniRESTSQLConnectionParamsSQLDb.GetDatabaseName : string;
486479begin
487480 Result := FDatabaseName;
@@ -558,7 +551,42 @@ procedure TMiniRESTSQLConnectionSQLDb.Invalidate;
558551procedure TMiniRESTSQLConnectionSQLDb.CheckConnectionIsValid ;
559552begin
560553 if not IsValid then
561- raise Exception.Create(' A conexão foi invalidada.' );
554+ raise Exception.Create(' A conexão foi invalidada.' );
555+ end ;
556+
557+ procedure TMiniRESTSQLConnectionSQLDb.SetConnectionParams ;
558+ var
559+ LStringList: TStringList;
560+ LName: string;
561+ I: Integer;
562+ begin
563+ LStringList := TStringList.Create;
564+ try
565+ FSQLConnection.ConnectorType := GetConnectorType(FConnectionParams.GetDatabaseType);
566+ FSQLConnection.LoginPrompt := False;
567+ FSQLConnection.UserName := FConnectionParams.GetUserName;
568+ FSQLConnection.Password := FConnectionParams.GetPassword;
569+ FSQLConnection.DatabaseName := FConnectionParams.GetDatabaseName;
570+ FSQLConnection.HostName := FConnectionParams.GetServerHostName;
571+ LStringList.Text := FConnectionParams.GetConnectionString;
572+ for I := 0 to LStringList.Count - 1 do
573+ begin
574+ LName := LStringList.Names[I];
575+ FSQLConnection.Params.Values[LName] := LStringList.Values[LName];
576+ end ;
577+ finally
578+ LStringList.Free;
579+ end ;
580+ end ;
581+
582+ function TMiniRESTSQLConnectionParamsSQLDb.GetServerHostName : string;
583+ begin
584+ Result := FServerHostName;
585+ end ;
586+
587+ procedure TMiniRESTSQLConnectionParamsSQLDb.SetServerHostName (const AServerHostName: string);
588+ begin
589+ FServerHostName := AServerHostName;
562590end ;
563591
564592end .
0 commit comments