Cannot convert <type1> to <type2>

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
felixbcastillo
Posts: 33
Joined: Tue 25 Nov 2014 17:26

Re: Cannot convert <type1> to <type2>

Post by felixbcastillo » Wed 29 Aug 2018 20:05

THE PROBLEM PERSISTS!

...Expecting: Currency actual: Memo

Returning back to version 7.2.7

PLEASE TRY THE SAME SAMPLES I SENT YOU!

ertank
Posts: 172
Joined: Wed 13 Jan 2016 16:00

Re: Cannot convert <type1> to <type2>

Post by ertank » Thu 30 Aug 2018 03:50

Hello,

I am using UniDAC 7.3.9 on Delphi 10.2.3 (all hotfixes and patches applied).

I confirm that I have same problem in a FMX project targetting Android platform.

Since I do not use any data aware components like DBGrid or smilar or any live binding with VirtualQuery, I used a workaround of accessing field as type string and converting it back to Currency, Double, etc.

MaximG
Devart Team
Posts: 1822
Joined: Mon 06 Jul 2015 11:34

Re: Cannot convert <type1> to <type2>

Post by MaximG » Thu 30 Aug 2018 09:03

We sent the links for downloading the night build with the required changes related to fixing the described error, to all users who contacted us using e-support form (https://www.devart.com/company/contactform.html). Perhaps for technical reasons, we could not receive your request. Please provide your license number and the IDE version that you are using via e-support again

felixbcastillo
Posts: 33
Joined: Tue 25 Nov 2014 17:26

Re: Cannot convert <type1> to <type2>

Post by felixbcastillo » Thu 30 Aug 2018 11:19

But the problem still persists.

When using "SELECT SUM(Field1) Field2 FROM TABLE1" in a VirtualQuery from a VirtualTable is resulting Field2 as a MemoField that can nlt be mapped to currency...

It was perfect in version 7.2.7 and you have not been able to fix it in 2 releases and 3 night builds...

I hope you really have it fixed before next release.

MaximG
Devart Team
Posts: 1822
Joined: Mon 06 Jul 2015 11:34

Re: Cannot convert <type1> to <type2>

Post by MaximG » Mon 03 Sep 2018 14:11

We tested the work of the night build sent to you using the following console application:

Code: Select all

program Project1;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils, Data.DB, VirtualTable, VirtualQuery;

var
  VirtualTable: TVirtualTable;
  VirtualQuery: TVirtualQuery;
begin
  VirtualTable := TVirtualTable.Create(nil);
  try
    VirtualTable.FieldDefs.Add('Field1', ftCurrency);
    VirtualTable.FieldDefs.Add('Field2', ftFloat);
    VirtualTable.Open;
    VirtualTable.Append;
    VirtualTable.FieldByName('Field1').AsCurrency := 1;
    VirtualTable.FieldByName('Field2').AsFloat := 2;
    VirtualTable.Post;
    VirtualQuery := TVirtualQuery.Create(nil);
    try
      VirtualQuery.SourceDataSets.Add(VirtualTable, '', 'TABLE1');
      VirtualQuery.SQL.Text := 'SELECT SUM(Field1) As Field1, Field2 FROM TABLE1';
      VirtualQuery.Open;
      Assert(VirtualQuery.FieldByName('Field2').DataType = ftFloat);
    finally
      VirtualQuery.Free;
    end;
  finally
    VirtualTable.Free;
  end;
end.


Please, check the behavior of this sample in your environment and let us know the results. In case of the correct behavior, change the sample code in order for the issue to occur

felixbcastillo
Posts: 33
Joined: Tue 25 Nov 2014 17:26

Re: Cannot convert <type1> to <type2>

Post by felixbcastillo » Mon 03 Sep 2018 14:51

Why did not you try this code? if it is included in my sample...

Assert(VirtualQuery.FieldByName('Field1').DataType = ftCurrency);

It fails too!

Returning back to version 7.2.7
Please!!!

MaximG
Devart Team
Posts: 1822
Joined: Mon 06 Jul 2015 11:34

Re: Cannot convert <type1> to <type2>

Post by MaximG » Tue 04 Sep 2018 07:32

In the provided sample, FIELD1 is the result of the SUM function. Therefore, to represent this field with the ftCurrency type, you should use DataTypeMapping.
We changed the sample according to your description and successfully executed it using UniDAC 7.2.7, as well as using the UniDAC_27_08_2018 night build sent to you:

Code: Select all

program Project1;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils,
  Data.DB,
  VirtualTable,
  VirtualQuery;
var
  VirtualTable: TVirtualTable;
  VirtualQuery: TVirtualQuery;
begin
  VirtualTable := TVirtualTable.Create(nil);
  try
    VirtualTable.FieldDefs.Add('Field1', ftCurrency);
    VirtualTable.FieldDefs.Add('Field2', ftFloat);
    VirtualTable.Open;
    VirtualTable.Append;
    VirtualTable.FieldByName('Field1').AsCurrency := 1;
    VirtualTable.FieldByName('Field2').AsFloat := 2;
    VirtualTable.Post;
    VirtualQuery := TVirtualQuery.Create(nil);
    try
      VirtualQuery.SourceDataSets.Add(VirtualTable, '', 'TABLE1');
      VirtualQuery.SQL.Text := 'SELECT SUM(Field1) As Field1, Field2 FROM TABLE1';
      VirtualQuery.Open;
      Assert(VirtualQuery.FieldByName('Field1').DataType = ftFloat);
      Assert(VirtualQuery.FieldByName('Field2').DataType = ftFloat);
      VirtualQuery.Close;
      VirtualQuery.DataTypeMap.AddFieldNameRule('Field1', ftCurrency);
      VirtualQuery.Open;
      Assert(VirtualQuery.FieldByName('Field1').DataType = ftCurrency);
      Assert(VirtualQuery.FieldByName('Field2').DataType = ftFloat);
    finally
      VirtualQuery.Free;
    end;
  finally
    VirtualTable.Free;
  end;
end.  
In both cases, we got an absolutely identical result. Please check the operation of the modified sample in your environment and let us know the results.

ertank
Posts: 172
Joined: Wed 13 Jan 2016 16:00

Re: Cannot convert <type1> to <type2>

Post by ertank » Tue 04 Sep 2018 08:32

Hello,

I just tested Night build from 3rd of September.

I confirm that Win32 platform does not have any problem. However, problem still continues on FMX platform. You should also make some tests on FMX platform.

Thanks & regards,
Ertan

MaximG
Devart Team
Posts: 1822
Joined: Mon 06 Jul 2015 11:34

Re: Cannot convert <type1> to <type2>

Post by MaximG » Tue 04 Sep 2018 10:41

To investigate the issue, please compose and send us the simplest FMX application, execution of which causes the issue. It is convenient to do it using the e-support form ( https://www.devart.com/company/contactform.html )

ertank
Posts: 172
Joined: Wed 13 Jan 2016 16:00

Re: Cannot convert <type1> to <type2>

Post by ertank » Tue 04 Sep 2018 13:20

I reproduced my case of problem on all platforms.

When field value tried to be reached as float/currency and it has Null value, exception raises. Maybe, there should be a parameter to return a zero (0) in such a case, or it maybe a default behavior.

Code: Select all

program Project1;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils,
  Data.DB,
  VirtualTable,
  VirtualQuery;
var
  VirtualTable: TVirtualTable;
  VirtualQuery: TVirtualQuery;
  ValueCurr: Currency;
begin
  VirtualTable := TVirtualTable.Create(nil);
  try
    VirtualTable.FieldDefs.Add('Field1', ftCurrency);
    VirtualTable.FieldDefs.Add('Field2', ftFloat);
    VirtualTable.Open;
//    VirtualTable.Append;
//    VirtualTable.FieldByName('Field1').AsCurrency := 1;
//    VirtualTable.FieldByName('Field2').AsFloat := 2;
//    VirtualTable.Post;
    VirtualQuery := TVirtualQuery.Create(nil);
    try
      VirtualQuery.SourceDataSets.Add(VirtualTable, '', 'TABLE1');
      VirtualQuery.SQL.Text := 'SELECT SUM(Field1) As Field1, Field2 FROM TABLE1';
      VirtualQuery.Open;
      Assert(VirtualQuery.FieldByName('Field1').DataType = ftFloat);
      Assert(VirtualQuery.FieldByName('Field2').DataType = ftFloat);
      VirtualQuery.Close;
      VirtualQuery.DataTypeMap.AddFieldNameRule('Field1', ftCurrency);
      VirtualQuery.Open;
      ValueCurr := VirtualQuery.FieldByName('Field1').AsCurrency; // Here you will get exception
    finally
      VirtualQuery.Free;
    end;
  finally
    VirtualTable.Free;
  end;
end.

MaximG
Devart Team
Posts: 1822
Joined: Mon 06 Jul 2015 11:34

Re: Cannot convert <type1> to <type2>

Post by MaximG » Tue 04 Sep 2018 15:06

Thank you for the information. We will investigate the described issue and let you know the results shortly.

felixbcastillo
Posts: 33
Joined: Tue 25 Nov 2014 17:26

Re: Cannot convert <type1> to <type2>

Post by felixbcastillo » Wed 05 Sep 2018 05:58

That is as I have in my samples, but they ran with data and my samples were empty/null records/fields

Thank you for explaining better, I was just keeping saying that the problem persisted and it did, but did not say a thing that helped.

Thank you again, I hope they now have it fixed!

felixbcastillo
Posts: 33
Joined: Tue 25 Nov 2014 17:26

Re: Cannot convert <type1> to <type2>

Post by felixbcastillo » Wed 05 Sep 2018 05:58

That is as I have in my samples, but they ran with data and my samples were empty/null records/fields

Thank you for explaining better, I was just keeping saying that the problem persisted and it did, but did not say a thing that helped.

Thank you again, I hope they now have it fixed!

ALL MY TESTS ARE IN FMX (Android) NOT VCL PROJECTS!

MaximG
Devart Team
Posts: 1822
Joined: Mon 06 Jul 2015 11:34

Re: Cannot convert <type1> to <type2>

Post by MaximG » Wed 05 Sep 2018 09:45

Thank you for the information. We reproduced the issue and fixed this error. The links to download the night build with the required changes were sent to your email.

felixbcastillo
Posts: 33
Joined: Tue 25 Nov 2014 17:26

Re: Cannot convert <type1> to <type2>

Post by felixbcastillo » Wed 05 Sep 2018 18:13

It is almost unbelievable!

No error messages, but no fine working neither!

VirtualTable empty in design time...All SUM(Fieldx) in VirtualQuery result in null
VirtualTable with a record in design time... Everything works fine!
VirtualTable with a record in design time, records added... Everything works fine!
VirtualTable with a record in design time, table cleared then records added... All SUM fields are null

Everything was fine in version 7.2.7
Trying to deal with it before returning to version 7.2.7

Post Reply