Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

To check if a query returns more Fields than when you created it and defined its persistent fields

When you have a select * from XXX query eventually you can get more fields than you expected, do you know if there is a way to check if new fields have been added since you created that query and defined its persistent fields ?.

Normally you can open your queries without having to worry if new fields have been added. If new fields are not within your persistent fields then you just won't see them. But on a Datasnap REST Server you get an AV when trying to return a Dataset from a query that now has more fields than when you created its persistent fields.

If would like to know if there is a quick check that I can do so I can return a more helpful error instead of an AV.

Something like :

MyQuery.Open;
if MyQuery.FieldDefs.Count <> MyQuery.Fields.Count then begin
  raise Exception.Create('The number of returned Fields doesn''t match the expected');
end;

Thank you

like image 849
Marc Guillot Avatar asked Oct 24 '16 12:10

Marc Guillot


People also ask

How can you check the performance of a query?

Use the Query Store page in SQL Server Management Studio In Object Explorer, right-click a database, and then select Properties. Requires at least version 16 of Management Studio. In the Database Properties dialog box, select the Query Store page. In the Operation Mode (Requested) box, select Read Write.

What happens when you run a query containing criteria for more than one field?

Multiple criteria in a single row When you use criteria for more than one field, and put them all in the Criteria row of the query grid, Access assumes that you mean to join them with AND. So a record must meet all criteria within that row in order to be displayed on the datasheet.

Which function do we use to return the number of fields in a query result?

You can count the number of items in a field (a column of values) by using the Count function.


1 Answers

If the dataset has persistent fields and you want those additional fields to be created when the query opens, you have to set dataset.FieldOptions.AutoCreateMode to acCombineAlways first.

Now after opening the query, you can check for the existance of additional fields with lcAutomatic in dataset.Fields.LifeCycles.

In case you are interested in which fields are new, just iterate dataset.Fields and check for field.LifeCycle = lcAutomatic.

BTW, using the setting above you probably might not need that check anymore.

like image 80
Uwe Raabe Avatar answered Oct 04 '22 02:10

Uwe Raabe