<?xml version="1.0" encoding="UTF-8"?>
<post>
  <category-id type="integer" nil="true"></category-id>
  <comment-count type="integer">0</comment-count>
  <content>&lt;p&gt;Problem adding &quot;%&quot; inside your sql queries? read below.&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-family: Menlo, Arial, Helvetica, sans-serif; font-size: 11px; color: #e90000; &quot;&gt;&lt;span style=&quot;color: #d200a5&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #d200a5&quot;&gt;char&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; *sqlStatement = &lt;/span&gt;&quot;select fname,lname from students where lname like ?001 and fname like ?002&quot;&lt;span style=&quot;color: #000000&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;&lt;span style=&quot;font-family: Menlo, Arial, Helvetica, sans-serif; font-size: 11px;&quot;&gt;Notice that the parameter tokens, ?001 and ?002 do not have quotes around them.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style=&quot;font-family: Menlo, Arial, Helvetica, sans-serif; font-size: small;&quot;&gt;&lt;span style=&quot;font-size: 11px;&quot;&gt;This statement needs to be prepared in the usual way.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style=&quot;font-family: Menlo, Arial, Helvetica, sans-serif; font-size: small;&quot;&gt;&lt;span style=&quot;font-size: 11px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style=&quot;font-family: Menlo, Arial, Helvetica, sans-serif; font-size: small;&quot;&gt;&lt;span style=&quot;font-size: 11px;&quot;&gt;
&lt;script src=&quot;../../javascripts/tiny_mce/themes/advanced/langs/en.js?1249362019&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo&quot;&gt;&lt;span style=&quot;color: #7e11ad&quot;&gt;NSString&lt;/span&gt; *fnameSearch = [&lt;span style=&quot;color: #7e11ad&quot;&gt;NSString&lt;/span&gt; &lt;span style=&quot;color: #480085&quot;&gt;stringWithFormat&lt;/span&gt;:&lt;span style=&quot;color: #e90000&quot;&gt;@&quot;%%%@%%&quot;&lt;/span&gt;, &lt;span style=&quot;color: #368288;&quot;&gt;fnameSearchWord&lt;/span&gt;];&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo&quot;&gt;&lt;span style=&quot;color: #7e11ad&quot;&gt;NSString&lt;/span&gt;&amp;nbsp;*lnameSearch = [&lt;span style=&quot;color: #7e11ad&quot;&gt;NSString&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #480085&quot;&gt;stringWithFormat&lt;/span&gt;:&lt;span style=&quot;color: #e90000&quot;&gt;@&quot;%%%@%%&quot;&lt;/span&gt;, &lt;span style=&quot;color: #368288;&quot;&gt;lnameSearchWord&lt;/span&gt;];&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;div&gt;&lt;span style=&quot;font-family: Verdana, Arial, Helvetica, sans-serif; font-size: x-small;&quot;&gt;&lt;span style=&quot;font-size: 10px; &quot;&gt;&lt;span style=&quot;font-family: Menlo, Arial, Helvetica, sans-serif; font-size: small;&quot;&gt;&lt;span style=&quot;font-size: 11px;&quot;&gt;Notice the %% characters in the format string. This results in one % in the output string. &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style=&quot;font-family: Verdana, Arial, Helvetica, sans-serif; font-size: x-small;&quot;&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;&lt;span style=&quot;font-family: Menlo, Arial, Helvetica, sans-serif; font-size: small;&quot;&gt;&lt;span style=&quot;font-size: 11px;&quot;&gt;%@ is the replacement token for your string parameter. &amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style=&quot;font-family: Verdana, Arial, Helvetica, sans-serif; font-size: x-small;&quot;&gt;&lt;span style=&quot;font-size: 10px;&quot;&gt;&lt;span style=&quot;font-family: Menlo, Arial, Helvetica, sans-serif; font-size: small;&quot;&gt;&lt;span style=&quot;font-size: 11px;&quot;&gt;Finally, you have to bind your strings to the prepared statement like this:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;span style=&quot;color: #7e11ad;&quot;&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo&quot;&gt;&lt;span style=&quot;color: #7e11ad&quot;&gt;sqlite3_stmt&lt;/span&gt; *compiledStatement;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo&quot;&gt;&lt;span style=&quot;color: #d200a5&quot;&gt;if&lt;/span&gt;(&lt;span style=&quot;color: #480085&quot;&gt;sqlite3_prepare_v2&lt;/span&gt;(database, sqlStatement, -&lt;span style=&quot;color: #3900de&quot;&gt;1&lt;/span&gt;, &amp;amp;compiledStatement, &lt;span style=&quot;color: #d200a5&quot;&gt;NULL&lt;/span&gt;) == &lt;span style=&quot;color: #824725&quot;&gt;SQLITE_OK&lt;/span&gt;)&amp;nbsp;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;{&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo&quot;&gt;&lt;span style=&quot;color: #008d00;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #000000; &quot;&gt;&lt;span style=&quot;color: #480085&quot;&gt;sqlite3_bind_text&lt;/span&gt;(&lt;span style=&quot;color: #368288;&quot;&gt;compiledStatement&lt;/span&gt;, &lt;span style=&quot;color: #3900de&quot;&gt;1&lt;/span&gt;, [&lt;span style=&quot;color: #368288;&quot;&gt;fnameSearchWord&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #480085&quot;&gt;UTF8String&lt;/span&gt;], -&lt;span style=&quot;color: #3900de&quot;&gt;1&lt;/span&gt;, &lt;span style=&quot;color: #824725&quot;&gt;SQLITE_STATIC&lt;/span&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo&quot;&gt;&lt;span style=&quot;color: #008d00;&quot;&gt;&lt;span style=&quot;color: #000000; &quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #480085&quot;&gt;sqlite3_bind_text&lt;/span&gt;(&lt;span style=&quot;color: #368288;&quot;&gt;compiledStatement&lt;/span&gt;, &lt;span style=&quot;color: #3900de;&quot;&gt;2&lt;/span&gt;, [&lt;span style=&quot;color: #368288;&quot;&gt;lnameSearchWord&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #480085&quot;&gt;UTF8String&lt;/span&gt;], -&lt;span style=&quot;color: #3900de&quot;&gt;1&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color: #824725&quot;&gt;SQLITE_STATIC&lt;/span&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo&quot;&gt;&lt;span style=&quot;color: #008d00;&quot;&gt;&lt;span style=&quot;color: #000000; &quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;&quot;&gt;&lt;span style=&quot;color: #d200a5;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;while&lt;/span&gt;(&lt;span style=&quot;color: #480085;&quot;&gt;sqlite3_step&lt;/span&gt;(compiledStatement) == &lt;span style=&quot;color: #824725;&quot;&gt;SQLITE_ROW&lt;/span&gt;)&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;span style=&quot;color: #000000; white-space: normal;&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;// continue data manipulation here.&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;&quot;&gt;&amp;nbsp;&lt;span style=&quot;color: #000000;&quot;&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo;&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;</content>
  <created-at type="datetime">2009-11-19T10:25:37+08:00</created-at>
  <id type="integer">11</id>
  <permalink>escaping-sqlite-string-in-obj-c</permalink>
  <published type="boolean" nil="true"></published>
  <title>Escaping sqlite string in obj-c</title>
  <updated-at type="datetime">2009-11-19T10:30:14+08:00</updated-at>
</post>
