From 0968ac92d77d7db3f5c96a0c2e4139086226408a Mon Sep 17 00:00:00 2001 From: Glaucos Ginez Date: Fri, 20 Mar 2020 22:34:45 -0300 Subject: [PATCH] =?UTF-8?q?Implementa=C3=A7=C3=A3o=20par=C3=A2metro=20port?= =?UTF-8?q?a=20(#9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MiniREST.SQL.SQLDb.pas | 21 ++++++++++++++ unittest/SQL/Test.SQL.Default.pas | 45 ++++++++++++++++++++++++++++++ unittest/SQL/test.sql.sqldb.pas | 1 + unittest/TEST.FDB | Bin 1064960 -> 1064960 bytes 4 files changed, 67 insertions(+) diff --git a/MiniREST.SQL.SQLDb.pas b/MiniREST.SQL.SQLDb.pas index 737ade1..daeb0bc 100644 --- a/MiniREST.SQL.SQLDb.pas +++ b/MiniREST.SQL.SQLDb.pas @@ -24,6 +24,8 @@ interface procedure SetLogEvent(const ALogEvent: TLogEvent); function GetServerHostName: string; procedure SetServerHostName(const AServerHostName: string); + function GetServerPort: Integer; + procedure SetServerPort(const AServerPort: Integer); end; TMiniRESTSQLConnectionParamsSQLDb = class(TMiniRESTSQLConnectionFactoryParams, IMiniRESTSQLConnectionFactoryParamsSQLDb) @@ -35,6 +37,7 @@ TMiniRESTSQLConnectionParamsSQLDb = class(TMiniRESTSQLConnectionFactoryParams, FDatabaseName: string; FLogEvent: TLogEvent; FServerHostName: string; + FPort: Integer; public function GetConnectionString: string; procedure SetConnectionString(const AConnectionString: string); @@ -50,6 +53,8 @@ TMiniRESTSQLConnectionParamsSQLDb = class(TMiniRESTSQLConnectionFactoryParams, procedure SetLogEvent(const ALogEvent: TLogEvent); function GetServerHostName: string; procedure SetServerHostName(const AServerHostName: string); + function GetServerPort: Integer; + procedure SetServerPort(const AServerPort: Integer); end; TMiniRESTSQLConnectionFactorySQLDb = class(TMiniRESTSQLConnectionFactoryBase) @@ -568,6 +573,12 @@ procedure TMiniRESTSQLConnectionSQLDb.SetConnectionParams; FSQLConnection.Password := FConnectionParams.GetPassword; FSQLConnection.DatabaseName := FConnectionParams.GetDatabaseName; FSQLConnection.HostName := FConnectionParams.GetServerHostName; + if (FConnectionParams.GetServerPort > 0) and (FConnectionParams.GetDatabaseType = dbtFirebird) then + begin + FSQLConnection.HostName := ''; + FSQLConnection.DatabaseName := FConnectionParams.GetServerHostName + '/' + IntToStr(FConnectionParams.GetServerPort) + ':' + + FConnectionParams.GetDatabaseName; + end; LStringList.Text := FConnectionParams.GetConnectionString; for I := 0 to LStringList.Count - 1 do begin @@ -589,4 +600,14 @@ procedure TMiniRESTSQLConnectionParamsSQLDb.SetServerHostName(const AServerHostN FServerHostName := AServerHostName; end; +function TMiniRESTSQLConnectionParamsSQLDb.GetServerPort: Integer; +begin + Result := FPort; +end; + +procedure TMiniRESTSQLConnectionParamsSQLDb.SetServerPort(const AServerPort: Integer); +begin + FPort := AServerPort; +end; + end. diff --git a/unittest/SQL/Test.SQL.Default.pas b/unittest/SQL/Test.SQL.Default.pas index 2ccfc60..2209bf7 100644 --- a/unittest/SQL/Test.SQL.Default.pas +++ b/unittest/SQL/Test.SQL.Default.pas @@ -10,6 +10,7 @@ interface TMiniRESTSQLTest = class({$IFNDEF FPC}TObject{$ELSE}TTestCase{$IFEND}) private FServerHostName: string; + FServerPort: Integer; procedure MethodThatRaiseException; protected FConnectionCount: Integer; @@ -22,6 +23,7 @@ TMiniRESTSQLTest = class({$IFNDEF FPC}TObject{$ELSE}TTestCase{$IFEND}) function GetSequenceValue(const ASequenceName: string): Integer; procedure LogConnectionPoolEvent(const AMessage: string); function GetServerHostName: string; + function GetServerPort: Integer; public {$IFNDEF FPC} [SetupFixture] @@ -116,6 +118,14 @@ TMiniRESTSQLTest = class({$IFNDEF FPC}TObject{$ELSE}TTestCase{$IFEND}) [Test] {$IFEND} procedure TestFailWithInvalidServerHostName; + {$IFNDEF FPC} + [Test] + {$IFEND} + procedure TestFailWithInvalidServerPort; + {$IFNDEF FPC} + [Test] + {$IFEND} + procedure TestSuccessWithDefaultServerPort; (* {$IFNDEF FPC} [Test] {$IFEND} @@ -210,6 +220,8 @@ procedure TMiniRESTSQLTest.Setup; var LConnection: IMiniRESTSQLConnection; begin + FServerHostName := 'LOCALHOST'; + FServerPort := 3050; {$IFDEF FPC} FConnectionFactory := GetConnectionFactory; {$IFEND} @@ -785,4 +797,37 @@ procedure TMiniRESTSQLTest.MethodThatRaiseException; LQry.Open; end; +procedure TMiniRESTSQLTest.TestFailWithInvalidServerPort; +begin + FServerPort := 3099; + FConnectionFactory := GetConnectionFactory(GetConnectionFactoryParams); + CheckException(@MethodThatRaiseException, Exception); +end; + +function TMiniRESTSQLTest.GetServerPort: Integer; +begin + Result := FServerPort; +end; + +procedure TMiniRESTSQLTest.TestSuccessWithDefaultServerPort; +var + LConn1: IMiniRESTSQLConnection; + LQry: IMiniRESTSQLQuery; + LTotal: Integer; +begin + FServerPort := 0; + FConnectionFactory := GetConnectionFactory(GetConnectionFactoryParams); + LConn1 := FConnectionFactory.GetConnection; + LQry := LConn1.GetQuery; + LQry.SQL := 'SELECT * FROM CUSTOMER WHERE NAME = :NAME'; + LQry.ParamByName('NAME').AsString := 'HUE'; + LQry.Open; + + {$IFNDEF FPC} + Assert.AreTrue(LQry.DataSet.Active); + {$ELSE} + CheckTrue(LQry.DataSet.Active); + {$IFEND} +end; + end. diff --git a/unittest/SQL/test.sql.sqldb.pas b/unittest/SQL/test.sql.sqldb.pas index 4b5703c..0c94ec4 100644 --- a/unittest/SQL/test.sql.sqldb.pas +++ b/unittest/SQL/test.sql.sqldb.pas @@ -113,6 +113,7 @@ function TMiniRESTSQLTestSQLDbFPC.InternalGetConnectionFactoryParams: IMiniRESTS Result.SetPassword('masterkey'); Result.SetLogEvent(@LogEvent); Result.SetServerHostName(GetServerHostName); + Result.SetServerPort(GetServerPort); finally LConnectionInfo.Free; end; diff --git a/unittest/TEST.FDB b/unittest/TEST.FDB index cf4c4972bd8deec16ce8a0248bb35ffb3e554c2a..12d7dfa6d18e60ca9b7a6b374aa8ff7eb52afec3 100644 GIT binary patch delta 1640 zcmbu7ze~eF6vyvJ`Xg!DoT5WjunK}hK{s)9kh*CGS7~t(MEWNrD6~2V#-(c}ClP~S zCfDw|C@KizAi602*81bs*7l@_2j-4%j?3qJym#-OZI9XZ*d#`y!z=R?H3o~>Kf9|O zMb~v9MDXARLI=kf&-T>Z3=x>w?+u18c>TT<_KbC=#96Xtx`UbYY;nTXQ^jf z>$jFuQTl(u(aj*|qgH_6)xbd$umWWtJOSfZ`R7ul+>X{+Jo7aF%!}RbwVy%@m7xnT zOakjk&OguVGrE&itV3Y+feEg>BNbj8Q8Y0B?u7b4Fax9cuc}I zj$5J|s+>W@qY@sG@Nknue8CMvO@ojt5>6$YGAOYMk2zUi?1!(P$&&=Qb^TBh` z`@i!BL2?xdf0OW6jtk%ag)@k%^DN;{68_laBf|1OGz~(2pYiW4ow4}kK=pm4ylFfd%Y#mHzN2~jP;zyyQ| zU=AaY1ghPxsKB_9f06(T?-X%}qR&9;*u+5TW*vcc9RWrlW&&bnAZ7t#Rv=~rVs;?r z*sdeMc_W`WLWpT%pyYIg2F?KHxe81h1AFYJ zmC9QQ7|=pMzL|i06GYw`XEtjjU_gVy_Am830s_26LZCQ;g6)D6xR