Writing Variable Rows to DB

I have a process that requires me to be able to write between 1 to 15 new values to a database depending on what is happening. I was able to do this in a client, but I lost something when I tried to make it a gateway script and I can’t find the error in the wrapper.log to read what is happening. This is the script I was trying to use:

for j in range(scanned):
system.db.runPrepUpdate(“INSERT INTO Giveaway_10A (Bag_Weight, time_stamp) VALUES (?,?)”,[weight,time])

The formatting isn’t cooperating for me but the indentation in the for loop should be correct. I looked into doing this with block groups too but the rows I want to add aren’t guaranteed to change they could be the same value each time. Any ideas or questions?

Hi David,

The values variable is a list of tag values. But the loop is only getting the first item in the list (values[0]).

Perhaps replace values[0][j] with values[j].

It didn’t fix the problem, but it is possible there is more than one issue too. Thanks for the suggestion.

DavidKettle, try specifying the database connection a the third parameter:

for j in range(scanned): system.db.runPrepUpdate("INSERT INTO Giveaway_10A (Bag_Weight, time_stamp) VALUES (?,?)",[values[j],time], "yourDbConnectionName")

I specified the database and kept the change nmudge suggested as well and the script is working great so far.

Thanks both of you for your help!

Yayyy! Good team work :smiley: