diff --git a/MiniREST.SQL.Common.pas b/MiniREST.SQL.Common.pas index 0a09542..55d5f16 100644 --- a/MiniREST.SQL.Common.pas +++ b/MiniREST.SQL.Common.pas @@ -5,7 +5,7 @@ interface uses SysUtils, Variants{$IFNDEF FPC},DB, Rtti{$ENDIF}; type - TMiniRESTSQLDatabaseType = (dbtUnknown, dbtFirebird); + TMiniRESTSQLDatabaseType = (dbtUnknown, dbtFirebird, dbtPostgreSQL); TMiniRESTSQLParamType = (stString, stFloat, stInteger, stDate, stDateTime, stBoolean, stVariant, stUndefined); diff --git a/MiniREST.SQL.SQLDb.pas b/MiniREST.SQL.SQLDb.pas index eeba717..739bafe 100644 --- a/MiniREST.SQL.SQLDb.pas +++ b/MiniREST.SQL.SQLDb.pas @@ -4,7 +4,7 @@ interface uses Classes, SysUtils, MiniREST.SQL.Intf, MiniREST.SQL.Base, MiniREST.SQL.Common, DB, - sqldb, IBConnection, fgl; + sqldb, IBConnection, pqconnection, fgl; type TLogEvent = procedure (Sender : TSQLConnection; EventType : TDBEventType; Const Msg : String); @@ -342,6 +342,7 @@ function TMiniRESTSQLConnectionSQLDb.GetDriverName(const ADatabaseType: TMiniRES begin case ADatabaseType of dbtFirebird: Result := 'Firebird'; + dbtPostgreSQL: Result := 'PostgreSQL'; end; end; @@ -484,6 +485,7 @@ function TMiniRESTSQLConnectionSQLDb.GetConnectorType(const ADatabaseType: TMini case ADatabaseType of dbtUnknown: raise Exception.Create('Database Type not supported'); dbtFirebird: Result := 'Firebird'; + dbtPostgreSQL: Result := 'PostgreSQL'; end; end; @@ -588,7 +590,7 @@ procedure TMiniRESTSQLConnectionSQLDb.SetConnectionParams; FSQLConnection.UserName := FConnectionParams.GetUserName; FSQLConnection.Password := FConnectionParams.GetPassword; FSQLConnection.DatabaseName := FConnectionParams.GetDatabaseName; - FSQLConnection.HostName := FConnectionParams.GetServerHostName; + FSQLConnection.HostName := FConnectionParams.GetServerHostName; if (FConnectionParams.GetServerPort > 0) and (FConnectionParams.GetDatabaseType = dbtFirebird) then begin FSQLConnection.HostName := ''; @@ -601,6 +603,8 @@ procedure TMiniRESTSQLConnectionSQLDb.SetConnectionParams; LName := LStringList.Names[I]; FSQLConnection.Params.Values[LName] := LStringList.Values[LName]; end; + if (FConnectionParams.GetServerPort > 0) and (FConnectionParams.GetDatabaseType = dbtPostgreSQL) then + FSQLConnection.Params.Values['port'] := IntToStr(FConnectionParams.GetServerPort); finally LStringList.Free; end; diff --git a/unittest/SQL/MiniRESTSQLTest.lpi b/unittest/SQL/MiniRESTSQLTest.lpi index b9a8873..b6d1f48 100644 --- a/unittest/SQL/MiniRESTSQLTest.lpi +++ b/unittest/SQL/MiniRESTSQLTest.lpi @@ -33,40 +33,47 @@ - + - + - - + - + - + - + - + - + + + + + + + + + diff --git a/unittest/SQL/MiniRESTSQLTest.lpr b/unittest/SQL/MiniRESTSQLTest.lpr index 3d22f30..7c349c4 100644 --- a/unittest/SQL/MiniRESTSQLTest.lpr +++ b/unittest/SQL/MiniRESTSQLTest.lpr @@ -3,7 +3,7 @@ {$mode objfpc}{$H+} uses - Classes, TextTestRunner, Test.SQL.SQLDb, SysUtils; + Classes, TextTestRunner, Test.SQL.Firebird, Test.SQL.PostgreSQL, SysUtils; begin {$DEFINE XMLLISTENER} diff --git a/unittest/SQL/MiniRESTSQLTest.lps b/unittest/SQL/MiniRESTSQLTest.lps index 16c5e1c..39a96c6 100644 --- a/unittest/SQL/MiniRESTSQLTest.lps +++ b/unittest/SQL/MiniRESTSQLTest.lps @@ -4,42 +4,33 @@ - + - - + + + - - - - - - - - - - - + - - + + - + - - + + @@ -47,32 +38,39 @@ - - + + - - + + - + - - + + - - - + + + + + + + + + + @@ -105,7 +103,7 @@ - + @@ -162,26 +160,26 @@ - + - + - + - + - + - + @@ -189,7 +187,7 @@ - + @@ -197,130 +195,146 @@ - + + + + + + + + + + + + + + + + + - - + + - + - + - - - - - - + + - - + + - - + + - - + + - - + + + + + + - + - - + + - + - - + + - + - + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - - + + diff --git a/unittest/SQL/Test.SQL.Default.pas b/unittest/SQL/Test.SQL.Default.pas index 01da33a..ea457a5 100644 --- a/unittest/SQL/Test.SQL.Default.pas +++ b/unittest/SQL/Test.SQL.Default.pas @@ -24,6 +24,9 @@ TMiniRESTSQLTest = class({$IFNDEF FPC}TObject{$ELSE}TTestCase{$IFEND}) procedure LogConnectionPoolEvent(const AMessage: string); function GetServerHostName: string; function GetServerPort: Integer; + function GetDatabaseType: TMiniRESTSQLDatabaseType; virtual; abstract; + procedure TestCharSetFirebird; + procedure TestCharSetPostgreSQL; public {$IFNDEF FPC} [SetupFixture] @@ -149,11 +152,13 @@ TThreadTesteInsert2 = class(TThread) FID: Integer; FFactory: IMiniRESTSQLConnectionFactory; FLogMessageProc: TLogMessageProc; + FTestCase: TMiniRESTSQLTest; procedure LogMessage(const AMessage: string); protected procedure Execute; override; public - constructor Create(const AID: Integer; ACreateSuspended: Boolean; AFactory: IMiniRESTSQLConnectionFactory; ALogMessageProc: TLogMessageProc); + constructor Create(const AID: Integer; ACreateSuspended: Boolean; AFactory: IMiniRESTSQLConnectionFactory; ALogMessageProc: TLogMessageProc; + ATestCase: TMiniRESTSQLTest); end; { TConnectionFactoryEventLogger } @@ -187,6 +192,7 @@ procedure TMiniRESTSQLTest.TearDown; (* LConnection := FConnectionFactory.GetConnection; LConnection.Execute('DELETE FROM CUSTOMER', []); *) + FConnectionFactory := nil; FConnectionPoolEvents.Free; end; @@ -200,17 +206,21 @@ procedure TMiniRESTSQLTest.TestInsert; LConn1 := FConnectionFactory.GetConnection; LConn2 := FConnectionFactory.GetConnection; LQry := LConn1.GetQuery; - LQryID := LConn1.GetQuery; + if GetDatabaseType = dbtFirebird then + LQryID := LConn1.GetQuery; LQry.SQL := 'SELECT * FROM CUSTOMER WHERE 1=0'; LQry.Open; for I := 0 to 99 do begin - LQryID.Close; - LQryID.SQL := 'select gen_id(gen_customer_id, 1) from rdb$database'; - LQryID.Open; - LId := LQryID.DataSet.FieldByName('GEN_ID').AsInteger; LQry.DataSet.Append; - LQry.DataSet.FieldByName('ID').AsInteger := LId; + if GetDatabaseType = dbtFirebird then + begin + LQryID.Close; + LQryID.SQL := 'select gen_id(gen_customer_id, 1) from rdb$database'; + LQryID.Open; + LId := LQryID.DataSet.FieldByName('GEN_ID').AsInteger; + LQry.DataSet.FieldByName('ID').AsInteger := LId; + end; LQry.DataSet.FieldByName('NAME').AsString := 'HUE'; LQry.DataSet.Post; end; @@ -229,7 +239,11 @@ procedure TMiniRESTSQLTest.Setup; LConnection: IMiniRESTSQLConnection; begin FServerHostName := 'LOCALHOST'; - FServerPort := 3050; + if GetDatabaseType = dbtFirebird then + FServerPort := 3050 + else + if GetDatabaseType = dbtPostgreSQL then + FServerPort := 5432; {$IFDEF FPC} FConnectionFactory := GetConnectionFactory; {$IFEND} @@ -359,12 +373,15 @@ procedure TMiniRESTSQLTest.TestTransaction; LQry.Open; for I := 0 to 99 do begin - LQryID.Close; - LQryID.SQL := 'select gen_id(gen_customer_id, 1) from rdb$database'; - LQryID.Open; - LId := LQryID.DataSet.FieldByName('GEN_ID').AsInteger; LQry.DataSet.Append; - LQry.DataSet.FieldByName('ID').AsInteger := LId; + if GetDatabaseType = dbtFirebird then + begin + LQryID.Close; + LQryID.SQL := 'select gen_id(gen_customer_id, 1) from rdb$database'; + LQryID.Open; + LId := LQryID.DataSet.FieldByName('GEN_ID').AsInteger; + LQry.DataSet.FieldByName('ID').AsInteger := LId; + end; LQry.DataSet.FieldByName('NAME').AsString := 'HUE'; LQry.DataSet.Post; end; @@ -395,12 +412,15 @@ procedure TMiniRESTSQLTest.TestTransaction2; LQry.Open; for I := 0 to 99 do begin - LQryID.Close; - LQryID.SQL := 'select gen_id(gen_customer_id, 1) from rdb$database'; - LQryID.Open; - LId := LQryID.DataSet.FieldByName('GEN_ID').AsInteger; LQry.DataSet.Append; - LQry.DataSet.FieldByName('ID').AsInteger := LId; + if GetDatabaseType = dbtFirebird then + begin + LQryID.Close; + LQryID.SQL := 'select gen_id(gen_customer_id, 1) from rdb$database'; + LQryID.Open; + LId := LQryID.DataSet.FieldByName('GEN_ID').AsInteger; + LQry.DataSet.FieldByName('ID').AsInteger := LId; + end; LQry.DataSet.FieldByName('NAME').AsString := 'HUE'; LQry.DataSet.Post; end; @@ -433,7 +453,7 @@ procedure TMiniRESTSQLTest.TestInsert2; LConn := FConnectionFactory.GetConnection; for I := 1 to LCount do begin - TThreadTesteInsert2.Create(I, False, FConnectionFactory, {$IFDEF FPC}@LogMessage{$ELSE}nil{$IFEND}); + TThreadTesteInsert2.Create(I, False, FConnectionFactory, {$IFDEF FPC}@LogMessage{$ELSE}nil{$IFEND}, Self); end; while not (gContatorTesteInsert2 = LCount) do Sleep(1000); @@ -457,18 +477,21 @@ procedure TThreadTesteInsert2.Execute; Sleep(Random(10) * 100); LConn := FFactory.GetConnection; LQry := LConn.GetQuery; - LQryID := LConn.GetQuery; - - LQryID.Close; - LQryID.SQL := 'select gen_id(gen_customer_id, 1) from rdb$database'; - LQryID.Open; - LId := LQryID.DataSet.FieldByName('GEN_ID').AsInteger; - LogMessage('CUSTOMER ID: ' + IntToStr(LId)); - LQryID.Close; + if FTestCase.GetDatabaseType = dbtFirebird then + begin + LQryID := LConn.GetQuery; + LQryID.Close; + LQryID.SQL := 'select gen_id(gen_customer_id, 1) from rdb$database'; + LQryID.Open; + LId := LQryID.DataSet.FieldByName('GEN_ID').AsInteger; + LogMessage('CUSTOMER ID: ' + IntToStr(LId)); + LQryID.Close; + end; LQry.SQL := 'SELECT * FROM CUSTOMER WHERE 1=0'; LQry.Open; LQry.DataSet.Insert; - LQry.DataSet.FieldByName('ID').AsInteger := LId; + if FTestCase.GetDatabaseType = dbtFirebird then + LQry.DataSet.FieldByName('ID').AsInteger := LId; LQry.DataSet.FieldByName('NAME').AsString := 'HUE'; LQry.DataSet.Post; @@ -478,13 +501,15 @@ procedure TThreadTesteInsert2.Execute; end; end; -constructor TThreadTesteInsert2.Create(const AID: Integer; ACreateSuspended: Boolean; AFactory: IMiniRESTSQLConnectionFactory; ALogMessageProc: TLogMessageProc); +constructor TThreadTesteInsert2.Create(const AID: Integer; ACreateSuspended: Boolean; AFactory: IMiniRESTSQLConnectionFactory; ALogMessageProc: TLogMessageProc; + ATestCase: TMiniRESTSQLTest); begin inherited Create(ACreateSuspended); FFactory := AFactory; FreeOnTerminate := True; FLogMessageProc := ALogMessageProc; - FID := AID; + FID := AID; + FTestCase := ATestCase; end; procedure TMiniRESTSQLTest.LogMessage(const AMessage: string); @@ -512,7 +537,8 @@ procedure TMiniRESTSQLTest.TestInsert3; for I := 1 to 5 do begin LQry.DataSet.Append; - LQry.DataSet.FieldByName('ID').AsInteger := GetSequenceValue('gen_customer_id'); + if GetDatabaseType = dbtFirebird then + LQry.DataSet.FieldByName('ID').AsInteger := GetSequenceValue('gen_customer_id'); LQry.DataSet.FieldByName('NAME').AsString := 'HUE'; LQry.DataSet.Post; end; @@ -607,23 +633,23 @@ procedure TMiniRESTSQLTest.TestCheckInTransaction; begin LConn1 := FConnectionFactory.GetConnection; {$IFNDEF FPC} - Assert.IsFalse(LConn1.InTransaction, 'Está em transação'); + Assert.IsFalse(LConn1.InTransaction, 'Est� em transa��o'); {$ELSE} - CheckFalse(LConn1.InTransaction, 'Está em transação'); + CheckFalse(LConn1.InTransaction, 'Est� em transa��o'); {$IFEND} LConn1.StartTransaction; {$IFNDEF FPC} - Assert.IsTrue(LConn1.InTransaction, 'Não está em transação'); + Assert.IsTrue(LConn1.InTransaction, 'N�o est� em transa��o'); {$ELSE} - CheckTrue(LConn1.InTransaction, 'Não está em transação'); + CheckTrue(LConn1.InTransaction, 'N�o est� em transa��o'); {$IFEND} LConn1.Commit; {$IFNDEF FPC} - Assert.IsFalse(LConn1.InTransaction, 'Está em transação'); + Assert.IsFalse(LConn1.InTransaction, 'Est� em transa��o'); {$ELSE} - CheckFalse(LConn1.InTransaction, 'Está em transação'); + CheckFalse(LConn1.InTransaction, 'Est� em transa��o'); {$IFEND} end; @@ -639,7 +665,7 @@ procedure TMiniRESTSQLTest.TestClearParamsOnSetSQL; LQry.ParamByName('NAME').AsString := 'HUE'; LQry.Open; - // O teste é assim para verificar se não vai dar erro quando não existir o parâmetro, + // O teste � assim para verificar se n�o vai dar erro quando n�o existir o par�metro, // passado anteriormente LQry.Close; LQry.SQL := 'SELECT * FROM CUSTOMER'; @@ -743,13 +769,13 @@ procedure TMiniRESTSQLTest.TestGetSingletonConnection; LConn1 := FConnectionFactory.GetSingletonConnection; LConn2 := FConnectionFactory.GetSingletonConnection; {$IFNDEF FPC} - Assert.IsTrue(LConn1 <> nil, 'LCon1 está nil'); - Assert.IsTrue(LConn2 <> nil, 'LCon2 está nil'); - Assert.IsTrue(LConn1 = LConn2, 'LCon1 está diferente de LCon2'); + Assert.IsTrue(LConn1 <> nil, 'LCon1 est� nil'); + Assert.IsTrue(LConn2 <> nil, 'LCon2 est� nil'); + Assert.IsTrue(LConn1 = LConn2, 'LCon1 est� diferente de LCon2'); {$ELSE} - CheckTrue(LConn1 <> nil, 'LCon1 está nil'); - CheckTrue(LConn2 <> nil, 'LCon2 está nil'); - CheckTrue(LConn1 = LConn2, 'LCon1 está diferente de LCon2'); + CheckTrue(LConn1 <> nil, 'LCon1 est� nil'); + CheckTrue(LConn2 <> nil, 'LCon2 est� nil'); + CheckTrue(LConn1 = LConn2, 'LCon1 est� diferente de LCon2'); {$IFEND} end; @@ -759,9 +785,9 @@ procedure TMiniRESTSQLTest.TestConnectionIsValid; begin LConn1 := FConnectionFactory.GetConnection; {$IFNDEF FPC} - Assert.IsTrue(LConn1.IsValid, 'LCon1 não está válida.'); + Assert.IsTrue(LConn1.IsValid, 'LCon1 n�o est� v�lida.'); {$ELSE} - CheckTrue(LConn1.IsValid, 'LCon1 não está válida.'); + CheckTrue(LConn1.IsValid, 'LCon1 n�o est� v�lida.'); {$IFEND} end; @@ -771,15 +797,15 @@ procedure TMiniRESTSQLTest.TestConnectionIsNotValid; begin LConn1 := FConnectionFactory.GetConnection; {$IFNDEF FPC} - Assert.IsTrue(LConn1.IsValid, 'LCon1 não está válida.'); + Assert.IsTrue(LConn1.IsValid, 'LCon1 n�o est� v�lida.'); {$ELSE} - CheckTrue(LConn1.IsValid, 'LCon1 não está válida.'); + CheckTrue(LConn1.IsValid, 'LCon1 n�o est� v�lida.'); {$IFEND} FConnectionFactory.InvalidateConnections; {$IFNDEF FPC} - Assert.IsFalse(LConn1.IsValid, 'LCon1 está válida.'); + Assert.IsFalse(LConn1.IsValid, 'LCon1 est� v�lida.'); {$ELSE} - CheckFalse(LConn1.IsValid, 'LCon1 está válida.'); + CheckFalse(LConn1.IsValid, 'LCon1 est� v�lida.'); {$IFEND} end; @@ -857,12 +883,15 @@ procedure TMiniRESTSQLTest.TestParamSize; LQry.Open; for I := 0 to 5 do begin - LQryID.Close; - LQryID.SQL := 'select gen_id(gen_customer_id, 1) from rdb$database'; - LQryID.Open; - LId := LQryID.DataSet.FieldByName('GEN_ID').AsInteger; LQry.DataSet.Append; - LQry.DataSet.FieldByName('ID').AsInteger := LId; + if GetDatabaseType = dbtFirebird then + begin + LQryID.Close; + LQryID.SQL := 'select gen_id(gen_customer_id, 1) from rdb$database'; + LQryID.Open; + LId := LQryID.DataSet.FieldByName('GEN_ID').AsInteger; + LQry.DataSet.FieldByName('ID').AsInteger := LId; + end; LQry.DataSet.FieldByName('NAME').AsString := 'HUE'; LQry.DataSet.FieldByName('PHONE').AsString := '999999999999999'; LQry.DataSet.Post; @@ -880,7 +909,7 @@ procedure TMiniRESTSQLTest.TestParamSize; {$IFEND} end; -procedure TMiniRESTSQLTest.TestCharSet; +procedure TMiniRESTSQLTest.TestCharSetFirebird; var LConn1: IMiniRESTSQLConnection; LQry: IMiniRESTSQLQuery; @@ -921,4 +950,49 @@ procedure TMiniRESTSQLTest.TestCharSet; {$IFEND} end; +procedure TMiniRESTSQLTest.TestCharSet; +begin + if GetDatabaseType = dbtFirebird then + TestCharSetFirebird + else + if GetDatabaseType = dbtPostgreSQL then + CheckTrue(True); {TODO: Verificar charset postgresql} + //TestCharSetPostgreSQL; +end; + +procedure TMiniRESTSQLTest.TestCharSetPostgreSQL; +var + LConn1: IMiniRESTSQLConnection; + LQry: IMiniRESTSQLQuery; + LConnectionFactory: IMiniRESTSQLConnectionFactory; + LConnectionFactoryParams: IMiniRESTSQLConnectionFactoryParams; + LExpectedFilePath: string; +begin + LConnectionFactoryParams := GetConnectionFactoryParams; + LConnectionFactoryParams.SetCharSet('UTF8'); + LConnectionFactory := GetConnectionFactory(LConnectionFactoryParams); + LExpectedFilePath := ParamStr(0); + LConn1 := LConnectionFactory.GetConnection; + LQry := LConn1.GetQuery; + LQry.SQL := 'SHOW CLIENT_ENCODING'; + LQry.Open; + {$IFNDEF FPC} + Assert.AreTrue(LQry.DataSet.FieldByName('CLIENT_ENCODING').AsString = 'UTF8'); + {$ELSE} + CheckTrue(LQry.DataSet.FieldByName('CLIENT_ENCODING').AsString = 'UTF8'); + {$IFEND} + + LConnectionFactoryParams.SetCharSet('WIN1252'); + LConnectionFactory := GetConnectionFactory(LConnectionFactoryParams); + LConn1 := LConnectionFactory.GetConnection; + LQry := LConn1.GetQuery; + LQry.SQL := 'SHOW CLIENT_ENCODING'; + LQry.Open; + {$IFNDEF FPC} + Assert.AreTrue(LQry.DataSet.FieldByName('CLIENT_ENCODING').AsString = 'WIN1252'); + {$ELSE} + CheckEquals('WIN1252', LQry.DataSet.FieldByName('CLIENT_ENCODING').AsString); + {$IFEND} +end; + end. diff --git a/unittest/SQL/Test.SQL.Firebird.pas b/unittest/SQL/Test.SQL.Firebird.pas new file mode 100644 index 0000000..245aa1a --- /dev/null +++ b/unittest/SQL/Test.SQL.Firebird.pas @@ -0,0 +1,59 @@ +unit Test.SQL.Firebird; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, TestFramework, MiniREST.SQL.SQLDb, + MiniREST.SQL.Intf, MiniREST.SQL.Common, sqldb, Test.SQL.SQLDb; + +type + TMiniRESTSQLTestSQLFirebird = class(TMiniRESTSQLTestSQLDbFPC) + protected + function GetConnectionFactoryParams: IMiniRESTSQLConnectionFactoryParams; override; + function GetDatabaseType: TMiniRESTSQLDatabaseType; override; + end; + +implementation + +function TMiniRESTSQLTestSQLFirebird.GetConnectionFactoryParams: IMiniRESTSQLConnectionFactoryParams; +var + LConnectionInfo: TStringList; + LDBFilePath: string; + LPathAux: string; + LParams: IMiniRESTSQLConnectionFactoryParamsSQLDb; +begin + LConnectionInfo := TStringList.Create; + try + //LConnectionInfo.LoadFromFile('..\..\dbxcon.txt'); + LPathAux := ExtractFilePath(ParamStr(0)) + '..\TEST.FDB'; + LDBFilePath := ExpandFileName(LPathAux); + LConnectionInfo.Values['DatabaseName'] := LDBFilePath; + LConnectionInfo.Values['Server'] := GetServerHostName; + LParams := TMiniRESTSQLConnectionParamsSQLDb.Create; + LParams.SetConnectionsCount(FConnectionCount); + LParams.SetConnectionString(LConnectionInfo.Text); + LParams.SetDatabseType(dbtFirebird); + LParams.SetDatabaseName(LDBFilePath); + LParams.SetUserName('SYSDBA'); + LParams.SetPassword('masterkey'); + LParams.SetLogEvent(@LogEvent); + LParams.SetServerHostName(GetServerHostName); + LParams.SetServerPort(GetServerPort); + Result := LParams; + finally + LConnectionInfo.Free; + end; +end; + +function TMiniRESTSQLTestSQLFirebird.GetDatabaseType: TMiniRESTSQLDatabaseType; +begin + Result := dbtFirebird; +end; + +initialization + RegisterTest(TMiniRESTSQLTestSQLFirebird.Suite); + +end. + diff --git a/unittest/SQL/Test.SQL.PostgreSQL.pas b/unittest/SQL/Test.SQL.PostgreSQL.pas new file mode 100644 index 0000000..90c0b41 --- /dev/null +++ b/unittest/SQL/Test.SQL.PostgreSQL.pas @@ -0,0 +1,59 @@ +unit Test.SQL.PostgreSQL; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, TestFramework, MiniREST.SQL.SQLDb, + MiniREST.SQL.Intf, MiniREST.SQL.Common, sqldb, Test.SQL.SQLDb; + +type + TMiniRESTSQLTestSQLPostgreSQL = class(TMiniRESTSQLTestSQLDbFPC) + protected + function GetConnectionFactoryParams: IMiniRESTSQLConnectionFactoryParams; override; + function GetDatabaseType: TMiniRESTSQLDatabaseType; override; + end; + +implementation + +function TMiniRESTSQLTestSQLPostgreSQL.GetConnectionFactoryParams: IMiniRESTSQLConnectionFactoryParams; +var + //LConnectionInfo: TStringList; + //LDBFilePath: string; + //LPathAux: string; + LParams: IMiniRESTSQLConnectionFactoryParamsSQLDb; +begin + //LConnectionInfo := TStringList.Create; + try + //LConnectionInfo.LoadFromFile('..\..\dbxcon.txt'); + //LPathAux := ExtractFilePath(ParamStr(0)) + '..\TEST.FDB'; + //LDBFilePath := ExpandFileName(LPathAux); + //LConnectionInfo.Values['DatabaseName'] := LDBFilePath; + //LConnectionInfo.Values['Server'] := GetServerHostName; + LParams := TMiniRESTSQLConnectionParamsSQLDb.Create; + LParams.SetConnectionsCount(FConnectionCount); + //LParams.SetConnectionString(''); + LParams.SetDatabseType(dbtPostgreSQL); + LParams.SetDatabaseName('minirestsql'); + LParams.SetUserName('postgres'); + LParams.SetPassword('postgres'); + LParams.SetLogEvent(@LogEvent); + LParams.SetServerHostName(GetServerHostName); + LParams.SetServerPort(GetServerPort); + Result := LParams; + finally + //LConnectionInfo.Free; + end; +end; + +function TMiniRESTSQLTestSQLPostgreSQL.GetDatabaseType: TMiniRESTSQLDatabaseType; +begin + Result := dbtPostgreSQL; +end; + +initialization + RegisterTest(TMiniRESTSQLTestSQLPostgreSQL.Suite); + +end. + diff --git a/unittest/SQL/test.sql.sqldb.pas b/unittest/SQL/test.sql.sqldb.pas index 0c94ec4..bfeae32 100644 --- a/unittest/SQL/test.sql.sqldb.pas +++ b/unittest/SQL/test.sql.sqldb.pas @@ -12,18 +12,18 @@ interface { TMiniRESTSQLTestSQLDbFPC } TMiniRESTSQLTestSQLDbFPC= class(TMiniRESTSQLTest) - private - function InternalGetConnectionFactoryParams: IMiniRESTSQLConnectionFactoryParamsSQLDb; protected procedure SetUpOnce; override; function GetConnectionFactory: IMiniRESTSQLConnectionFactory; override; overload; function GetConnectionFactory(AParams: IMiniRESTSQLConnectionFactoryParams): IMiniRESTSQLConnectionFactory; override; overload; - function GetConnectionFactoryParams: IMiniRESTSQLConnectionFactoryParams; override; procedure LogMessage(const AMessage: string); override; published procedure TestSQLDB1; end; + procedure LogEvent(Sender : TSQLConnection; EventType : TDBEventType; Const Msg : String); overload; + procedure LogEvent(Const Msg : String); overload; + implementation var @@ -82,45 +82,11 @@ function TMiniRESTSQLTestSQLDbFPC.GetConnectionFactory(AParams: IMiniRESTSQLConn LParams: IMiniRESTSQLConnectionFactoryParamsSQLDb; begin if not AParams.GetObject.GetInterface(IMiniRESTSQLConnectionFactoryParamsSQLDb, LParams) then - raise Exception.Create('AParams não implementa a interface IMiniRESTSQLConnectionFactoryParamsSQLDb'); + raise Exception.Create('AParams não implementa a interface IMiniRESTSQLConnectionFactoryParamsSQLDb'); Result := TMiniRESTSQLConnectionFactorySQLDb.Create(LParams); end; -function TMiniRESTSQLTestSQLDbFPC.GetConnectionFactoryParams: IMiniRESTSQLConnectionFactoryParams; -begin - Result := InternalGetConnectionFactoryParams; -end; - -function TMiniRESTSQLTestSQLDbFPC.InternalGetConnectionFactoryParams: IMiniRESTSQLConnectionFactoryParamsSQLDb; -var - LConnectionInfo: TStringList; - LDBFilePath: string; - LPathAux: string; -begin - LConnectionInfo := TStringList.Create; - try - //LConnectionInfo.LoadFromFile('..\..\dbxcon.txt'); - LPathAux := ExtractFilePath(ParamStr(0)) + '..\TEST.FDB'; - LDBFilePath := ExpandFileName(LPathAux); - LConnectionInfo.Values['DatabaseName'] := LDBFilePath; - LConnectionInfo.Values['Server'] := GetServerHostName; - Result := TMiniRESTSQLConnectionParamsSQLDb.Create; - Result.SetConnectionsCount(FConnectionCount); - Result.SetConnectionString(LConnectionInfo.Text); - Result.SetDatabseType(dbtFirebird); - Result.SetDatabaseName(LDBFilePath); - Result.SetUserName('SYSDBA'); - Result.SetPassword('masterkey'); - Result.SetLogEvent(@LogEvent); - Result.SetServerHostName(GetServerHostName); - Result.SetServerPort(GetServerPort); - finally - LConnectionInfo.Free; - end; -end; - -initialization - RegisterTest(TMiniRESTSQLTestSQLDbFPC.Suite); +initialization if FileExists('log.txt') then DeleteFile('log.txt'); gLog := TStringList.Create; diff --git a/unittest/TEST.FDB b/unittest/TEST.FDB index ada90c5..2d2b8c7 100644 Binary files a/unittest/TEST.FDB and b/unittest/TEST.FDB differ