I want to insert the last row of a pydataset into an existing database. However, my current script adds the entire dataset each time it is executed. What modifications can I make to my script (below) to ensure only the last row of the dataset is inserted into the database table?
pydata = system.dataset.toPyDataSet(data) strQuery = "INSERT INTO Results (t_stamp, serial_numbers, avg) VALUES (?,?, ?)"
for row in pydata: t_stamp = row["Time Stamp"] serial_numbers = row["Serial Numbers"] avg = row["Ave"] args = [t_stamp, serial_numbers, avg] system.db.runPrepUpdate(strQuery, args)
Additional Information: To avoid
DUPLICATE KEY errors, I removed the
PRIMARY KEY from my
serial_number column. I would like to have a
PRIMARY KEY column either with an
AUTO-INCREMENT INDEX or my