Update sql logic to update instead of insert

Before it would do an INSERT OR REPLACE which would set other values to
their defaults.  There's various "UPSERT" methods I found but it's
easier to just do the update and if no rows were updated then insert the
row and do the update again.  Need to work on cleaning up the logic
though.