Browse Source

增加clear清理函数

xx 2 years ago
parent
commit
7cd027b6be
2 changed files with 43 additions and 0 deletions
  1. 8 0
      include/db/sqler.h
  2. 35 0
      src/db/sqler.cpp

+ 8 - 0
include/db/sqler.h

@@ -81,6 +81,8 @@ namespace ylib
 		/// 查询
 		/// </summary>
 		ylib::mysql::result* query();
+
+		void clear();
 #if 0
 		/// <summary>
 		/// 查询转换为layui需求模板
@@ -159,6 +161,8 @@ namespace ylib
 		/// 查询
 		/// </summary>
 		uint64 exec();
+
+		void clear();
 	private:
 		/// <summary>
 		/// 生成SQL片段
@@ -199,6 +203,8 @@ namespace ylib
 		/// 查询
 		/// </summary>
 		uint64 exec();
+
+		void clear();
 	private:
 		mysql::conn* m_conn = nullptr;
 		std::string m_table_name;
@@ -245,6 +251,8 @@ namespace ylib
 		/// 查询
 		/// </summary>
 		uint64 exec();
+
+		void clear();
 	private:
 		/// <summary>
 		/// 生成SQL片段

+ 35 - 0
src/db/sqler.cpp

@@ -207,6 +207,15 @@ ylib::mysql::result* ylib::select::query()
 		setInsetValue(ppst, i + 1, insert_values[i]);
 	return ppst->query();
 }
+void ylib::select::clear()
+{
+	m_wheres.clear();
+	m_table_name = "";
+	m_fields.clear();
+	m_limit.count = -1;
+	m_limit.start = -1;
+	m_orderby.field = "";
+}
 void ylib::select::make_sql(std::string& field_name, std::string& where, std::string& orderby, std::string& limit, std::vector<std::any>& insert_values)
 {
 	if (m_fields.size() == 0)
@@ -367,6 +376,16 @@ uint64 ylib::update::exec()
 	return ppst->update();
 }
 
+void ylib::update::clear()
+{
+	m_wheres.clear();
+	m_table_name = "";
+	m_limit.count = -1;
+	m_limit.start = -1;
+	m_orderby.field = "";
+	m_sets.clear();
+}
+
 void ylib::update::make_sql(std::string& set, std::string& where, std::string& orderby, std::string& limit, std::vector<std::any>& insert_values)
 {
 	{
@@ -494,6 +513,13 @@ uint64 ylib::insert::exec()
 	return ppst->update();
 }
 
+void ylib::insert::clear()
+{
+	m_table_name = "";
+	m_sets.clear();
+
+}
+
 
 
 
@@ -594,6 +620,15 @@ uint64 ylib::delete_::exec()
 	return ppst->update();
 }
 
+void ylib::delete_::clear()
+{
+	m_wheres.clear();
+	m_table_name = "";
+	m_limit.count = -1;
+	m_limit.start = -1;
+	m_orderby.field = "";
+}
+
 void ylib::delete_::make_sql(std::string& where, std::string& orderby, std::string& limit, std::vector<std::any>& insert_values)
 {
 	if (m_wheres.size() != 0)