From f7f5e23e7d3a2735637a9f653ec79f0b0228cf81 Mon Sep 17 00:00:00 2001 From: Jacyking <791026912@qq.com> Date: Tue, 20 Feb 2024 16:54:46 +0800 Subject: [PATCH] add query_s delete_records_s --- ormpp/dbng.hpp | 11 +++++------ ormpp/mysql.hpp | 9 +++------ ormpp/postgresql.hpp | 9 +++------ ormpp/sqlite.hpp | 9 +++------ ormpp/utility.hpp | 11 ++++++----- 5 files changed, 20 insertions(+), 29 deletions(-) diff --git a/ormpp/dbng.hpp b/ormpp/dbng.hpp index cd232087..aae2859c 100644 --- a/ormpp/dbng.hpp +++ b/ormpp/dbng.hpp @@ -83,31 +83,30 @@ class dbng { return db_.template query_s(str, std::forward(args)...); } - // deprecated template - bool delete_records(Args &&...where_condition) { + [[deprecated]] bool delete_records(Args &&...where_condition) { return db_.template delete_records( std::forward(where_condition)...); } - // deprecated // restriction, all the args are string, the first is the where condition, // rest are append conditions template - std::vector query(Args &&...args) { + [[deprecated]] std::vector query(Args &&...args) { return db_.template query(std::forward(args)...); } // support member variable, such as: query(FID(simple::id), "<", 5) template - auto query(Pair pair, std::string_view oper, U &&val) { + [[deprecated]] auto query(Pair pair, std::string_view oper, U &&val) { auto sql = build_condition(pair, oper, std::forward(val)); using T = typename ormpp::field_attribute::type; return query(sql); } template - bool delete_records(Pair pair, std::string_view oper, U &&val) { + [[deprecated]] bool delete_records(Pair pair, std::string_view oper, + U &&val) { auto sql = build_condition(pair, oper, std::forward(val)); using T = typename ormpp::field_attribute::type; return delete_records(sql); diff --git a/ormpp/mysql.hpp b/ormpp/mysql.hpp index 0e66f731..68e5e9e8 100644 --- a/ormpp/mysql.hpp +++ b/ormpp/mysql.hpp @@ -298,9 +298,8 @@ class mysql { if constexpr (sizeof...(Args) > 0) { size_t index = 0; - using expander = int[]; std::vector param_binds; - expander{0, (set_param_bind(param_binds, args), 0)...}; + (set_param_bind(param_binds, args), 0)...); if (mysql_stmt_bind_param(stmt_, ¶m_binds[0])) { set_last_error(mysql_stmt_error(stmt_)); return false; @@ -338,9 +337,8 @@ class mysql { if constexpr (sizeof...(Args) > 0) { size_t index = 0; - using expander = int[]; std::vector param_binds; - expander{0, (set_param_bind(param_binds, args), 0)...}; + (set_param_bind(param_binds, args), ...); if (mysql_stmt_bind_param(stmt_, ¶m_binds[0])) { set_last_error(mysql_stmt_error(stmt_)); return {}; @@ -424,9 +422,8 @@ class mysql { if constexpr (sizeof...(Args) > 0) { size_t index = 0; - using expander = int[]; std::vector param_binds; - expander{0, (set_param_bind(param_binds, args), 0)...}; + (set_param_bind(param_binds, args), ...); if (mysql_stmt_bind_param(stmt_, ¶m_binds[0])) { set_last_error(mysql_stmt_error(stmt_)); return {}; diff --git a/ormpp/postgresql.hpp b/ormpp/postgresql.hpp index b7abd6eb..41fd69cf 100644 --- a/ormpp/postgresql.hpp +++ b/ormpp/postgresql.hpp @@ -135,10 +135,9 @@ class postgresql { if constexpr (sizeof...(Args) > 0) { size_t index = 0; - using expander = int[]; std::vector param_values_buf; std::vector> param_values; - expander{0, (set_param_values(param_values, args), 0)...}; + (set_param_values(param_values, args), ...); for (auto &item : param_values) { param_values_buf.push_back(item.data()); } @@ -168,10 +167,9 @@ class postgresql { if constexpr (sizeof...(Args) > 0) { size_t index = 0; - using expander = int[]; std::vector param_values_buf; std::vector> param_values; - expander{0, (set_param_values(param_values, args), 0)...}; + (set_param_values(param_values, args), ...); for (auto &item : param_values) { param_values_buf.push_back(item.data()); } @@ -213,10 +211,9 @@ class postgresql { if constexpr (sizeof...(Args) > 0) { size_t index = 0; - using expander = int[]; std::vector param_values_buf; std::vector> param_values; - expander{0, (set_param_values(param_values, args), 0)...}; + (set_param_values(param_values, args), ...); for (auto &item : param_values) { param_values_buf.push_back(item.data()); } diff --git a/ormpp/sqlite.hpp b/ormpp/sqlite.hpp index 523e1f78..e36322c0 100644 --- a/ormpp/sqlite.hpp +++ b/ormpp/sqlite.hpp @@ -136,8 +136,7 @@ class sqlite { if constexpr (sizeof...(Args) > 0) { size_t index = 0; - using expander = int[]; - expander{0, (set_param_bind(args, ++index), 0)...}; + (set_param_bind(args, ++index), ...); } auto guard = guard_statment(stmt_); @@ -164,8 +163,7 @@ class sqlite { if constexpr (sizeof...(Args) > 0) { size_t index = 0; - using expander = int[]; - expander{0, (set_param_bind(args, ++index), 0)...}; + (set_param_bind(args, ++index), ...); } auto guard = guard_statment(stmt_); @@ -206,8 +204,7 @@ class sqlite { if constexpr (sizeof...(Args) > 0) { size_t index = 0; - using expander = int[]; - expander{0, (set_param_bind(args, ++index), 0)...}; + (set_param_bind(args, ++index), ...); } auto guard = guard_statment(stmt_); diff --git a/ormpp/utility.hpp b/ormpp/utility.hpp index 6c10142b..e04c80d7 100644 --- a/ormpp/utility.hpp +++ b/ormpp/utility.hpp @@ -446,16 +446,17 @@ inline void get_sql_conditions(std::string &sql, const std::string &arg, template inline std::string generate_query_sql(Args &&...args) { - bool where = true; + bool where = false; auto name = get_name(); std::string sql = "select "; auto fields = get_fields(); append(sql, fields.data(), "from", name.data()); if constexpr (sizeof...(Args) > 0) { - if (where && !is_empty(std::forward(args)...)) { - append(sql, "where 1=1 and "); - where = false; - } + using expander = int[]; + expander{0, (where = where ? where : !is_empty(args), 0)...}; + } + if (where) { + append(sql, "where 1=1 and "); } get_sql_conditions(sql, std::forward(args)...); return sql;