1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-27 00:11:17 +02:00

SQLite:: Add some convenience

This commit is contained in:
Eelco Dolstra 2016-08-09 14:27:30 +02:00
parent 6cb4bdf152
commit f294623d1d
4 changed files with 33 additions and 28 deletions

View file

@ -35,6 +35,13 @@ namespace nix {
throw SQLiteError(format("%1%: %2%") % f.str() % sqlite3_errmsg(db));
}
SQLite::SQLite(const Path & path)
{
if (sqlite3_open_v2(path.c_str(), &db,
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, 0) != SQLITE_OK)
throw Error(format("cannot open SQLite database %s") % path);
}
SQLite::~SQLite()
{
try {
@ -45,6 +52,12 @@ SQLite::~SQLite()
}
}
void SQLite::exec(const std::string & stmt)
{
if (sqlite3_exec(db, stmt.c_str(), 0, 0, 0) != SQLITE_OK)
throwSQLiteError(db, format("executing SQLite statement %s") % stmt);
}
void SQLiteStmt::create(sqlite3 * db, const string & s)
{
checkInterrupt();