Problem adding calculated field to a query

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
sandy771
Posts: 194
Joined: Tue 22 May 2007 13:57

Problem adding calculated field to a query

Post by sandy771 » Wed 28 Jun 2017 22:25

I am having problems adding a calculated field to a query at run time

The following query fails with an exception

Code: Select all

	UniQuery1->SQL->Clear();
	UniQuery1->SQL->Text = "select count(*) as rowcount from sqlite_master"

	UniQuery1->FieldDefs->Update();
	TField *field;
	for (int f = 0; f < UniQuery1->FieldDefs->Count; f++)
		field = UniQuery1->FieldDefs->Items[f]->CreateField(UniQuery1);

	TIntegerField *field2;
	field2 = new TIntegerField(UniQuery1);
	field2->FieldName = "id";
	field2->FieldKind = fkCalculated;
	field2->DataSet = UniQuery1;

	UniQuery1->Open();

	while(!UniQuery1->Eof)
	{
		for(int i=0; i<UniQuery1->FieldCount; i++)
		{
			f = UniQuery1->Fields->FieldByNumber(i+1);     <-- results in exception "Error Field is not BLOB"
                }
        }

However if I do not add the additional integer field, and just execute the query it runs OK.

Code: Select all

	UniQuery1->SQL->Clear();
	UniQuery1->SQL->Text = "select count(*) as rowcount from sqlite_master"

	UniQuery1->Execute();


	TField *f;
	for(int i=0; i<UniQuery1->FieldCount; i++)
	{
		f = UniQuery1->Fields->FieldByNumber(i+1);
	}
Obviously I need to provide a value for the id field in OnCalcfields - but there is something else I am doing wrong

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

Re: Problem adding calculated field to a query

Post by MaximG » Fri 30 Jun 2017 14:35

Thank you for the information. Unfortunately, we could not reproduce the problem according to the description. For further problem investigation, please compose and send us via the e-support form ( https://www.devart.com menu "Support"\"Request Support" ) a small complete sample, execution of which causes the problem. In addition, we will need SQLite DB used in this sample.

sandy771
Posts: 194
Joined: Tue 22 May 2007 13:57

Re: Problem adding calculated field to a query

Post by sandy771 » Mon 03 Jul 2017 08:44

Hi Maxim

Thank You

I have sent a sample simple project via the link (and sent the same by email on Friday afternoon last week).

Please let me know if there is anything else I can do

Paul

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

Re: Problem adding calculated field to a query

Post by MaximG » Mon 03 Jul 2017 14:20

Thank you for the information, we received your sample and reproduced the described error. The difference in the behavior of UniDAC when using the CreateField method and without it is explained by the peculiarities of using SQLite database. In the first case, when working with the CreateField method and before opening a query, SQLite cannot determine the type of the ROWCOUNT field. Therefore, in this case, UniDAC will create such a field as TMemoField, what leads to a further error in your code. In the second case, the ROWCOUNT field will be represented as TLargeIntField, which is the correct behavior. We will fix UniDAC behavior and let you know about the results in the near future.

sandy771
Posts: 194
Joined: Tue 22 May 2007 13:57

Re: Problem adding calculated field to a query

Post by sandy771 » Tue 04 Jul 2017 09:24

Thank You Maxim

I look forward to receiving a fix

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

Re: Problem adding calculated field to a query

Post by MaximG » Tue 04 Jul 2017 15:00

Thank you for the information. We have reproduced the problem and fixed the bug. The fix will be included in the next UniDAC build. Currently, we can send you a night build of UniDAC with the fix. For this, please specify your license number and and the exact version of RAD Studio you are using via the e-support form ( https://www.devart.com menu "Support"\"Request Support" )

sandy771
Posts: 194
Joined: Tue 22 May 2007 13:57

Re: Problem adding calculated field to a query

Post by sandy771 » Tue 04 Jul 2017 15:10

Hi Maxim

Thank You for fixing this so promptly.

I have provided the details asked for via the support link.

Cheers

sandy771
Posts: 194
Joined: Tue 22 May 2007 13:57

Re: Problem adding calculated field to a query

Post by sandy771 » Wed 05 Jul 2017 08:29

Hi Maxim

I filled in the form yesterday as requested, but have not received the night build yet. How do I get this?

The next stage of my development requires this fix so everything is on hold here :(

Cheers
Paul

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

Re: Problem adding calculated field to a query

Post by MaximG » Wed 05 Jul 2017 11:38

The links to download UniDAC night build with the made fixes were sent to your email

sandy771
Posts: 194
Joined: Tue 22 May 2007 13:57

Re: Problem adding calculated field to a query

Post by sandy771 » Wed 05 Jul 2017 11:49

Thank you - got the email an hour ago

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

Re: Problem adding calculated field to a query

Post by MaximG » Mon 10 Jul 2017 12:41

Please specify whether the described problem is reproduced or not when using the sent night build

sandy771
Posts: 194
Joined: Tue 22 May 2007 13:57

Re: Problem adding calculated field to a query

Post by sandy771 » Mon 10 Jul 2017 13:13

All seems OK now thank you.

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

Re: Problem adding calculated field to a query

Post by MaximG » Mon 10 Jul 2017 14:56

We are glad to see the problem resolved. Please don't hesitate to contact us with questions concerning UniDAC usage.

Post Reply