Firedac Adapter must set Param Datatype if the Param value is unassigned

Issue #77 closed
Todd Flora created an issue

When attempting to insert a record using FireDac, the Parameters must be typed otherwise Firedac fails with the following exception.

Capture.PNG

Thiis a one line fix to ensure that Firedac knows the parameter type of the value is unassigned.

Please add the following line to the TFireDacStatementAdapter.SetParam method in the Spring.Persistence.Adapters.FireDAC Unit.

procedure TFireDACStatementAdapter.SetParam(const param: TDBParam);
var
  paramName: string;
begin
  paramName := param.Name;
  //strip leading : in param name because FireDAC does not like them
  if (param.Name <> '') and StartsStr(':', param.Name) then
    paramName := Copy(param.Name, 2, Length(param.Name));
  {TFlora - If a param value is null then FD must know the type of the param,
     so set the type into the parameter before setting the value}
  Statement.Params.ParamByName(paramName).DataType := Param.ParamType;  <--- This line needs to be added
  Statement.Params.ParamValues[paramName] := param.Value;
end;

This issue is related to #76 which I have also updated with my fix code.

Comments (5)

  1. Log in to comment