SQL fixes, prevents injection attacks.

Prevents clients from being able to do bad things with botched data. Still more to do, but this takes care of the worst of them.