Improve sql string literal escaping

Related to #630