diff options
-rw-r--r-- | ignore.conf | 5 | ||||
-rw-r--r-- | 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<T>) { auto value = sqlite3_column_int64(stmt, column); return static_cast<T>(value); - } else if constexpr (std::is_same_v<T, int>) { - return (int)sqlite3_column_int(stmt, column); + } else if constexpr (std::is_same_v<T, int> || std::is_same_v<T, bool>) { + return (T)sqlite3_column_int(stmt, column); } else if constexpr (std::is_same_v<T, int64_t>) { - return (int64_t)sqlite3_column_int64(stmt, column); + return (T)sqlite3_column_int64(stmt, column); } else if constexpr (std::is_same_v<T, const char*>) { return (const char*)sqlite3_column_text(stmt, column); } else if constexpr (std::is_same_v<T, std::string> || std::is_same_v<T, std::string_view>) { + // 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<T, TpFromUnixTimestamp>) { auto unixTimestamp = sqlite3_column_int64(stmt, column); @@ -186,7 +189,19 @@ struct SQLiteRunningStatement { return TimePoint(chrono); } else if constexpr (std::is_same_v<T, TpFromDateTime>) { // 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"); } |