-- handle changes in data_state. Used for the modes tocleanedimfile and topurgedimfile
-- args are new data_state, chip_id, class_id, and current expected state for chipRun
UPDATE chipProcessedImfile
    SET 
    data_state = '%s'
WHERE
    chip_id = %lld
    AND class_id = '%s'
    -- only update if chipRun.state has the expected value
    AND (
        SELECT state from chipRun where chipRun.chip_id = chipProcessedImfile.chip_id
    ) = '%s'
    

