aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/sqlite.cc
diff options
context:
space:
mode:
authorJade Lovelace <lix@jade.fyi>2024-08-04 20:20:59 -0700
committerJade Lovelace <lix@jade.fyi>2024-08-08 14:53:17 -0700
commit4ed8461cacced97717bf9a7525e12ba69fe168c0 (patch)
tree03308b2f43692cc306cb0f2825144a7ff97fc46a /src/libstore/sqlite.cc
parenta318c96851579b2a9812034c3a42f0e3fef05d9a (diff)
sqlite: add a Use::fromStrNullable
There were several usages of the raw sqlite primitives along with C style casts, seemingly because nobody thought to use an optional for getting a string or NULL. Let's fix this API given we already *have* a wrapper. Change-Id: I526cceedc2e356209d8fb62e11b3572282c314e8
Diffstat (limited to 'src/libstore/sqlite.cc')
-rw-r--r--src/libstore/sqlite.cc15
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)