Firedac adapter fails to set paramtype correctly causing unicode issues

Issue #121 resolved
Todd Flora created an issue

The firedac adapter code only explicitly sets the param type in the setparam method when the underlying value is blank.

procedure TFireDACStatementAdapter.SetParam(const param: TDBParam);
var
  paramName: string;
  parameter: TFDParam;
begin
  paramName := param.NormalizeParamName(':', param.Name);
  parameter := Statement.ParamByName(paramName);
  parameter.Value := param.Value;
  if parameter.IsNull then
    parameter.DataType := param.ParamType;
end;

This causes issues with unicode support in Firedac as it's documentation explicitly states that the paramtype for unicode strings must be set to ftWideString before unicode will work correctly. When the value is used to determine the datatype Firedac will not correctly set the type to ftWideString in some cases as we are seeing in our code.

Please See the following FD Document page: http://docwiki.embarcadero.com/RADStudio/XE7/en/Unicode_Support_(FireDAC) under the subheading Parameter Values.

Therefore in order to support unicode we had to change the Firedac Adapter to always set the param type before setting the param value like so:

procedure TFireDACStatementAdapter.SetParam(const param: TDBParam);
var
  paramName: string;
  parameter: TFDParam;
begin
  paramName := param.NormalizeParamName(':', param.Name);
  parameter := Statement.ParamByName(paramName);
  parameter.DataType := param.ParamType;
  parameter.Value := param.Value;
end;

Comments (1)

  1. Log in to comment