Here is my attempt to make a multi row INSERT. It’s actually much simpler than it would have been with db.runUpdateQuery. Here is a portion of the gateway event, tag change script. Note: “writeSize” can vary between 100 and 500, depending on the number of samples recorded by the PLC on each part.
# contruct database query strings
sqlString1 = "INSERT INTO data (timeVal, PromessPosition, promessForce, Temp0, Temp1, Temp2, Temp3, Temp4, Force0, Force1, Force2, Force3, Force4) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)"
sqlString2 = []
for i in range(0, writeSize):
j = (i*5)
myList = [timeList[i], promPosList[i], promForceList[i],tempList[j],tempList[j+1],tempList[j+2],tempList[j+3],tempList[j+4],forceList[j],forceList[j+1],forceList[j+2],forceList[j+3],forceList[j+4]]
sqlString2.append(myList)
# DB Insert call
system.db.runPrepUpdate(sqlString1,sqlString2)
but for simplicity, I’ve sterilized it a little bit
# contruct database query strings
sqlString1 = "INSERT INTO data (col1, col2, col3, col4, col5, col6, col7, col8, col9, col10) VALUES (?,?,?,?,?,?,?,?,?,?)"
sqlString2 = []
for i in range(0, writeSize):
myList = [val1List[i],val2List[i],val3List[i],val4List[i],val5List[i],val6List[i],val7List[i],val8List[i],val9List[i],val10List[i]]
sqlString2.append(myList)
# DB Insert call
system.db.runPrepUpdate(sqlString1,sqlString2)
Can I use this “sqlString2.append()” and insert it right into db.runPrepUpdate() like this?