Skip to content

Commit

Permalink
Implementação PostgreSQL (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
glprog authored Jun 26, 2020
1 parent 78864a9 commit 32ca238
Show file tree
Hide file tree
Showing 10 changed files with 371 additions and 188 deletions.
2 changes: 1 addition & 1 deletion MiniREST.SQL.Common.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 6 additions & 2 deletions MiniREST.SQL.SQLDb.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -342,6 +342,7 @@ function TMiniRESTSQLConnectionSQLDb.GetDriverName(const ADatabaseType: TMiniRES
begin
case ADatabaseType of
dbtFirebird: Result := 'Firebird';
dbtPostgreSQL: Result := 'PostgreSQL';
end;
end;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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 := '';
Expand All @@ -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;
Expand Down
25 changes: 16 additions & 9 deletions unittest/SQL/MiniRESTSQLTest.lpi
Original file line number Diff line number Diff line change
Expand Up @@ -33,40 +33,47 @@
<PackageName Value="FCL"/>
</Item3>
</RequiredPackages>
<Units Count="8">
<Units Count="10">
<Unit0>
<Filename Value="MiniRESTSQLTest.lpr"/>
<IsPartOfProject Value="True"/>
</Unit0>
<Unit1>
<Filename Value="test.sql.sqldb.pas"/>
<Filename Value="..\..\MiniREST.SQL.Base.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="Test.SQL.SQLDb"/>
</Unit1>
<Unit2>
<Filename Value="..\..\MiniREST.SQL.Base.pas"/>
<Filename Value="..\..\MiniREST.SQL.Common.pas"/>
<IsPartOfProject Value="True"/>
</Unit2>
<Unit3>
<Filename Value="..\..\MiniREST.SQL.Common.pas"/>
<Filename Value="..\..\MiniREST.SQL.Firebird.pas"/>
<IsPartOfProject Value="True"/>
</Unit3>
<Unit4>
<Filename Value="..\..\MiniREST.SQL.Firebird.pas"/>
<Filename Value="..\..\MiniREST.SQL.Intf.pas"/>
<IsPartOfProject Value="True"/>
</Unit4>
<Unit5>
<Filename Value="..\..\MiniREST.SQL.Intf.pas"/>
<Filename Value="Test.SQL.Default.pas"/>
<IsPartOfProject Value="True"/>
</Unit5>
<Unit6>
<Filename Value="Test.SQL.Default.pas"/>
<Filename Value="..\..\MiniREST.SQL.SQLDb.pas"/>
<IsPartOfProject Value="True"/>
</Unit6>
<Unit7>
<Filename Value="..\..\MiniREST.SQL.SQLDb.pas"/>
<Filename Value="Test.SQL.SQLDb.pas"/>
<IsPartOfProject Value="True"/>
</Unit7>
<Unit8>
<Filename Value="Test.SQL.Firebird.pas"/>
<IsPartOfProject Value="True"/>
</Unit8>
<Unit9>
<Filename Value="Test.SQL.PostgreSQL.pas"/>
<IsPartOfProject Value="True"/>
</Unit9>
</Units>
</ProjectOptions>
<CompilerOptions>
Expand Down
2 changes: 1 addition & 1 deletion unittest/SQL/MiniRESTSQLTest.lpr
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Loading

0 comments on commit 32ca238

Please sign in to comment.