Still in dev for the script so alot of hardcoding that ill fix after it works.
getting this error, at a standstill on what to try next
def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
def populate_dbtable_from_pydataset(pds, dbTable, dbConn, maxRecs):
cols = pds.getColumnCount()
rows = pds.getRowCount()
#clear db table each time
queryStr = "TRUNCATE TABLE {:s}".format(dbTable)
system.db.runUpdateQuery(queryStr, dbConn)
# no inserts if no data
if (rows >0):
# set up insert query string
#pholders = "({:s})".format(",".join("?"*cols))
pholders = "({:s})".format("Seq_Number","Next_Seq_Number","External_Serialized","Manual_Process","Bypass_Task","BOM_PN,Deviation_PN","Deviation_Number","Deviation_Experation","Work_Instructions","Picture_Name","Tool","Job","PV1_Name","PV1_UL","PV1_LL","PV2_Name","PV2_UL","PV2_LL","PV3_Name","PV3_UL","PV3_LL","Doc_Name")
queryStr = "INSERT INTO {:s} VALUES {:s}".format(dbTable, "{pholders}")
# indices for first N records
minIdx = 0
maxIdx = maxRecs
# DB inserts in batches of N
while (maxIdx < rows):
queryArgs = []
queryData = []
for row in pds[minIdx:maxIdx]:
queryData.extend(row)
queryArgs.append(pholders)
#queryStr1 = queryStr.format(pholders=",".join(queryArgs))
queryStr1 = queryStr.format(pholders(queryArgs))
# insert N rows in DB
system.db.runPrepUpdate(queryStr1, queryData, dbConn)
#advance and leftover records
minIdx = rows
MaxIdx += maxRecs
# handle any leftover records
maxIdx = rows
queryArgs = []
queryData = []
for row in pds[minIdx:maxIdx]:
queryData.extend(row)
queryArgs.append(pholders)
queryStr2 = query.format(pholders=",".join(queryArgs))
# insert remaining rows into DB
system.db.runPrepUpdate(queryStr2, queryData, dbConn)
ds = system.tag.read("[.]MESv4_Data/500 WIs Dataset").value
pds = system.dataset.toPyDataSet(ds)
dbTable = "WI_Test3"
dbConn = "LOMESSQL01_BE35k"
maxRecs = 100
populate_dbtable_from_pydataset(pds, dbTable, dbConn, maxRecs)