Skip to content

Commit

Permalink
Merge pull request #177 from NoWhere-NowHere-TLD/master
Browse files Browse the repository at this point in the history
Support query uppercase sql statements(fix bug)
  • Loading branch information
Jacyking authored Aug 29, 2024
2 parents fd01e4d + 9a4ef4b commit f7cfb83
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@
*build*
.vscode
.cache
/.vs
/CMakeSettings.json
9 changes: 6 additions & 3 deletions ormpp/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//
#ifndef ORM_UTILITY_HPP
#define ORM_UTILITY_HPP
#include <algorithm>
#include <optional>

#include "entity.hpp"
Expand Down Expand Up @@ -440,15 +441,17 @@ inline void get_sql_conditions(std::string &) {}
template <typename... Args>
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) {
if (temp.find("order by") != std::string::npos) {
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);
}
Expand Down
3 changes: 3 additions & 0 deletions tests/test_ormpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1392,6 +1392,8 @@ TEST_CASE("query_s delete_records_s") {
auto vec5 = sqlite.query_s<person>("name=? and age=?", "purecpp", 200);
auto vec6 =
sqlite.query_s<person>("select * from person where name=?", "purecpp");
auto vec11 =
sqlite.query_s<person>("SELECT * FROM PERSON WHERE NAME=?", "purecpp");
auto vec7 = sqlite.query_s<person>("name=?", "purecpp' or '1=1");
sqlite.delete_records_s<person>("name=?", "purecpp' or '1=1");
auto vec8 = sqlite.query_s<person>();
Expand All @@ -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
}
Expand Down

0 comments on commit f7cfb83

Please sign in to comment.