Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support query uppercase sql statements(fix bug) #176

Closed
wants to merge 10 commits into from
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 @@ -4,6 +4,7 @@
#ifndef ORM_UTILITY_HPP
#define ORM_UTILITY_HPP
#include <optional>
#include <algorithm>

#include "entity.hpp"
#include "iguana/reflection.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
Loading