...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
<Query> <DeleteAll> <VendorInfo> <vendorName eq="Phidget"/> </VendorInfo> </DeleteAll> </Query> |
DataModel with one Complex type.
...
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.
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
<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.
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
<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> |
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
<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> |
Finally to View the file:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
http://<ip>:<port>/fid-tqlengineres/<nameoffile> |