SQLite Forum

C/C++ API: Is it posiible to clone database connection?
Login
As I understand, the WAL mode is used to readers do not block writers and a writer does not block readers. My case may be limited to readers.

Let's assume we have a long time query e.g.
```
WITH RECURSIVE t(x) AS (SELECT 1 UNION ALL SELECT x+1 FROM t LIMIT 10000),
t2(x) as (select x from t order by random())
select avg(t.x * t2.x) from t, t2 order by random()
```
This statement is executed by typical calls
```
sqlite3_prepare_v2(...)
while (SQLITE_ROW == sqlite3_step(stmt)) { ... }
sqlie3_finalize(stmt);
```
There are 3 threading modes: Single-thread, Serialized and Multi-thread.<br>

If steps running in main loop (main thread) in single thread mode, they will stop GUI. <br>The simpest way to stay GUI responsible is to use [progress handler](https://www.sqlite.org/c3ref/progress_handler.html).<br>But in the single thread I can't run an another query in parallel.

I can use Serialized mode: use one database connection and a separate thread per query.<br>But there are two problems:
 
1. Queries will be running in sequental mode - one by one.
2. An interrupt operation will be terminate all executing/planned queries.

So I come to multi-thread mode.<br>But there is problem with the synchronization of connection configs (they all should be same).