title: How to prepare a C++ string for sql query
body: <p>I have to prepare strings to be suitable for queries because these strings will be used in the queries as field values. if they contain a ' etc the sql query fails to execute.</p>
  
  <p>I therefore want to replace ' with '' I have seen the code to find and replace a substring with a substring. but I guess the problem is a little tricky because replacing string also contains two single quotes '' replacing one quote '  so when I have to find the next occurance it would encounter a ' which was intentionally replaced.</p>
  
  <p>I am using Sql lite C api and the example query might look like this</p>
  
  <pre><code> select * from persons where name  = 'John' D'oe'
  </code></pre>
  
  <p>Since John Doe contain a ' the query will fail , so I want all occurances of ' in the name to replaced with ''</p>
  
  <p>Any ideas how you guys prepares your field values in query to be used in sql ??? may be it's a basic thing but I am not too smart in C/C++.</p>
  
  <p>your help would be very helpful </p>