mirror of
https://github.com/NixOS/nix
synced 2025-06-26 20:01:15 +02:00
Misc changes from the flakes branch
This commit is contained in:
parent
c85097da7c
commit
0a10854f85
22 changed files with 110 additions and 60 deletions
|
@ -25,11 +25,16 @@ namespace nix {
|
|||
throw SQLiteError("%s: %s (in '%s')", fs.s, sqlite3_errstr(exterr), path);
|
||||
}
|
||||
|
||||
SQLite::SQLite(const Path & path)
|
||||
SQLite::SQLite(const Path & path, bool create)
|
||||
{
|
||||
if (sqlite3_open_v2(path.c_str(), &db,
|
||||
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, 0) != SQLITE_OK)
|
||||
SQLITE_OPEN_READWRITE | (create ? SQLITE_OPEN_CREATE : 0), 0) != SQLITE_OK)
|
||||
throw Error(format("cannot open SQLite database '%s'") % path);
|
||||
|
||||
if (sqlite3_busy_timeout(db, 60 * 60 * 1000) != SQLITE_OK)
|
||||
throwSQLiteError(db, "setting timeout");
|
||||
|
||||
exec("pragma foreign_keys = 1");
|
||||
}
|
||||
|
||||
SQLite::~SQLite()
|
||||
|
@ -42,6 +47,12 @@ SQLite::~SQLite()
|
|||
}
|
||||
}
|
||||
|
||||
void SQLite::isCache()
|
||||
{
|
||||
exec("pragma synchronous = off");
|
||||
exec("pragma main.journal_mode = truncate");
|
||||
}
|
||||
|
||||
void SQLite::exec(const std::string & stmt)
|
||||
{
|
||||
retrySQLite<void>([&]() {
|
||||
|
@ -94,6 +105,16 @@ SQLiteStmt::Use & SQLiteStmt::Use::operator () (const std::string & value, bool
|
|||
return *this;
|
||||
}
|
||||
|
||||
SQLiteStmt::Use & SQLiteStmt::Use::operator () (const unsigned char * data, size_t len, bool notNull)
|
||||
{
|
||||
if (notNull) {
|
||||
if (sqlite3_bind_blob(stmt, curArg++, data, len, SQLITE_TRANSIENT) != SQLITE_OK)
|
||||
throwSQLiteError(stmt.db, "binding argument");
|
||||
} else
|
||||
bind();
|
||||
return *this;
|
||||
}
|
||||
|
||||
SQLiteStmt::Use & SQLiteStmt::Use::operator () (int64_t value, bool notNull)
|
||||
{
|
||||
if (notNull) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue