SqlThreadConnection

Gives each store one SQLite connection per thread, with names that are never used again.

Group libsql

Declared in src/libs/libsql/sql/SqlThreadConnection.hpp.

Detailed description

A QSqlDatabase is usable only on the thread that created it. A store that is called from more than one thread thus needs one connection per thread. SpecStore found two ways to get this wrong, and this class holds the answer that SpecStore uses:

  • The name of a connection must not come from the address of the thread. The OPAL runtime makes a new QThread for each plan, and a new thread can get the address of a thread that has ended. It then finds a connection that a dead thread made, and a read does not see a write that committed.
  • The name must not come from the address of the store either. A test makes stores on the stack, and a new store can get the address of an old one, and with it the file of the old one.

So the store gets a base name with a number that the process never gives again (uniqueBase()), and each thread adds a token of its own, also never given again. A thread removes its connections when it ends.

The pragmas of each connection come from SqlTuning.

In this section