1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-30 06:01:00 +01:00
nix/src/libstore/sqlite-impl.hh
John Ericson 05ec0beb40 Move templated functions to sqlite-impl.hh
This ensures that use-sites properly trigger new monomorphisations on
one hand, and on the other hand keeps the main `sqlite.hh` clean and
interface-only. I think that is good practice in general, but in this
situation in particular we do indeed have `sqlite.hh` users that don't
need the `throw_` function.
2022-04-20 16:57:06 +00:00

42 lines
1.2 KiB
C++

#include "sqlite.hh"
#include "globals.hh"
#include "util.hh"
#include <sqlite3.h>
#include <atomic>
namespace nix {
template<typename... Args>
SQLiteError::SQLiteError(const char *path, int errNo, int extendedErrNo, const Args & ... args)
: Error(""), path(path), errNo(errNo), extendedErrNo(extendedErrNo)
{
auto hf = hintfmt(args...);
err.msg = hintfmt("%s: %s (in '%s')",
normaltxt(hf.str()),
sqlite3_errstr(extendedErrNo),
path ? path : "(in-memory)");
}
template<typename... Args>
[[noreturn]] void SQLiteError::throw_(sqlite3 * db, const std::string & fs, const Args & ... args)
{
int err = sqlite3_errcode(db);
int exterr = sqlite3_extended_errcode(db);
auto path = sqlite3_db_filename(db, nullptr);
if (err == SQLITE_BUSY || err == SQLITE_PROTOCOL) {
auto exp = SQLiteBusy(path, err, exterr, fs, args...);
exp.err.msg = hintfmt(
err == SQLITE_PROTOCOL
? "SQLite database '%s' is busy (SQLITE_PROTOCOL)"
: "SQLite database '%s' is busy",
path ? path : "(in-memory)");
throw exp;
} else
throw SQLiteError(path, err, exterr, fs, args...);
}
}