Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

Create Query:

Create DataModel Query
<Query>
  <Create>
    <VendorInfo>
      <vendorName>Phidget</vendorName>
      <vendorTitle>Sensor Provider</vendorTitle>
    </VendorInfo>
  </Create>
</Query>

Create Query Result:

Note that VendorSysId of type Sid is automatically generated without specifying the value in Create Query Statement.

Create DataModel Query Results
<Create Status="Success">
  <VendorInfo>
    <VendorSysId>KNTJ5MYXAAAAUAABA7EIY2FH</VendorSysId>
    <vendorName Status="Success+Created:1:1457715589911;" Value="Phidget"/>
    <vendorTitle Status="Success+Created:1:1457715589914;" Value="Sensor Provider"/>
  </VendorInfo>
</Create>

Find Query:

Find DataModel Query
<Query>
  <Find format="all">
    <VendorInfo>
      <vendorName eq="Phidget"/>
    </VendorInfo>
  </Find>
</Query>

Find Query Result:

Find DataModel Query Result
<Find Status="Success" Format="all">
  <Result>
    <VendorInfo QName="SimpleModel.MyModels.VendorInfo">
      <VendorSysId>KNRX3TBUAAAAUAABA4LIWHP2</VendorSysId>
      <vendorTitle Value="Sensor Company" Known="Sensor Company" Version="1" Timestamp="1457663102018" DateTime="2016-03-10 18:25:02.018" QName="SimpleModel.MyModels.VendorInfo.vendorTitle" FName="vendorTitle"/>
      <vendorName Value="Phidget" Known="Phidget" Version="1" Timestamp="1457663102004" DateTime="2016-03-10 18:25:02.004" QName="SimpleModel.MyModels.VendorInfo.vendorName" FName="vendorName"/>
    </VendorInfo>
  </Result>
</Find>

Update Query:

Update DataModel Query
<Query>
  <Find format="version">
    <VendorInfo>
      <vendorName eq="Phidget"/>
    </VendorInfo>
  </Find>
  <SetResponseData>
    <Key>Message.Value.Find.Result.VendorInfo.vendorName</Key>
    <Value>Phidget Inc</Value>
  </SetResponseData>
  <Update>
    <From>Result</From>
    <Include>$Response.Message.Value.Find</Include>
  </Update>
</Query>

Update Query Result:

Note that the Version number is incremented automatically if the update is successful.
Update DataModel Query
<Find Status="Success" Format="version">
  <Result>
    <VendorInfo>
      <VendorSysId>KNTMS6F7AAAAUAABA7SVACBP</VendorSysId>
      <vendorTitle Value="Sensor Provider" Version="1"/>
      <vendorName>Phidget Inc</vendorName>
    </VendorInfo>
  </Result>
</Find>
<Update Status="Success" Format="version">
  <VendorInfo>
    <VendorSysId>KNTMS6F7AAAAUAABA7SVACBP</VendorSysId>
    <vendorName Status="Success=Updated:2:1457718402256;" Value="Phidget Inc" Version="2"/>
    <vendorTitle Status="Success_NoAction:1:1457718393024;" Value="Sensor Provider" Version="1"/>
  </VendorInfo>
</Update>


Delete Query:

Delete DataModel Query
<Query>
  <DeleteAll>
    <VendorInfo>
      <vendorName eq="Phidget"/>
    </VendorInfo>
  </DeleteAll>
</Query>


DataModel with one Complex type

DataModel with one Complex Type
<Def Name="PostalAddress">
 <String Name="Street"/>
 <String Name="City"/>
 <String Name="Zipcode"/>
</Def>
<DataModel Name="VendorInfo">
  <Sid name="VendorSysId"/>
  <String name="vendorName"/>
  <String name="vendorTitle"/>
  <PostalAddress name="VendorAddress"/>
</DataModel>

DataModel with one Attribute that is of Array defined via Cardinality.


Save Query Results to a CSV

In some cases the user may want to save the query results to a CSV file. This can be achieved easily using 3 step process:

  • Find Data
  • Convert result to comma separated lines
  • Save the content
  • View the content

For example: Let's say you have a DataModel VendorInfo as defined below.

Sample project
<Namespace Name="SimpleModel">
  <Domain Name="MyModels">
    <DataModel Name="VendorInfo">
      <Sid name="VendorSysId"/>
      <String name="vName"/>
      <String name="vTitle"/>
      <String name="vLocation"/>
    </DataModel>
  </Domain>
</Namespace>

Generic Macro to Save File:

You can make is as part of your project.

Note the content has to be part of ProcessData.

Generic SaveFile Macro
<Macro Name="SaveFile">
  <Argument>
    <FilePath/>
  </Argument>
  <Result>
    <JexlScript>
      var file = "[:$Macro.Argument.FilePath:]";
      var data = sffContext.getProcessData(["toCSV","result"]);
      sffLog.info("Data" + data);
      sff:saveTxt("text", file, data);
      return null;
    </JexlScript>
  </Result>
</Macro>
FindConvertAndSave
<Query>
  <Find>
    <VendorInfo>
      <vName ne=""/>
    </VendorInfo>
  </Find>
  <SetProcessData key="toCSV.result" value="Name,Title,Location[:EOL:]"/>
  <For Each="val" In="Find.Result.VendorInfo">
    <SetProcessData key="toCSV.result" Value="[:$ProcessData.toCSV.result:][:$LocalData.val.vName:],[:$LocalData.val.vTitle:],[:$LocalData.val.vLocation:][:EOL:]"/>
  </For>
  <SaveFile>
    <FilePath>
      ./resources/querydata.csv
    </FilePath>
  </SaveFile>
</Query>
Save Query Output to a File
<Query>
  <Find>
    <VendorInfo>
      <vName ne=""/>
    </VendorInfo>
  </Find>
  <SetProcessData key="toCSV.result" value="Name,Title,Location[:EOL:]"/>
  <For Each="val" In="Find.Result.VendorInfo">
    <SetProcessData key="toCSV.result" Value="[:$ProcessData.toCSV.result:][:$LocalData.val.vName:],[:$LocalData.val.vTitle:],[:$LocalData.val.vLocation:][:EOL:]"/>
  </For>
  <SetLocalData key="FILE" value="#o'resources/querydata.csv'#"/>
  <Log>[:[:$LocalData.FILE:][:$ProcessData.toCSV.result:]:]</Log>
</Query>

Finally to View the file:

View OR Download File
http://<ip>:<port>/fid-tqlengineres/<nameoffile>
  • No labels