sqldb and threads lazarus / 16-Databases ---------------------------------------------------------------------- Max V. Terentiev · 2017-06-28 12:29 Hi, I need to read/write SQLite database from several threads. Should I create TSQLite3Connection in each thread ? Or I can use single connection in many threads ? Should I use CriticalSections in this case ? Thanks for help ! ---------------------------------------------------------------------- Blestan · 2017-06-28 14:21 not all functions of sqlite are thread safe .... create several connections in a pool and use them in the threads... do not use critical sections on one connection because if the app is heavely db active you will loose the advantages of multithreading ... one possible solutions is to serialize the access to sqlite in one thread and use a event mechanisme to signal the threads that the db operations are executed ... ---------------------------------------------------------------------- Max V. Terentiev · 2017-06-28 15:23 Sqlite have different compile-time threading options, including serialized where one connection can be shared betweern threads and multithreaded where each thread must have own connection. But what about sqldb ? Is it threadsafe ? ---------------------------------------------------------------------- Blestan · 2017-06-28 16:46 no idea about sdldb... why not use raw sqlite.dll? you can take a look at rqlite witch is a distribited sqlite and acess i rest based ---------------------------------------------------------------------- Leledumbo · 2017-06-30 20:57 Quote from: Max V. Terentiev on June 28, 2017, 05:23:01 pmBut what about sqldb ? Is it threadsafe ? AFAIK it just relies on the underlying DBMS. ---------------------------------------------------------------------- taazz · 2017-06-30 21:16 Quote from: Leledumbo on June 30, 2017, 10:57:58 pmQuote from: Max V. Terentiev on June 28, 2017, 05:23:01 pmBut what about sqldb ? Is it threadsafe ? AFAIK it just relies on the underlying DBMS. That is not enough. For example lcl relies on the underline widgetset as well but it is not thread safe, even when the underline widgetset is. ---------------------------------------------------------------------- Max V. Terentiev · 2017-07-03 12:15 But in the end. Should I create should I create TSQLite3Connection in each thread ? Or I can use (in threads) single connection from main DataModule ? ---------------------------------------------------------------------- mangakissa · 2017-07-04 06:26 You have to create TSQLite3Connection in each thread. But be carefull. As I mentioned earlier, I don't know is the database will be locked for another transaction is the database is opened. ---------------------------------------------------------------------- Max V. Terentiev · 2017-07-06 11:22 Thanks for help !