-1

I migrated an IBX application which have 500+ forms to Firedac. I mapped the datatypes with Delphi Help. Here is my data mapping:

  with ADB.FormatOptions do
  begin
    OwnMapRules := True;
    DefaultParamDataType := ftVariant;

    MapRules.Clear;
    with MapRules.Add do
    begin
      PrecMax        := 4;
      PrecMin        := 0;
      ScaleMax       := 0;
      ScaleMin       := 0;
      SourceDataType := dtFmtBCD;
      TargetDataType := dtInt16;
    end;

    with MapRules.Add do
    begin
      PrecMax        := 10;
      PrecMin        := 5;
      ScaleMax       := 0;
      ScaleMin       := 0;
      SourceDataType := dtFmtBCD;
      TargetDataType := dtInt32;
    end;

    with MapRules.Add do
    begin
      PrecMax        := 18;
      PrecMin        := 11;
      ScaleMax       := 0;
      ScaleMin       := 0;
      SourceDataType := dtFmtBCD;
      TargetDataType := dtInt64;
    end;

    with MapRules.Add do
    begin
      SourceDataType := dtFmtBCD;
      TargetDataType := dtDouble;
    end;

    with MapRules.Add do
    begin
      SourceDataType := dtDateTimeStamp;
      TargetDataType := dtDateTime;
    end;
  end;

Is this mapping is true? If it's false, how do I it's true?

When a FDQuery has parameters and a parameter has no value on execute the query,an exception occured :

[FireDAC][Phys][FB]-338. Param [XXX] type changed from [ftVariant] to [ftInteger]. Query must be reprepared. Possible reason: an assignment to a TFDParam.AsXXX property implicitly changed the parameter data type. Hint: use the TFDParam.Value or appropriate TFDParam.AsXXX property

How do I solve this problem? Thanks for everything.

ErkanK
  • 95
  • 7
  • Are you asking whether a BCD-format field can be mapped to an integer? – MartynA Feb 26 '19 at 08:26
  • I ask true Firedac Firebird mapping for posibble situations @MartynA – ErkanK Feb 26 '19 at 08:34
  • Well, surely whether your BCD data can be *safely* mapped to integers depends on the values actually stored. So I think it's an unaswerable question, from that point of view. – MartynA Feb 26 '19 at 08:38
  • "When .... parameter has no value" - that means it should be SQL `NULL` as far as I can understand. Also, Delphi `variant` type has `null` as possible value. I did not work with AnyDAC, but maybe relevant (`TParam` type is maybe shared by all db-aware-compatible access libraries) experience with Delphi XE2 dbExpress shows that one has to make two steps and in proper order: `Par1 := Query1.ParamByName('...'); Par1.Clear {sets *both* Null value and null/variant type}; Par1.DataType := ftInteger {or any other expected type};` – Arioch 'The Feb 26 '19 at 11:32
  • Think about `DefaultParamDataType := ftVariant;` - maybe you can remove that line, or put something like `ftNull` or anything. Maybe there can be some special rules for `NULL` value to be casted to any of `TargetDataType` without re-conversions. Sadly original AnyDAc site is down, including the documentation there, but google for "anydac firebird parameter null Query must be reprepared" and there are at least some links – Arioch 'The Feb 26 '19 at 11:35
  • example: https://stackoverflow.com/questions/46428723 – Arioch 'The Feb 26 '19 at 11:40

1 Answers1

0

I solved my problem by using the mapping below:

with ADB.FormatOptions do
begin
  OwnMapRules := True;

  with MapRules.Add do
  begin
    SourceDataType := dtDateTimeStamp;
    TargetDataType := dtDateTime;
  end;

  with MapRules.Add do
  begin
    SourceDataType := dtDateTime;
    TargetDataType := dtDateTimeStamp;
  end;
end;

After than I build my application and test it. The Result is OK for me.

ErkanK
  • 95
  • 7