From 87a5c180d7233291e892a485cdf6d86698000b33 Mon Sep 17 00:00:00 2001 From: nekobit Date: Tue, 11 Oct 2022 03:09:41 +0000 Subject: [PATCH] NULL check Sqlite3 FossilOrigin-Name: 48a6e0f0b25381529d6c52ecf5397a8e2ed0c16bf726cd795a0ffee3fd469e8c --- src/database/sqlite/sqlite.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/database/sqlite/sqlite.cpp b/src/database/sqlite/sqlite.cpp index c2c7255..3da8aef 100644 --- a/src/database/sqlite/sqlite.cpp +++ b/src/database/sqlite/sqlite.cpp @@ -144,9 +144,12 @@ User SQLite::get_user(unsigned long id) int code = sqlite_exec(GET_USER_BY_ID, {{id}}, [&luser](sqlite3_stmt* stmt){ luser.acct = reinterpret_cast(sqlite3_column_text(stmt, 0)); - luser.display_name = reinterpret_cast(sqlite3_column_text(stmt, 1)); - luser.bio = reinterpret_cast(sqlite3_column_int64(stmt, 2)); - luser.key = reinterpret_cast(sqlite3_column_text(stmt, 3)); + if (sqlite3_column_type(stmt, 1) == SQLITE_NULL) + luser.display_name = reinterpret_cast(sqlite3_column_text(stmt, 1)); + if (sqlite3_column_type(stmt, 2) == SQLITE_NULL) + luser.bio = reinterpret_cast(sqlite3_column_int64(stmt, 2)); + if (sqlite3_column_type(stmt, 3) == SQLITE_NULL) + luser.key = reinterpret_cast(sqlite3_column_text(stmt, 3)); }); if (!code) @@ -166,9 +169,12 @@ User SQLite::get_user(const std::string& acct) int code = sqlite_exec(GET_USER_BY_ACCT, {acct}, [&luser](sqlite3_stmt* stmt){ luser.id = sqlite3_column_int64(stmt, 0); - luser.display_name = reinterpret_cast(sqlite3_column_text(stmt, 1)); - luser.bio = reinterpret_cast(sqlite3_column_text(stmt, 2)); - luser.key = reinterpret_cast(sqlite3_column_text(stmt, 3)); + if (sqlite3_column_type(stmt, 1) == SQLITE_NULL) + luser.display_name = reinterpret_cast(sqlite3_column_text(stmt, 1)); + if (sqlite3_column_type(stmt, 2) == SQLITE_NULL) + luser.bio = reinterpret_cast(sqlite3_column_text(stmt, 2)); + if (sqlite3_column_type(stmt, 3) == SQLITE_NULL) + luser.key = reinterpret_cast(sqlite3_column_text(stmt, 3)); }); if (!code)