Changed write() to perform an insert on duplicate key update query, as it was possible to update before and have nothing change, so we could not tell it apart from the case when the session had not been created.