diff options
author | rtk0c <[email protected]> | 2022-11-11 15:47:40 -0800 |
---|---|---|
committer | rtk0c <[email protected]> | 2022-11-11 15:47:40 -0800 |
commit | 01c98830affd1189ab2b227d685f10f5dc8b6ca7 (patch) | |
tree | f6eaab84ea5d73617517633dc1af3aba34d0d7ed /source/20-codegen-compiler/SQLiteHelper.hpp | |
parent | 92d01f21e420f41b3319431331af54011aa88af6 (diff) |
Changeset: 90 SQLite column reader updates
Diffstat (limited to 'source/20-codegen-compiler/SQLiteHelper.hpp')
-rw-r--r-- | source/20-codegen-compiler/SQLiteHelper.hpp | 21 |
1 files changed, 18 insertions, 3 deletions
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"); } |