I have a question about dynamic binding tags in table.
I have table with columns:
TagName, Description, EngUnits.
What i want:
execute SQL query, get tagname, description, enguints and get current values of tags using binding by tagname (system.tag.read ()).
I have at the moment next results:
Execute SQL query, get TagName, get current values using tagName
Execute SQL query, get values from table by TagName
but i can not combine this queries and display their in one Table.
And another question:
how i can convert system.db.runQuery result to dataset?
#clear table
myTable=event.source.parent.getComponent('Table')
header = ['id','TagName','Description','EU','Type','Value']
row = []
data = system.dataset.toDataSet(header,row)
myTable.data = data
#execute SQL query
query = system.db.runPrepQuery("SELECT * FROM sunst.points_list")
query_ds=system.dataset.toDataSet(query)
#get values from dataset
for row in range(query_ds.rowCount):
id=query_ds.getValueAt(row,"id")
tagname=query_ds.getValueAt(row,"TagName")
description=query_ds.getValueAt(row,"Description")
eu=query_ds.getValueAt(row,"EU")
type=query_ds.getValueAt(row,"Type")
#get current tag value
value=system.tag.read(tagname)
#create new row
newRow=[id,tagname,description,eu,type,value.value]
#add this new row
data=system.dataset.addRow(data,newRow)
#show data
myTable.data = data
[code]tagPathsToRead = [] #get values from dataset
for row in range(query_ds.rowCount):
id=query_ds.getValueAt(row,“id”)
tagname=query_ds.getValueAt(row,“TagName”)
description=query_ds.getValueAt(row,“Description”)
eu=query_ds.getValueAt(row,“EU”)
type=query_ds.getValueAt(row,“Type”)
Add the tagpath to the list
tagPathsToRead.append(tagname) #create new row
newRow=[id,tagname,description,eu,type,None] #add this new row
data=system.dataset.addRow(data,newRow)
tagValues = system.tag.readAll(tagPathsToRead)
for row in range(query_ds.rowCount):
data = system.dataset.updateRow(data,row,{“Value”:tagValues[row].value})[/code]
[quote=“StepanenkoPaul”]I think I solved the problem[/quote]You could simplify this considerably if you used the PyDataSet as intended, in addition to using system.tag.readAll() to get the values in bulk:myTable=event.source.parent.getComponent('Table')
header = ['id','TagName','Description','EU','Type','Value']
newRows = []
query = system.db.runPrepQuery("SELECT * FROM sunst.points_list")
tagNames = [row['TagName'] for row in query]
values = system.tag.readAll(tagNames)
for row, value in zip(query, values):
newRow = [row['id'], row['TagName'], row['Description'], row['EU'], row['Type'], value.value]
newRows.append(newRow)
myTable.data = system.dataset.toDataSet(header, newRows)