Better sql string handling

and a space in gettempo