From 01c98830affd1189ab2b227d685f10f5dc8b6ca7 Mon Sep 17 00:00:00 2001 From: rtk0c Date: Fri, 11 Nov 2022 15:47:40 -0800 Subject: Changeset: 90 SQLite column reader updates --- ignore.conf | 5 +++++ source/20-codegen-compiler/SQLiteHelper.hpp | 21 ++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/ignore.conf b/ignore.conf index 058534a..57f0d4e 100644 --- a/ignore.conf +++ b/ignore.conf @@ -10,3 +10,8 @@ _ReSharper.Caches imgui.ini project.4coder CMakeSettings.json + +build-Clion-debug +build-Clion-release +build-Clion-relwithdebinfo +build-Clion-minsizerel diff --git a/source/20-codegen-compiler/SQLiteHelper.hpp b/source/20-codegen-compiler/SQLiteHelper.hpp index 5e6222d..c24e476 100644 --- a/source/20-codegen-compiler/SQLiteHelper.hpp +++ b/source/20-codegen-compiler/SQLiteHelper.hpp @@ -171,14 +171,17 @@ struct SQLiteRunningStatement { if constexpr (std::is_enum_v) { auto value = sqlite3_column_int64(stmt, column); return static_cast(value); - } else if constexpr (std::is_same_v) { - return (int)sqlite3_column_int(stmt, column); + } else if constexpr (std::is_same_v || std::is_same_v) { + return (T)sqlite3_column_int(stmt, column); } else if constexpr (std::is_same_v) { - return (int64_t)sqlite3_column_int64(stmt, column); + return (T)sqlite3_column_int64(stmt, column); } else if constexpr (std::is_same_v) { return (const char*)sqlite3_column_text(stmt, column); } else if constexpr (std::is_same_v || std::is_same_v) { + // SQLite3 uses `unsigned char` to represent UTF-8 code units, on all platforms we care about this is the same as plain `char` auto cstr = (const char*)sqlite3_column_text(stmt, column); + // For std::string_view, this finds size based on null terminator and stores reference to pointer + // For std::string, this also allocates buffer and copies `cstr` content return T(cstr); } else if constexpr (std::is_same_v) { auto unixTimestamp = sqlite3_column_int64(stmt, column); @@ -186,7 +189,19 @@ struct SQLiteRunningStatement { return TimePoint(chrono); } else if constexpr (std::is_same_v) { // TODO wait for libstdc++ and libc++ implement c++20 std::chrono addition +#ifdef _MSC_VER + auto datetime = (const char*)sqlite3_column_text(stmt, column); + if (datetime) { + std::stringstream ss(datetime); + TimePoint timepoint; + ss >> std::chrono::parse("%F %T", timepoint); + return timepoint; + } else { + return TimePoint(); + } +#else static_assert(false && sizeof(T), "Unimplemented"); +#endif } else { static_assert(false && sizeof(T), "Unknown type"); } -- cgit v1.2.3-70-g09d2