SQLite Forum

cannot start a transaction within a transaction using sqlite shell
Login
I've tried this with multi-line statements as well:

window 1:
for n in `seq 1000000`; do echo -e "begin transaction;\ninsert into foo values($n);\nend;" ;done|sqlite3 test.db 

Window 2:
while ! sqlite3 test.db 'begin;select min(bar) from foo;end;'; do true ; done

The result is 

Error: database is locked
Error: database is locked
Error: database is locked
Error: database is locked
Error: database is locked
Error: database is locked
Error: database is locked
Error: database is locked
[...]
1

on the select side,
and on the insert side:
or n in `seq 1000000`; do echo -e "begin transaction;\ninsert into foo values($n);\nend;" ;done|sqlite3 test.db 

Error: near line 2640: database is locked
Error: near line 2641: cannot start a transaction within a transaction
Error: near line 2871: database is locked
Error: near line 2872: cannot start a transaction within a transaction
Error: near line 2874: database is locked
Error: near line 2875: cannot start a transaction within a transaction
Error: near line 2937: database is locked
Error: near line 2938: cannot start a transaction within a transaction
Error: near line 2940: database is locked
Error: near line 2941: cannot start a transaction within a transaction
Error: near line 2964: database is locked
Error: near line 2965: cannot start a transaction within a transaction
Error: near line 3114: database is locked
[...]

Even after the select transaction finishes, all further insert transactions fail.