title: Failed to create SQLite3 database with file protection in iOS
body: <p><strong>Background:</strong> I have been watching through WWDC 2011 - 208 Securing iOS application. They mention about how to secure our data with file encryption called NSFileProtection. While I discover the <a href="https://devforums.apple.com/message/627887#627887" rel="noreferrer">automatic method mentioned (@38:00) is bugged</a>, I hope the manual way (@37:00) is not. I tried using file protection with images and all is well. Only Sqlite I cannot create.</p>
  
  <p><strong>Problem:</strong> I try to create SQLite3 database (without core data) with <code>sqlite3_open_v2</code> and passing <code>SQLITE_OPEN_FILEPROTECTION_COMPLETE</code>as the flag for the third argument. It does not return <code>SQLITE_OK</code>. </p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>if (sqlite3_open_v2([databasePath UTF8String], &amp;database, SQLITE_OPEN_FILEPROTECTION_COMPLETE, NULL) == SQLITE_OK){
     //everything works
  }else{
    //failed
  }
  </code></pre>
  
  <hr>
  
  <p><strong>Update:</strong><br>
  As borrrden mentioned, both has resulted in the following error code:
  <code>SQLITE_MISUSE</code> (Library used incorrectly) </p>
  
  <hr>
  
  <p><strong>Update 2:</strong>
  borrrden's 2nd comment was correct to point out the need for both flags. It works following the code:</p>
  
  <pre><code>if (sqlite3_open_v2([databasePath UTF8String], &amp;database, SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE|SQLITE_OPEN_FILEPROTECTION_COMPLETE, NULL) == SQLITE_OK)
  </code></pre>