diff --git a/include/mysql.hpp b/include/mysql.hpp index 80f47f33..e934be00 100644 --- a/include/mysql.hpp +++ b/include/mysql.hpp @@ -144,16 +144,8 @@ class mysql { template bool delete_records(Args &&...where_conditon) { - reset_error(); auto sql = generate_delete_sql(std::forward(where_conditon)...); -#ifdef ORMPP_ENABLE_LOG - std::cout << sql << std::endl; -#endif - if (mysql_query(con_, sql.data())) { - set_last_error(mysql_error(con_)); - return false; - } - return true; + return execute(sql); } int get_last_affect_rows() { return (int)mysql_affected_rows(con_); } @@ -522,10 +514,20 @@ class mysql { std::cout << sql << std::endl; #endif reset_error(); - if (mysql_query(con_, sql.data()) != 0) { + stmt_ = mysql_stmt_init(con_); + if (!stmt_) { set_last_error(mysql_error(con_)); return false; } + auto guard = guard_statment(stmt_); + if (mysql_stmt_prepare(stmt_, sql.c_str(), (unsigned long)sql.size())) { + set_last_error(mysql_stmt_error(stmt_)); + return false; + } + if (mysql_stmt_execute(stmt_)) { + set_last_error(mysql_stmt_error(stmt_)); + return false; + } return true; } diff --git a/include/sqlite.hpp b/include/sqlite.hpp index c0bc91ce..6bc02c4c 100644 --- a/include/sqlite.hpp +++ b/include/sqlite.hpp @@ -118,22 +118,7 @@ class sqlite { template bool delete_records(Args &&...where_conditon) { auto sql = generate_delete_sql(std::forward(where_conditon)...); -#ifdef ORMPP_ENABLE_LOG - std::cout << sql << std::endl; -#endif - int result = sqlite3_prepare_v2(handle_, sql.data(), (int)sql.size(), - &stmt_, nullptr); - if (result != SQLITE_OK) { - set_last_error(sqlite3_errmsg(handle_)); - return false; - } - - auto guard = guard_statment(stmt_); - if (sqlite3_step(stmt_) != SQLITE_DONE) { - set_last_error(sqlite3_errmsg(handle_)); - return false; - } - return true; + return execute(sql); } // restriction, all the args are string, the first is the where condition,