Better Sql / Some toon handling

Maintains current TID in db. Some other minor changes to the way SQL
commands are handled.