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

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

You can usually open your queries without worrying about adding new fields. If the new fields are not in your permanent fields, you simply will not see them. But on the DATASnap REST server, you get AV when you try to return a dataset from a query that now has more fields than when creating its constant fields.

If you want to know if there is a quick check, what can I do, I can return a more useful error instead of AV.

Sort of:

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; 

thanks

+5
source share
1 answer

If the dataset has constant fields and you want these additional fields to be created when you open the query, you must first set dataset.FieldOptions.AutoCreateMode to acCombineAlways .

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

If you are interested in which fields are new, just repeat dataset.Fields and check field.LifeCycle = lcAutomatic .

BTW, using the above setting, you may no longer need this check.

+6
source

Source: https://habr.com/ru/post/1258711/


All Articles