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/6] =?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/6] Add blob fields for sqlite From 192c0361e9e816acd74fb173924e8f9f83a37222 Mon Sep 17 00:00:00 2001 From: NoWhere-NowHere-TLD <53173671+NoWhere-NowHere-TLD@users.noreply.github.com> Date: Wed, 7 Aug 2024 15:33:36 +0800 Subject: [PATCH 3/6] Add blob fields for sqlite --- ormpp/sqlite.hpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ormpp/sqlite.hpp b/ormpp/sqlite.hpp index 4a3d38f3..d47beda9 100644 --- a/ormpp/sqlite.hpp +++ b/ormpp/sqlite.hpp @@ -573,8 +573,9 @@ class sqlite { 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); + 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) { @@ -630,7 +631,8 @@ class sqlite { } 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)); + 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) { From 0d55b72fa49c466772fe063ea6516ed80886780a Mon Sep 17 00:00:00 2001 From: nowhere Date: Wed, 28 Aug 2024 15:29:01 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug=EF=BC=8C=E8=BE=93?= =?UTF-8?q?=E5=85=A5=E7=9A=84sql=E8=AF=AD=E5=8F=A5=E5=AD=97=E6=AF=8D?= =?UTF-8?q?=E8=BD=AC=E5=B0=8F=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ormpp/utility.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ormpp/utility.hpp b/ormpp/utility.hpp index 02d9b3a5..e72e4e98 100644 --- a/ormpp/utility.hpp +++ b/ormpp/utility.hpp @@ -4,6 +4,7 @@ #ifndef ORM_UTILITY_HPP #define ORM_UTILITY_HPP #include +#include #include "entity.hpp" #include "iguana/reflection.hpp" @@ -440,6 +441,7 @@ inline void get_sql_conditions(std::string &) {} template inline void get_sql_conditions(std::string &sql, const std::string &arg, Args &&...args) { + std::transform(arg.begin(),arg.end(),arg.begin(),::tolower); if (arg.find("select") != std::string::npos) { sql = arg; } From ed13ae662672598d4c60d580b016e32caaf50bce Mon Sep 17 00:00:00 2001 From: nowhere Date: Wed, 28 Aug 2024 15:29:01 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug=EF=BC=8C=E8=BE=93?= =?UTF-8?q?=E5=85=A5=E7=9A=84sql=E8=AF=AD=E5=8F=A5=E5=AD=97=E6=AF=8D?= =?UTF-8?q?=E8=BD=AC=E5=B0=8F=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ormpp/utility.hpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/ormpp/utility.hpp b/ormpp/utility.hpp index 02d9b3a5..a211be93 100644 --- a/ormpp/utility.hpp +++ b/ormpp/utility.hpp @@ -4,6 +4,7 @@ #ifndef ORM_UTILITY_HPP #define ORM_UTILITY_HPP #include +#include #include "entity.hpp" #include "iguana/reflection.hpp" @@ -440,16 +441,18 @@ inline void get_sql_conditions(std::string &) {} template inline void get_sql_conditions(std::string &sql, const std::string &arg, Args &&...args) { - if (arg.find("select") != std::string::npos) { + std::string temp=arg; + std::transform(arg.begin(),arg.end(),temp.begin(),::tolower); + if (temp.find("select") != std::string::npos) { sql = arg; } else { - if (arg.find("order by") != std::string::npos) { - auto pos = sql.find("where"); + if (temp.find("order by") != std::string::npos) { + auto pos = temp.find("where"); sql = sql.substr(0, pos); } - if (arg.find("limit") != std::string::npos) { - auto pos = sql.find("where"); + if (temp.find("limit") != std::string::npos) { + auto pos = temp.find("where"); sql = sql.substr(0, pos); } append(sql, arg, std::forward(args)...); From 07f252634f36f686e05d597d5eea2a2f84e0a2e0 Mon Sep 17 00:00:00 2001 From: nowhere Date: Wed, 28 Aug 2024 19:27:06 +0800 Subject: [PATCH 6/6] =?UTF-8?q?bug=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ ormpp/utility.hpp | 2 +- tests/test_ormpp.cpp | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 39821c17..f821c6ce 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,5 @@ *build* .vscode .cache +/.vs +/CMakeSettings.json diff --git a/ormpp/utility.hpp b/ormpp/utility.hpp index 88aea59b..dd09e3ea 100644 --- a/ormpp/utility.hpp +++ b/ormpp/utility.hpp @@ -451,7 +451,7 @@ inline void get_sql_conditions(std::string &sql, const std::string &arg, auto pos = sql.find("where"); sql = sql.substr(0, pos); } - if (arg.find("limit") != std::string::npos) { + if (temp.find("limit") != std::string::npos) { auto pos = sql.find("where"); sql = sql.substr(0, pos); } diff --git a/tests/test_ormpp.cpp b/tests/test_ormpp.cpp index db31d9a2..d99f66ab 100644 --- a/tests/test_ormpp.cpp +++ b/tests/test_ormpp.cpp @@ -1392,6 +1392,8 @@ TEST_CASE("query_s delete_records_s") { auto vec5 = sqlite.query_s("name=? and age=?", "purecpp", 200); auto vec6 = sqlite.query_s("select * from person where name=?", "purecpp"); + auto vec11 = + sqlite.query_s("SELECT * FROM PERSON WHERE NAME=?", "purecpp"); auto vec7 = sqlite.query_s("name=?", "purecpp' or '1=1"); sqlite.delete_records_s("name=?", "purecpp' or '1=1"); auto vec8 = sqlite.query_s(); @@ -1415,6 +1417,7 @@ TEST_CASE("query_s delete_records_s") { CHECK(vec8.size() == 2); CHECK(vec9.size() == 1); CHECK(vec10.size() == 0); + CHECK(vec11.front().age == 200); } #endif }