If you want to access individual elements like itâs a nested list, you need to change the Dataset returned by runNamedQuery into a PyDataset, via the appropriately named system.dataset.toPyDataset function. See the Datasets page for more background on the difference between the two: https://docs.inductiveautomation.com/display/DOC80/Datasets
So the named query executes the IN-LINE code and returns a pydataset but then the named query is converting it to a regular dataset? Thatâs mildly annoying to contemplate but thanks for the info.
Anyways I was able to fix my problem by converting the regular dataset back into a pydataset using the line:
for row in range( tbl.rowCount ):
keyId = tbl.getValueAt( row, 0 ) # better to use column names
someText = tbl.getValueAt( row, 1 ) # 2nd column
serialNum = tbl.getValueAt( row, 'SERIAL_NBR' ) # sample column name
# do your workload / logic here ...
That works with the dataset returned by the Named Query without duplicating all the data into another datatype.
You can use system.dataset.getColumnHeaders( tbl ) to get a List with the exact spelling and capitalization of the columns returned by the Named Query.
the toPyDataSet function solved my problem reading from a dataset returned from a named Query. Thank you very much for the post. #---------------------------------------------------------------------------------------------------------------- Preformatted text
parameters = {âLOT_NUMBERâ:(self.session.custom.strLotNumber)}
ds = system.db.runNamedQuery(ânq_spGetBrandâ, parameters)
pyDataSet = system.dataset.toPyDataSet(ds)
if pyDataSet.rowCount > 0:
strBrand = str(pyDataSet[0][âBRANDâ]) Preformatted text
When you configure a query binding there is an option to set the return format. By default this is set to auto.
If you wanting to do this in script then the type returned by system.db.runNamedQuery() is determined by the Query Type of the Named Query. If the Named Queries query type is set to query then the function will return a dataset.
This code wonât work yet but should get you pretty close. The named query returns a basic dataset so no need to convert it. Then add the column names for that dataset. Then pass it to the variable sp.