I am testing at Table addColumn .
it is ok that adding constant data but if the added data is from select query, the ignition V7.9.1 show fault.
Please see code below.
sorry for confusing you, i just want to add one column to a table, and the column data is from select query ,the result of select query also is a column same rows
the code is below:
ds1 =event.source.parent.getComponent(‘Chart 1’).Data
colCount = ds1.getColumnCount()
columnName = “zone2”
results = system.db.runPrepQuery(“SELECT zonetopctrtc FROM blocktable WHERE block_id = ?”,[15974] ,“SQLServer”)
columnData = []
for i in range(ds1.getRowCount()):
oneColumn =[“Column %d” % i,i+19]
columnData.append(oneColumn)
ds2 = system.dataset.addColumn(ds1, colCount, columnData, columnName, int)
event.source.Data = ds2
All right. What is happening is that a database query returns a PyDataSet. This isn’t the same thing as a DataSet. You will need to iterate through the PyDataSet to get your query results into a list that you can use in the addColumn function.
ds1 =event.source.parent.getComponent('Chart 1').Data
colCount = ds1.getColumnCount()
columnName = "zone2"
results = system.db.runPrepQuery("SELECT zonetopctrtc FROM blocktable WHERE block_id = ?",[15974] ,"SQLServer")
columnData = []
for row in results:
columnData.append(row[0])
ds2 = system.dataset.addColumn(ds1, colCount, columnData, columnName, int)
event.source.Data = ds2