diff options
Diffstat (limited to 'src/libstore/sqlite.cc')
-rw-r--r-- | src/libstore/sqlite.cc | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/libstore/sqlite.cc b/src/libstore/sqlite.cc index f40217734..8d0bfcb11 100644 --- a/src/libstore/sqlite.cc +++ b/src/libstore/sqlite.cc @@ -1,3 +1,4 @@ +#include "charptr-cast.hh" #include "sqlite.hh" #include "globals.hh" #include "logging.hh" @@ -199,11 +200,20 @@ bool SQLiteStmt::Use::next() return r == SQLITE_ROW; } +std::optional<std::string> SQLiteStmt::Use::getStrNullable(int col) +{ + auto s = charptr_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) |