Just assume that I have no control of creating the query string, for example,
select * from customer where name='Joe's construction'
Also, there isn't any control of executing the query, for example, pass this to a REST API to execute on a database.
I need to escape the query as
select * from customer where name='Joe\'s construction'
So I need to write a function like this:
string escape(string sql)
The function pass the origin query and return the escaped string, so it can use the function like this:
string s = "select * from customer where name='Joe's construction'";
string es = escape(s);
// 'es' should equals "select * from customer where name='Joe\'s construction'"
How can I make this function escape work?
Again, I have no control of creating that SQL query. I am only able to get the query string as a whole piece. And I am not using it to execute on any database; I just need to escape it and pass to an API.