title: How to wait until sqlite3 unlocks DB?
body: <p>I am using a one-line script calling the sqlite3 shell to update a value in a DB (this is on Windows 8.1 although that shouldn't matter here).</p>
  
  <p>The script simply reads:</p>
  
  <pre><code>sqlite3 &lt; update.sql
  </code></pre>
  
  <p>The update.sql-file contains:</p>
  
  <pre><code>.open "mydb.db"
  UPDATE &lt;args omitted for brevity&gt;;
  .save "mydb.db"
  .exit
  </code></pre>
  
  <p>i.e. it opens the DB (according to the sqlite3-help that means: reads it into memory), applies the update and then wants to save the modified DB back to disk again.</p>
  
  <p>But when I execute that script I get:</p>
  
  <pre><code>C:\&gt;sqlite3  0&lt;update.sql
  .open "mydb.db"
  UPDATE &lt;args omitted for brevity&gt;;
  .save "mydb.db"
  **Error: database is locked**
  .exit
  </code></pre>
  
  <p>The reason - as I found out by googling around - seems to be that the UPDATE is run in a background thread, which keeps the DB locked. That means, when the save-command tries to write the DB back to disk, the DB is still locked.</p>
  
  <p>I found no command in the sqlite3-shell to release that lock (or to wait until that lock gets released). So, what can I do to release that lock (or wait until it is released) and thus get this script to work properly?</p>
  
  <p>The absences of such a command and thus the inability to save a DB after applying some modifications seems to make the sqlite3 shell utterly useless to me. I must be missing something fundamental here!?!</p>