Vision: Convert dataset column type

Use Ignition’s DatasetBuilder. Something like this:

from com.inductiveautomation.ignition.common.util import DatasetBuilder
from java.lang import Integer, String, Object
from java.awt import Color

def forceTypes(sqlDS):
    builder = DatasetBuilder.newBuilder()
    builder.colNames(sqlDS.columnNames)
    originalTypes = list(sqlDS.columnTypes)
    i = #some column index for a color
    originalTypes[i] = Color
    builder.colTypes(originalTypes)
    for r in range(sqlDS.rowCount):
        builder.addRow([sqlDS.getValueAt(r, c) for c in range(sqlDS.columnCount)])
    return builder.build()
2 Likes