From ef5eca7f3f136e564bee79acb6845b77d6d5916f Mon Sep 17 00:00:00 2001 From: NoWhere-NowHere-TLD <53173671+NoWhere-NowHere-TLD@users.noreply.github.com> Date: Wed, 7 Aug 2024 14:14:17 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=9B=B4=E6=96=B0sqlite=E7=9A=84blob?= =?UTF-8?q?=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ormpp/sqlite.hpp | 8 ++++++++ ormpp/type_mapping.hpp | 3 +++ 2 files changed, 11 insertions(+) diff --git a/ormpp/sqlite.hpp b/ormpp/sqlite.hpp index 02f27abc..4a3d38f3 100644 --- a/ormpp/sqlite.hpp +++ b/ormpp/sqlite.hpp @@ -572,6 +572,10 @@ class sqlite { return SQLITE_OK == sqlite3_bind_text(stmt_, i, value, strlen(value), nullptr); } + else if constexpr (std::is_same_v, U>) { + return SQLITE_OK == + sqlite3_bind_blob(stmt_, i, value.data(),static_cast(value.size()), nullptr); + } #ifdef ORMPP_WITH_CSTRING else if constexpr (std::is_same_v) { return SQLITE_OK == sqlite3_bind_text(stmt_, i, value.GetString(), @@ -624,6 +628,10 @@ class sqlite { else if constexpr (iguana::c_array_v) { memcpy(value, sqlite3_column_text(stmt_, i), sizeof(U)); } + else if constexpr (std::is_same_v, U>) { + value.reserve(sqlite3_column_bytes(stmt_, i)); + memcpy(value.data(),(const char *)sqlite3_column_blob(stmt_, i),(size_t)sqlite3_column_bytes(stmt_, i)); + } #ifdef ORMPP_WITH_CSTRING else if constexpr (std::is_same_v) { value.SetString((const char *)sqlite3_column_text(stmt_, i)); diff --git a/ormpp/type_mapping.hpp b/ormpp/type_mapping.hpp index 76995718..9acfcdbd 100644 --- a/ormpp/type_mapping.hpp +++ b/ormpp/type_mapping.hpp @@ -85,6 +85,8 @@ namespace ormpp_sqlite { REGISTER_TYPE(int, SQLITE_INTEGER) REGISTER_TYPE(double, SQLITE_FLOAT) +using blob = std::vector; + inline int type_to_id(identity) noexcept { return SQLITE_TEXT; } inline std::string id_to_type( std::integral_constant) noexcept { @@ -113,6 +115,7 @@ inline constexpr auto type_to_name(identity) noexcept { inline constexpr auto type_to_name(identity) noexcept { return "INTEGER"sv; } +inline constexpr auto type_to_name(identity) noexcept { return "BLOB"sv; } inline auto type_to_name(identity) noexcept { return "TEXT"sv; } template inline auto type_to_name(identity>) noexcept { From 1373a97695e3cc0b16a872190e2e571a53a05571 Mon Sep 17 00:00:00 2001 From: NoWhere-NowHere-TLD <53173671+NoWhere-NowHere-TLD@users.noreply.github.com> Date: Wed, 7 Aug 2024 14:28:24 +0800 Subject: [PATCH 2/2] Add blob fields for sqlite