diff options
Diffstat (limited to 'src/libstore/sqlite.cc')
-rw-r--r-- | src/libstore/sqlite.cc | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/libstore/sqlite.cc b/src/libstore/sqlite.cc index f40217734..3114aad48 100644 --- a/src/libstore/sqlite.cc +++ b/src/libstore/sqlite.cc @@ -199,11 +199,20 @@ bool SQLiteStmt::Use::next() return r == SQLITE_ROW; } +std::optional<std::string> SQLiteStmt::Use::getStrNullable(int col) +{ + auto s = reinterpret_cast<const char *>(sqlite3_column_text(stmt, col)); + return s != nullptr ? std::make_optional<std::string>((s)) : std::nullopt; +} + std::string SQLiteStmt::Use::getStr(int col) { - auto s = (const char *) sqlite3_column_text(stmt, col); - assert(s); - return s; + if (auto res = getStrNullable(col); res.has_value()) { + return *res; + } else { + // FIXME: turn into fatal non-exception error with actual formatting when we have those + assert(false && "sqlite3 retrieved unexpected null"); + } } int64_t SQLiteStmt::Use::getInt(int col) |