Skip to content

Commit

Permalink
Fix clear params on set SQL
Browse files Browse the repository at this point in the history
  • Loading branch information
glprog committed Oct 27, 2019
1 parent 8813171 commit 3e47290
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions MiniREST.SQL.SQLDb.pas
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ function TMiniRESTSQLQuerySQLDb.GetSQL: string;

procedure TMiniRESTSQLQuerySQLDb.SetSQL(const ASQL: string);
begin
FParams.Clear;
FSQL := ASQL;
FQry.SQL.Text := ASQL;
end;
Expand Down
28 changes: 28 additions & 0 deletions unittest/SQL/Test.SQL.Default.pas
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ TMiniRESTSQLTest = class({$IFNDEF FPC}TObject{$ELSE}TTestCase{$IFEND})
[Test]
{$IFEND}
procedure TestCheckInTransaction;
{$IFNDEF FPC}
[Test]
{$IFEND}
procedure TestClearParamsOnSetSQL;
(* {$IFNDEF FPC}
[Test]
{$IFEND}
Expand Down Expand Up @@ -544,4 +548,28 @@ procedure TMiniRESTSQLTest.TestCheckInTransaction;
{$IFEND}
end;

procedure TMiniRESTSQLTest.TestClearParamsOnSetSQL;
var
LConn1: IMiniRESTSQLConnection;
LQry: IMiniRESTSQLQuery;
LTotal: Integer;
begin
LConn1 := FConnectionFactory.GetConnection;
LQry := LConn1.GetQuery;
LQry.SQL := 'SELECT * FROM CUSTOMER WHERE NAME = :NAME';
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,
// passado anteriormente
LQry.Close;
LQry.SQL := 'SELECT * FROM CUSTOMER';
LQry.Open;
{$IFNDEF FPC}
Assert.AreTrue(LQry.DataSet.Active);
{$ELSE}
CheckTrue(LQry.DataSet.Active);
{$IFEND}
end;

end.

0 comments on commit 3e47290

Please sign in to comment.