Recent

Author Topic: fpjsondataset - Property MetaData - Can be set directly  (Read 1776 times)

PaulANormanNZ

  • Full Member
  • ***
  • Posts: 117
fpjsondataset - Property MetaData - Can be set directly
« on: June 28, 2018, 01:00:34 pm »
HI,

Inside the unit it says that:-

Quote
Property MetaData;
    // Can be set directly if the dataset is closed. If metadata is set, it must match the data.
   
I am wanting to load the metaData from a stored version of a file,

Code: Pascal  [Select][+][-]
  1.  Const_btabb_template_jsonObj := getJSON(str_btabb_io_ver_0002.Strings.Text);
  2.  
  3.     Const_btabb_tamplate_metadata := TJSONObject(
  4.           Const_btabb_template_jsonObj.FindPath('metaData')
  5.           );  
  6.  

This metaData is always a safe SuperSet or equal to  whatever is in the data file.

I wish to use this to cause the fields list to represent the most up todate version of the metaData, so that when data is saved back out onto disk, it has that incorporated - allowing for automatic updating of older files - should they be opened/ then saved.

I want to apply this after an individual data JSON file (which has possibly older metaData in it) has loaded...

Code: Pascal  [Select][+][-]
  1.       FDataset.Close;
  2.  
  3.         FDataset.LoadFromFile(filename);
  4.  
  5.   // is this the correct way? ...
  6.           fDataset.MetaData := Const_btabb_tamplate_metadata;    
  7.  
  8.        FDataset.Open;
  9.  
  10.      global_FileName := filename;    
  11.  

While debugging it works fine the first time, but done again (immediately open even the same file without saving) throws a couple of these  errors:

exception class 'External SIGSEGV'

At Address 1000E0316


and then

Access Violation

TIA
Paul

PaulANormanNZ

  • Full Member
  • ***
  • Posts: 117
Re: fpjsondataset - Property MetaData - Can be set directly
« Reply #1 on: June 29, 2018, 07:30:52 am »
Ok, it looks like there were two things happening at once here.

1. The extreme User case where the JSON document's metaData.fields array is actually empty.

Where the array is empty it seems in FP you can not test on myJsonArray.count expecting 0

2. and the inappropriateness of direct assignment of the metaData TJSONObject

It'd work the first time, but when the dataset changes upon opening another JSON document, this will be nulled it seems; so the second use of it in a session will fail.
Maybe it is for scope, or some other reason - I do not yet grasp the underlying "wiring" of the JSON dataset. Whatever I must have been assuming the object was being shared by Value when it appears to actually be passed by Reference equivalence.

So I am testing the following, and so far it seems stable.
It copes with an old JSON document where any field is missing in metaData.fields, and the extreme User case where for some reason, there are no fields at all, and it avoids direct assignment of the JSON object...

Code: Pascal  [Select][+][-]
  1.  
  2.    if (dataset_fields_Array.IsNull = true)
  3.       or
  4.        (dataset_fields_Array.Count
  5.              <>   Const_btabb_tamplate_metadata_fields.Count) then
  6.  
  7.        fDataset.MetaData := GetJSON(Const_btabb_tamplate_metadata.AsJSON,true)
  8.                                   as TJSONObject;    
  9.  

Any thoughts - anything else I should be aware of please?

Paul
« Last Edit: June 29, 2018, 08:30:58 am by PaulANormanNZ »

 

TinyPortal © 2005-2018