title: SQLite: How to repair a malformed database programmatically
body: <p>I'm using SQLite3 for an embedded project.
  I have to concurrent processes that access a sqlite database.</p>
  
  <p>First process will do insert in the db (approx 50 per second).
  And the second process will try to drop from the db (approx 100 per second).</p>
  
  <p>Basically, my first process will collect data from a network, and will store it in the database.
  The second one will pop from the database to send the data using GPRS connection.</p>
  
  <p>The reason why I try to pop 100 elements per second (whereas I only store 50 elements per second) is to catch up, in case of GPRS connectivity is lost.</p>
  
  <p>At a random moment, I get my database malformed :</p>
  
  <pre><code>sqlite&gt; pragma integrity_check;
  Error: database disk image is malformed
  </code></pre>
  
  <p>And my second process loops with this message :</p>
  
  <pre><code>Failed to get table: database disk image is malformed
  </code></pre>
  
  <p>Is there any way to programmatically cleanup the database in case it malformed ? My programs are written in C.</p>
  
  <p>Thanks for any help</p>