Change write query to INSERT...ON DUPLICATE KEY UPDATE.

The write query using REPLACE prevented having any table with a FK to the
session id column since REPLACE actually DELETE and then INSERT. This new
type of query will try to INSERT first and then UPDATE if there is a PK
violation. Making it possible to have a FK tied to the id column without
issues. Perfermance wise, this change is untested.