title: When to check for database is locked errors in sqlite
body: <p>On the linux server, where our web app runs, we also have a small app that uses
  sqlite (it is written in c).</p>
  
  <p>For performing database actions we use the following commands:</p>
  
  <pre><code>sqlite3_prepare_v2
  sqlite3_bind_text or sqlite3_bind_int
  sqlite3_step
  sqlite3_finalize
  </code></pre>
  
  <p>Every now and then there was a concurrency situation and I got the following error:</p>
  
  <pre><code>database is locked
  </code></pre>
  
  <p>So I thought: "This happens when one process writes a certain record and the
  other one is trying to read exactly the same record."</p>
  
  <p>So after every step-command, where this collision could be, I checked for this error. When it happended, I waited a few milliseconds and the tried again.</p>
  
  <p>But the sqlite error "database is locked" still occurred. </p>
  
  <p>So I changed every step command and the code lines after it. Somehow I thought that this "database is locked" error could only occur with the step command.</p>
  
  <p>But the error kept coming. </p>
  
  <p>My question is now:</p>
  
  <p>Do I have to check after any sqlite3 command for "error_code ==5" (database is locked)?</p>
  
  <p>Thanks alot in advance</p>