mirror of
https://github.com/NixOS/nix.git
synced 2025-11-17 07:52:43 +01:00
sqlite.cc: Add SQL tracing
Set environment variable NIX_DEBUG_SQLITE_TRACES=1 to log all sql statements.
(cherry picked from commit 8a0ef5d58e)
This commit is contained in:
parent
b7166df536
commit
54ac8fa919
1 changed files with 14 additions and 0 deletions
|
|
@ -36,6 +36,15 @@ SQLiteError::SQLiteError(const char *path, int errNo, int extendedErrNo, hintfor
|
||||||
throw SQLiteError(path, err, exterr, std::move(hf));
|
throw SQLiteError(path, err, exterr, std::move(hf));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void traceSQL(void * x, const char * sql)
|
||||||
|
{
|
||||||
|
// wacky delimiters:
|
||||||
|
// so that we're quite unambiguous without escaping anything
|
||||||
|
// notice instead of trace:
|
||||||
|
// so that this can be enabled without getting the firehose in our face.
|
||||||
|
notice("SQL<[%1%]>", sql);
|
||||||
|
};
|
||||||
|
|
||||||
SQLite::SQLite(const Path & path, bool create)
|
SQLite::SQLite(const Path & path, bool create)
|
||||||
{
|
{
|
||||||
// useSQLiteWAL also indicates what virtual file system we need. Using
|
// useSQLiteWAL also indicates what virtual file system we need. Using
|
||||||
|
|
@ -49,6 +58,11 @@ SQLite::SQLite(const Path & path, bool create)
|
||||||
if (sqlite3_busy_timeout(db, 60 * 60 * 1000) != SQLITE_OK)
|
if (sqlite3_busy_timeout(db, 60 * 60 * 1000) != SQLITE_OK)
|
||||||
SQLiteError::throw_(db, "setting timeout");
|
SQLiteError::throw_(db, "setting timeout");
|
||||||
|
|
||||||
|
if (getEnv("NIX_DEBUG_SQLITE_TRACES") == "1") {
|
||||||
|
// To debug sqlite statements; trace all of them
|
||||||
|
sqlite3_trace(db, &traceSQL, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
exec("pragma foreign_keys = 1");
|
exec("pragma foreign_keys = 1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue