Adapter DBX: Error when assigning parameters

Issue #158 resolved
Eurides Baptistella created an issue

I was having some problems using method session.FindOne<T>(?), he could not find the register with code = 1 in database, returned nil always, but the record was there!

I use DBExpress adapter and investigated the problem!
The method ExecuteQuery in unit Spring.Persistence.Adapters.DBX is where the parameters set, they were always with Unassigned value (null/nil).

I realized that the assignment of the parameters was being made in this way:

query.Params.AssignValues (query.Params)

confused... the "query" object is TSQLQuery, was soon being assigned to himself.

I propose this change:

query.Params.AssignValues (Statement.Params);

Makes sense?

function TDBXStatementAdapter.ExecuteQuery(serverSideCursor: Boolean): IDBResultSet;
var
  query: TSQLQuery;
begin
  inherited;
  query               := TSQLQuery.Create(nil);
  query.SQLConnection := Statement.SQLConnection;
  query.SQL.Text      := Statement.SQL.Text;
  //query.Params.AssignValues(query.Params);
  query.Params.AssignValues(Statement.Params);
  query.DisableControls;
  try
    query.Open;
    Result := TDBXResultSetAdapter.Create(query, exceptionHandler);
  except
    on E: Exception do
    begin
      query.Free;
      raise HandleException(Format(SCannotOpenQuery, [E.Message]));
    end;
  end;
end;

Comments (4)

  1. Log in to comment