Fixed SQL syntax in various places, escaped quotes to fix syntax errors
Fix insert statments with empty table name
Escape single quotes in names