Switch to REPLACE for SQL record creation; refactor logging