title: attempt at programmatic sqlite database repair
body: <p>I discovered that it's possible for an app's database to become corrupt when a user pulls the battery out of the phone. This results in :</p>
  <blockquote>
  <p>I/Database(1217): sqlite returned: error code = 14, msg = cannot open
  file at source line 25467</p>
  <p>E/Database(1217):
  sqlite3_open_v2(&quot;/data/data/com.myapp/databases/mydata.db&quot;, &amp;handle,
  6, NULL) failed</p>
  <p>W/dalvikvm(1217): Exception
  Landroid/database/sqlite/SQLiteException; thrown while initializing
  Lcom/myapp/database/SQLhelper;</p>
  <p>D/AndroidRuntime(1217): Shutting down
  VM</p>
  <p>W/dalvikvm(1217): threadid=1: thread exiting with uncaught
  exception (group=0x40015560)</p>
  </blockquote>
  <p><strong>Premise</strong></p>
  <p>I read that using .dump can recover userful data. So I took the following approach...</p>
  <p><strong>Execution</strong></p>
  <pre><code>final String strDBpath = Application.getContext().getDatabasePath(DB_NAME).getAbsolutePath();
  
  final File fDBsrc = new File(strDBpath);
  final File fDBtrgt = new File(strDBpath.replace(&quot;.db&quot;, &quot;new.db&quot;));
  
  final String strExeCmd = &quot;sqlite3 &quot;+fDBsrc+&quot; .dump | sqlite3 &quot;+fDBtrgt;
  
  boolean bSuccess = true;
  
  try
  {
      Log.i(TAG, &quot;executing &quot;+strExeCmd);
      Process process = Runtime.getRuntime().exec(strExeCmd);
      process.waitFor();
  } catch (Exception er)
  {
      bSuccess = false;
  }
  </code></pre>
  <p><strong>Result</strong>
  HOWEVER - listing the /data/data/com.myapp/databases did not reveal a new database.</p>
  <p>is this a permissions problem ?</p>