Write From Translator Script
Contents
The code below looks for any queued messages in the NHCCVIS table (status = “W”), and pushes their MESSAGE_IDs onto the Iguana queue. After each MESSAGE_ID is queued the UPDATE statement changes the status flag of each entry (to “R” for read).
Note: The code below replaces the code from the previous step.
The UPDATE operation is intentionally not executed within the editor. This is because the conn:execute()
statement defaults to live = false
, so the database is not updated. The channel will need to be run to execute the UPDATE operation and push the data into the iguana queue.
Note: The Iguana queue is not active in the editor (test mode). Data is only pushed into the queue when the channel is run.
Here’s the code in a format you can copy:
local conn = db.connect{ api=db.SQLITE, name='test', live=true } function main() local R = conn:query( "SELECT MESSAGE_ID FROM NHCCVIS WHERE STATUS = 'W'" ) for i=1, #R do PushId(R[i].MESSAGE_ID:nodeValue()) conn:execute( "UPDATE NHCCVIS SET STATUS='R' WHERE MESSAGE_ID = " ..R[i].MESSAGE_ID ) end end function PushId(Id) queue.push{data=Id} end
Next Step?
Now we have written our From Translator script to queue the messages that need to processed. The next step is to run the channel to insert some MESSAGE_IDs into the queue, then we can use these as sample data.