mirror of
https://github.com/NixOS/nix
synced 2025-06-28 01:11:15 +02:00
Improve SQLite busy handling
This commit is contained in:
parent
34b12bad59
commit
fd86dd93dd
3 changed files with 43 additions and 31 deletions
|
@ -30,8 +30,9 @@ struct SQLiteStmt
|
|||
{
|
||||
sqlite3 * db = 0;
|
||||
sqlite3_stmt * stmt = 0;
|
||||
std::string sql;
|
||||
SQLiteStmt() { }
|
||||
SQLiteStmt(sqlite3 * db, const std::string & s) { create(db, s); }
|
||||
SQLiteStmt(sqlite3 * db, const std::string & sql) { create(db, sql); }
|
||||
void create(sqlite3 * db, const std::string & s);
|
||||
~SQLiteStmt();
|
||||
operator sqlite3_stmt * () { return stmt; }
|
||||
|
@ -94,6 +95,8 @@ MakeError(SQLiteBusy, SQLiteError);
|
|||
|
||||
[[noreturn]] void throwSQLiteError(sqlite3 * db, const format & f);
|
||||
|
||||
void handleSQLiteBusy(const SQLiteBusy & e);
|
||||
|
||||
/* Convenience function for retrying a SQLite transaction when the
|
||||
database is busy. */
|
||||
template<typename T>
|
||||
|
@ -103,6 +106,7 @@ T retrySQLite(std::function<T()> fun)
|
|||
try {
|
||||
return fun();
|
||||
} catch (SQLiteBusy & e) {
|
||||
handleSQLiteBusy(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue