SQLite Forum

C/C++ API: Is it posiible to clone database connection?
Will you please stop "editing" your post(s) just to change the timestamp? It is annoying and time-wasting.

If you have something substantive to add, add it as another post. And if you believe, after a reasonable period of time has passed, that the thread deserves more attention that it is getting, maybe then add something calculated to improve prospects for an answer.

Your dummy, no-real-changes editing makes me want to just block you. It is like a child crowding between a group of other children and an attention-giving adult.

BTW, there is no API for cloning a connection. You need to simply use the multi-threading capability (such as it is) that SQLite already has. Even if you could get a cloned connection, it would perform no better in multi-thread scenarios. Critical database access must be serialized either way, either by the set of connection holders or the library itself. (See [Using SQLite In Multi-Threaded Applications](https://sqlite.org/threadsafe.html).) You should study [Write-Ahead Logging](https://sqlite.org/wal.html#concurrency) to see what can be done to assuage your performance concerns. Use of multiple connections to the same database is among the scenarios addressed there.

Because there are allocated resources associated with a connection, it is better to simply make additional connections to the same database if there will be different prepared statements in process. Those clones (if they existed), would have to be deep copies, little different from seemingly redundant connections unless the copies were made different by usage.

Your objective of getting "similar" connection "configuration" could be achieved by using common code to get connections to the configuration you want, and keeping them in a pool instead of tossing them as threads are done or die.

I would also suggest that you first find out how well use of simply redundant connections solves the problem that motivates your "clone" inquiry before getting to attached to that approach or disappointed that it is unsupported. The real problem is not management of data held by some sqlite3 struct(s); it is management of the resources referenced by the struct(s). Replication of the struct data is a side problem, more of a distraction than the real issue.