Removed redundant code in database layer and merge EscapeCharacters function with ToSqlFormat.