开发者

sqlite multiple databases insert/update/delete

开发者 https://www.devze.com 2023-04-09 18:50 出处:网络
I was wondering how SQLite behaves when it\'s given multiple databases to insert/update/delete in at the same time? Does it spawn multiple processes which can in theory have better concurrency than us

I was wondering how SQLite behaves when it's given multiple databases to insert/update/delete in at the same time? Does it spawn multiple processes which can in theory have better concurrency than using a single database/single process or it utilizes the same process for each?

Searching through the documentation didn't provide e with a definitive answer. I a开发者_StackOverflowm aware that SQLite isn't the most ideal environment for multiple writes, as the database resides in as single file. But does that mean that multiple files = different write processes?

databaseOne = connectToSqlite('databaseOne'); 
databaseTwo = connectToSqlite('databaseTwo');
function write()
    queryDatabaseOne("INSERT SOMETHING INTO SOME_TABLE VALUES SOME_VALUES");
    queryDatabaseTwo("INSERT SOMETHING INTO SOME_TABLE VALUES SOME_VALUES");

So, two different sqlite databases, and two inserts executed in parallel, towards tables in the two databases.

Thanks


Normally, database queries are blocking - they do not return until they are complete. This helps secure the integrity of the database. The SQLITE API is blocking.

Of course, if you have a multiple databases, then you can write a multi-threaded application with non-blocking routines that call the the SQLITE API and then code overlapping, parallel inserts to the multiple databases. You will have to be careful about all the usual things in a multithreaded application - the SQLITE API will neither help not hinder - with added complication of insuring that there in no possibility of overlapping accesses to the SAME database.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号