How do I specify a timeout in sqlite3 from the command-line?

You can do this by using an init file.

init.sql (note that the timeout value is in milliseconds - 1 is rather short):

.timeout 1000

At the prompt:

$ sqlite3 -init init.sql outgoing.db "select * from edges where worker is not null;"
Loading resources from init.sql
# 1 second pause
Error: database is locked

With some shells (on Linux at least, not very portable), you can avoid the need for a proper file with process substitution if that's a problem:

$ sqlite3 -init <(echo .timeout 1000) your.db "your sql;"

The extra output line ("Loading resources from ...") doesn't get printed if the output is redirected to a file or pipe, or to the .output file if you specified one in your init file.


In the sqlite3 command-line tool, dot commands are not SQL commands, so you cannot mix them with queries in the same line (and you should not delimit them with a semicolon).

sqlite3 can read commands from its standard input, so you can simply use a here document to give it multiple lines:

$ sqlite3 outgoing.db <<EOF
.timeout 1000
select * from edges where worker is not null;
EOF

Just use:

$ sqlite3 -cmd ".timeout 1000" outgoing.db "SELECT * FROM edges"

Tags:

Sqlite