Several processes writing to an SQLite database at the same time

I have several bash scripts that write to an SQLite3 database at the same time. At some occasion the database returns: SQL error: database is locked.

How would be the best way, to make a process to wait until the data base is 'free' again. I tried:

sqlite3 test.db ".timeout 1000; update....." but it didn't work.

Any ideas, hints would be greatly be appreciated.

Thanks.

I've barely touched sqlite, but if it either

  • succeeds and returns 0 or
  • makes no change at all and returns an error code
    (as I would hope it would), you might try something like this.
while ! sqlite3 ... ; do
    sleep 1
done
1 Like

Thanks a lot, that works perfect.