Search code examples
c++performancesqlitec-preprocessorpragma

Should I use pragmas or preprocessor macros in SQLite3?


Is there a performance difference in SQLite3 whether I use PRAGMAs or preprocessor macros?

In my case, I wonder whether there is any difference between PRAGMA foreign_keys = ON and #define SQLITE_DEFAULT_FOREIGN_KEYS=1 regarding behavior or performance.

I tend to use the pragma to be more flexible, but I wonder whether there is some performance loss.

Additional question: Is it correct that the pragma applies to the connected database. Can there be race conditions if multiple processes/threads access the same database and set a pragma? I assume that the pragma information is stored in the sqlite3 file on the hard disk.


Solution

  • There is no speed difference between the PRAGMA and the default setting.

    This setting applies not to the database but to a database connection, so multiple connections cannot affect each other.