|
@@ -0,0 +1,9788 @@
|
|
|
+#ifndef _ORM_DEFAULT_FORTUNE_OPERATE_H
|
|
|
+#define _ORM_DEFAULT_FORTUNE_OPERATE_H
|
|
|
+
|
|
|
+#include <iostream>
|
|
|
+#include <mutex>
|
|
|
+#include <string>
|
|
|
+#include <map>
|
|
|
+#include <set>
|
|
|
+#include <string_view>
|
|
|
+#include <thread>
|
|
|
+#include "request.h"
|
|
|
+#include "unicode.h"
|
|
|
+#include "datetime.h"
|
|
|
+#include <stdexcept>
|
|
|
+#include <iostream>
|
|
|
+#include <functional>
|
|
|
+#include <tuple>
|
|
|
+#include <typeinfo>
|
|
|
+#include <memory>
|
|
|
+#include <list>
|
|
|
+#include <queue>
|
|
|
+#include <cmath>
|
|
|
+#include <condition_variable>
|
|
|
+#include <sstream>
|
|
|
+#include <algorithm>
|
|
|
+#include <vector>
|
|
|
+
|
|
|
+#include "mysql_conn.h"
|
|
|
+#include "mysql_conn_pool.h"
|
|
|
+#include "orm_cache.hpp"
|
|
|
+/*baseincludefile*/
|
|
|
+namespace orm
|
|
|
+{
|
|
|
+// mysql Operational SQL middleware
|
|
|
+/*tagnamespace*/
|
|
|
+//{ /*tagnamespace_replace*/
|
|
|
+ template <typename M_MODEL, typename B_BASE>
|
|
|
+ class fortune_mysql : public B_BASE
|
|
|
+ {
|
|
|
+ public:
|
|
|
+ fortune_mysql(const std::string &tag) : dbtag(tag)
|
|
|
+ {
|
|
|
+ std::map<std::string, std::shared_ptr<orm_conn_pool>> &conn_pool_obj = get_orm_conn_pool_obj();
|
|
|
+ auto iter = conn_pool_obj.find(dbtag);
|
|
|
+ if (iter != conn_pool_obj.end())
|
|
|
+ {
|
|
|
+ conn_obj = iter->second;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ conn_obj = nullptr;
|
|
|
+ iserror = true;
|
|
|
+ error_msg = "conn_pool not found " + dbtag;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ fortune_mysql() : dbtag(B_BASE::_rmstag)
|
|
|
+ {
|
|
|
+ std::map<std::string, std::shared_ptr<orm_conn_pool>> &conn_pool_obj = get_orm_conn_pool_obj();
|
|
|
+ auto iter = conn_pool_obj.find(dbtag);
|
|
|
+ if (iter != conn_pool_obj.end())
|
|
|
+ {
|
|
|
+ conn_obj = iter->second;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ conn_obj = nullptr;
|
|
|
+ iserror = true;
|
|
|
+ error_msg = "conn_pool not found " + dbtag;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ M_MODEL &switchDB(const std::string &temptag)
|
|
|
+ {
|
|
|
+ std::map<std::string, std::shared_ptr<orm_conn_pool>> &conn_pool_obj = get_orm_conn_pool_obj();
|
|
|
+ auto iter = conn_pool_obj.find(temptag);
|
|
|
+ if (iter != conn_pool_obj.end())
|
|
|
+ {
|
|
|
+ conn_obj = iter->second;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ conn_obj = nullptr;
|
|
|
+ iserror = true;
|
|
|
+ error_msg = "conn_pool not found " + temptag;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ M_MODEL &set_table(const std::string &table_name)
|
|
|
+ {
|
|
|
+ if (original_tablename.empty())
|
|
|
+ {
|
|
|
+ original_tablename = B_BASE::tablename;
|
|
|
+ }
|
|
|
+ if (table_name.size() > 0)
|
|
|
+ {
|
|
|
+ B_BASE::tablename = table_name;
|
|
|
+ }
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+ M_MODEL &reset_table()
|
|
|
+ {
|
|
|
+ if (original_tablename.empty())
|
|
|
+ {
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+ B_BASE::tablename = original_tablename;
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+ unsigned int count()
|
|
|
+ {
|
|
|
+ std::string countsql;
|
|
|
+ countsql = "SELECT count(*) as total_countnum FROM ";
|
|
|
+ countsql.append(B_BASE::tablename);
|
|
|
+ countsql.append(" WHERE ");
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ countsql.append(" 1 ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ countsql.append(wheresql);
|
|
|
+ }
|
|
|
+ if (!groupsql.empty())
|
|
|
+ {
|
|
|
+ countsql.append(groupsql);
|
|
|
+ }
|
|
|
+ if (!limitsql.empty())
|
|
|
+ {
|
|
|
+ countsql.append(limitsql);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iserror)
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ effect_num = 0;
|
|
|
+ if (conn_empty())
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ auto conn = conn_obj->get_select_conn();
|
|
|
+
|
|
|
+ unsigned int querysql_len = countsql.length() + 1;
|
|
|
+
|
|
|
+ conn->send_data.clear();
|
|
|
+ conn->send_data.push_back((querysql_len & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 8 & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 16 & 0xFF));
|
|
|
+ conn->send_data.push_back(0x00);
|
|
|
+ conn->send_data.push_back(0x03);
|
|
|
+ conn->send_data.append(countsql);
|
|
|
+
|
|
|
+ std::size_t n = asio::write(*conn->socket, asio::buffer(conn->send_data), conn->ec);
|
|
|
+
|
|
|
+
|
|
|
+ pack_info_t temp_pack_data;
|
|
|
+ temp_pack_data.seq_id = 1;
|
|
|
+ bool is_sql_item = false;
|
|
|
+ //std::vector<field_info_t> field_array;
|
|
|
+ unsigned char action_setup = 0;
|
|
|
+ unsigned int column_num = 0;
|
|
|
+ unsigned int offset = 0;
|
|
|
+
|
|
|
+ querysql_len = 0;
|
|
|
+
|
|
|
+ for (; is_sql_item == false;)
|
|
|
+ {
|
|
|
+ n = conn->read_loop();
|
|
|
+ offset = 0;
|
|
|
+ for (; offset < n;)
|
|
|
+ {
|
|
|
+ conn->read_field_pack(conn->_cache_data, n, offset, temp_pack_data);
|
|
|
+ if (temp_pack_data.length == temp_pack_data.current_length)
|
|
|
+ {
|
|
|
+ if (conn->pack_eof_check(temp_pack_data))
|
|
|
+ {
|
|
|
+ is_sql_item = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (action_setup == 0)
|
|
|
+ {
|
|
|
+ if (temp_pack_data.length == 2 && (unsigned char)temp_pack_data.data[0] < 251 && (unsigned char)temp_pack_data.data[0] > 0)
|
|
|
+ {
|
|
|
+ action_setup = 1;
|
|
|
+ column_num = (unsigned char)temp_pack_data.data[0];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (action_setup == 1)
|
|
|
+ {
|
|
|
+ field_info_t temp_filed_col;
|
|
|
+ conn->read_col_info(temp_pack_data.data, temp_filed_col);
|
|
|
+
|
|
|
+ column_num--;
|
|
|
+ if (column_num == 0)
|
|
|
+ {
|
|
|
+ action_setup = 2;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (action_setup == 2)
|
|
|
+ {
|
|
|
+ unsigned int tempnum = 0;
|
|
|
+
|
|
|
+ unsigned int name_length = conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], tempnum);
|
|
|
+
|
|
|
+ querysql_len = 0;
|
|
|
+ for (unsigned int ik = 0; ik < name_length; ik++)
|
|
|
+ {
|
|
|
+ if (temp_pack_data.data[tempnum] >= '0' && temp_pack_data.data[tempnum] <= '9')
|
|
|
+ {
|
|
|
+ querysql_len = querysql_len * 10 + (temp_pack_data.data[tempnum] - '0');
|
|
|
+ }
|
|
|
+ tempnum++;
|
|
|
+ }
|
|
|
+ effect_num++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (offset >= n)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ is_sql_item = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ conn_obj->back_select_conn(conn);
|
|
|
+
|
|
|
+ if (iscache)
|
|
|
+ {
|
|
|
+ if (exptime > 0)
|
|
|
+ {
|
|
|
+ save_cache(exptime);
|
|
|
+ exptime = 0;
|
|
|
+ iscache = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return querysql_len;
|
|
|
+ }
|
|
|
+ catch (const std::exception &e)
|
|
|
+ {
|
|
|
+ error_msg = std::string(e.what());
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ catch (const std::string &e)
|
|
|
+ {
|
|
|
+ error_msg = e;
|
|
|
+ }
|
|
|
+ catch (...)
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ std::tuple<unsigned int, unsigned int, unsigned int, unsigned int>
|
|
|
+ page(unsigned int page, unsigned int per_page = 10, unsigned int list_num = 5)
|
|
|
+ {
|
|
|
+ unsigned int total_page = count();
|
|
|
+ if (per_page == 0)
|
|
|
+ {
|
|
|
+ per_page = 10;
|
|
|
+ }
|
|
|
+ if (list_num < 1)
|
|
|
+ {
|
|
|
+ list_num = 1;
|
|
|
+ }
|
|
|
+ total_page = std::ceil((float)total_page / per_page);
|
|
|
+
|
|
|
+ if (total_page < 1)
|
|
|
+ {
|
|
|
+ total_page = 1;
|
|
|
+ }
|
|
|
+ if (page > total_page)
|
|
|
+ {
|
|
|
+ page = total_page;
|
|
|
+ }
|
|
|
+ if (page < 1)
|
|
|
+ {
|
|
|
+ page = 1;
|
|
|
+ }
|
|
|
+ unsigned int mid_num = std::floor(list_num / 2);
|
|
|
+ unsigned int last_num = list_num - 1;
|
|
|
+
|
|
|
+ int temp_num = page - mid_num;
|
|
|
+
|
|
|
+ unsigned int minpage = temp_num < 1 ? 1 : temp_num;
|
|
|
+ unsigned int maxpage = minpage + last_num;
|
|
|
+
|
|
|
+ if (maxpage > total_page)
|
|
|
+ {
|
|
|
+ maxpage = total_page;
|
|
|
+ temp_num = (maxpage - last_num);
|
|
|
+ if (temp_num < 1)
|
|
|
+ {
|
|
|
+ minpage = 1;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ minpage = temp_num;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ limit((page - 1) * per_page, per_page);
|
|
|
+ return std::make_tuple(minpage, maxpage, page, total_page);
|
|
|
+ }
|
|
|
+ asio::awaitable<unsigned int> async_count()
|
|
|
+ {
|
|
|
+ std::string countsql;
|
|
|
+ countsql = "SELECT count(*) as total_countnum FROM ";
|
|
|
+ countsql.append(B_BASE::tablename);
|
|
|
+ countsql.append(" WHERE ");
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ countsql.append(" 1 ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ countsql.append(wheresql);
|
|
|
+ }
|
|
|
+ if (!groupsql.empty())
|
|
|
+ {
|
|
|
+ countsql.append(groupsql);
|
|
|
+ }
|
|
|
+ if (!limitsql.empty())
|
|
|
+ {
|
|
|
+ countsql.append(limitsql);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iserror)
|
|
|
+ {
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ effect_num = 0;
|
|
|
+ if (conn_empty())
|
|
|
+ {
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ auto conn = co_await conn_obj->async_get_select_conn();
|
|
|
+
|
|
|
+ unsigned int querysql_len = countsql.length() + 1;
|
|
|
+
|
|
|
+ conn->send_data.clear();
|
|
|
+ conn->send_data.push_back((querysql_len & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 8 & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 16 & 0xFF));
|
|
|
+ conn->send_data.push_back(0x00);
|
|
|
+ conn->send_data.push_back(0x03);
|
|
|
+ conn->send_data.append(countsql);
|
|
|
+
|
|
|
+ std::size_t n = co_await asio::async_write(*conn->socket, asio::buffer(conn->send_data), asio::use_awaitable);
|
|
|
+
|
|
|
+
|
|
|
+ pack_info_t temp_pack_data;
|
|
|
+ temp_pack_data.seq_id = 1;
|
|
|
+ bool is_sql_item = false;
|
|
|
+ //std::vector<field_info_t> field_array;
|
|
|
+ unsigned char action_setup = 0;
|
|
|
+ unsigned int column_num = 0;
|
|
|
+ unsigned int offset = 0;
|
|
|
+
|
|
|
+ querysql_len = 0;
|
|
|
+
|
|
|
+ for (; is_sql_item == false;)
|
|
|
+ {
|
|
|
+ n = co_await conn->async_read_loop();
|
|
|
+ offset = 0;
|
|
|
+ for (; offset < n;)
|
|
|
+ {
|
|
|
+ conn->read_field_pack(conn->_cache_data, n, offset, temp_pack_data);
|
|
|
+ if (temp_pack_data.length == temp_pack_data.current_length)
|
|
|
+ {
|
|
|
+ if (conn->pack_eof_check(temp_pack_data))
|
|
|
+ {
|
|
|
+ is_sql_item = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (action_setup == 0)
|
|
|
+ {
|
|
|
+ if (temp_pack_data.length == 2 && (unsigned char)temp_pack_data.data[0] < 251 && (unsigned char)temp_pack_data.data[0] > 0)
|
|
|
+ {
|
|
|
+ action_setup = 1;
|
|
|
+ column_num = (unsigned char)temp_pack_data.data[0];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (action_setup == 1)
|
|
|
+ {
|
|
|
+ field_info_t temp_filed_col;
|
|
|
+ conn->read_col_info(temp_pack_data.data, temp_filed_col);
|
|
|
+
|
|
|
+ column_num--;
|
|
|
+ if (column_num == 0)
|
|
|
+ {
|
|
|
+ action_setup = 2;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (action_setup == 2)
|
|
|
+ {
|
|
|
+ unsigned int tempnum = 0;
|
|
|
+
|
|
|
+ unsigned int name_length = conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], tempnum);
|
|
|
+
|
|
|
+ querysql_len = 0;
|
|
|
+ for (unsigned int ik = 0; ik < name_length; ik++)
|
|
|
+ {
|
|
|
+ if (temp_pack_data.data[tempnum] >= '0' && temp_pack_data.data[tempnum] <= '9')
|
|
|
+ {
|
|
|
+ querysql_len = querysql_len * 10 + (temp_pack_data.data[tempnum] - '0');
|
|
|
+ }
|
|
|
+ tempnum++;
|
|
|
+ }
|
|
|
+ effect_num++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (offset >= n)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ is_sql_item = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ conn_obj->back_select_conn(conn);
|
|
|
+
|
|
|
+ if (iscache)
|
|
|
+ {
|
|
|
+ if (exptime > 0)
|
|
|
+ {
|
|
|
+ save_cache(exptime);
|
|
|
+ exptime = 0;
|
|
|
+ iscache = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ co_return querysql_len;
|
|
|
+ }
|
|
|
+ catch (const std::exception &e)
|
|
|
+ {
|
|
|
+ error_msg = std::string(e.what());
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ catch (const std::string &e)
|
|
|
+ {
|
|
|
+ error_msg = e;
|
|
|
+ }
|
|
|
+ catch (...)
|
|
|
+ {
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ asio::awaitable<std::tuple<unsigned int, unsigned int, unsigned int, unsigned int>>
|
|
|
+ async_page(unsigned int page, unsigned int per_page = 10, unsigned int list_num = 5)
|
|
|
+ {
|
|
|
+ unsigned int total_page = async_count();
|
|
|
+ if (per_page == 0)
|
|
|
+ {
|
|
|
+ per_page = 10;
|
|
|
+ }
|
|
|
+ if (list_num < 1)
|
|
|
+ {
|
|
|
+ list_num = 1;
|
|
|
+ }
|
|
|
+ total_page = std::ceil((float)total_page / per_page);
|
|
|
+
|
|
|
+ if (total_page < 1)
|
|
|
+ {
|
|
|
+ total_page = 1;
|
|
|
+ }
|
|
|
+ if (page > total_page)
|
|
|
+ {
|
|
|
+ page = total_page;
|
|
|
+ }
|
|
|
+ if (page < 1)
|
|
|
+ {
|
|
|
+ page = 1;
|
|
|
+ }
|
|
|
+ unsigned int mid_num = std::floor(list_num / 2);
|
|
|
+ unsigned int last_num = list_num - 1;
|
|
|
+
|
|
|
+ int temp_num = page - mid_num;
|
|
|
+
|
|
|
+ unsigned int minpage = temp_num < 1 ? 1 : temp_num;
|
|
|
+ unsigned int maxpage = minpage + last_num;
|
|
|
+
|
|
|
+ if (maxpage > total_page)
|
|
|
+ {
|
|
|
+ maxpage = total_page;
|
|
|
+ temp_num = (maxpage - last_num);
|
|
|
+ if (temp_num < 1)
|
|
|
+ {
|
|
|
+ minpage = 1;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ minpage = temp_num;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ limit((page - 1) * per_page, per_page);
|
|
|
+ co_return std::make_tuple(minpage, maxpage, page, total_page);
|
|
|
+ }
|
|
|
+
|
|
|
+ unsigned int update_col(std::string colname, int num, char symbol = '+')
|
|
|
+ {
|
|
|
+ effect_num = 0;
|
|
|
+ std::string countsql;
|
|
|
+ countsql = "UPDATE ";
|
|
|
+ countsql.append(B_BASE::tablename);
|
|
|
+ countsql.append(" SET ");
|
|
|
+ countsql.append(colname);
|
|
|
+ if (num > 0)
|
|
|
+ {
|
|
|
+ countsql.append(" = ");
|
|
|
+ countsql.append(colname);
|
|
|
+ countsql.push_back(' ');
|
|
|
+ countsql.push_back(symbol);
|
|
|
+ countsql.append(std::to_string(num));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ countsql.append(" = ");
|
|
|
+ countsql.append(colname);
|
|
|
+ countsql.push_back(' ');
|
|
|
+ countsql.push_back(symbol);
|
|
|
+ countsql.push_back('(');
|
|
|
+ countsql.push_back('-');
|
|
|
+ countsql.append(std::to_string(std::abs(num)));
|
|
|
+ countsql.push_back(')');
|
|
|
+ }
|
|
|
+ countsql.append(" where ");
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ if (B_BASE::getPK() > 0)
|
|
|
+ {
|
|
|
+ std::ostringstream tempsql;
|
|
|
+ tempsql << " ";
|
|
|
+ tempsql << B_BASE::getPKname();
|
|
|
+ tempsql << " = '";
|
|
|
+ tempsql << B_BASE::getPK();
|
|
|
+ tempsql << "' ";
|
|
|
+ countsql.append(tempsql.str());
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ countsql.append(wheresql);
|
|
|
+ }
|
|
|
+ if (!groupsql.empty())
|
|
|
+ {
|
|
|
+ countsql.append(groupsql);
|
|
|
+ }
|
|
|
+ if (!limitsql.empty())
|
|
|
+ {
|
|
|
+ countsql.append(limitsql);
|
|
|
+ }
|
|
|
+ if (iscommit)
|
|
|
+ {
|
|
|
+ iscommit = false;
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iserror)
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (conn_empty())
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ auto conn = conn_obj->get_edit_conn();
|
|
|
+
|
|
|
+ unsigned int querysql_len = countsql.length() + 1;
|
|
|
+
|
|
|
+ conn->send_data.clear();
|
|
|
+ conn->send_data.push_back((querysql_len & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 8 & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 16 & 0xFF));
|
|
|
+ conn->send_data.push_back(0x00);
|
|
|
+ conn->send_data.push_back(0x03);
|
|
|
+ conn->send_data.append(countsql);
|
|
|
+
|
|
|
+ std::size_t n = asio::write(*conn->socket, asio::buffer(conn->send_data), conn->ec);
|
|
|
+
|
|
|
+ unsigned int offset = 0;
|
|
|
+ n = conn->read_loop();
|
|
|
+
|
|
|
+ pack_info_t temp_pack_data;
|
|
|
+ temp_pack_data.seq_id = 1;
|
|
|
+ conn->read_field_pack(conn->_cache_data, n, offset, temp_pack_data);
|
|
|
+
|
|
|
+ conn_obj->back_edit_conn(conn);
|
|
|
+
|
|
|
+ if ((unsigned char)temp_pack_data.data[0] == 0xFF)
|
|
|
+ {
|
|
|
+ error_msg = temp_pack_data.data.substr(3);
|
|
|
+ }
|
|
|
+ else if ((unsigned char)temp_pack_data.data[0] == 0x00)
|
|
|
+ {
|
|
|
+
|
|
|
+ unsigned int d_offset = 1;
|
|
|
+ effect_num = conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], d_offset);
|
|
|
+ //insertid = pack_real_num((unsigned char *)&temp_pack_data.data[0], d_offset);
|
|
|
+ return effect_num;
|
|
|
+ }
|
|
|
+
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ catch (const std::exception &e)
|
|
|
+ {
|
|
|
+ error_msg = std::string(e.what());
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ catch (const std::string &e)
|
|
|
+ {
|
|
|
+ error_msg = e;
|
|
|
+ }
|
|
|
+ catch (...)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ asio::awaitable<unsigned int> async_update_col(std::string colname, int num, char symbol = '+')
|
|
|
+ {
|
|
|
+ effect_num = 0;
|
|
|
+ std::string countsql;
|
|
|
+ countsql = "UPDATE ";
|
|
|
+ countsql.append(B_BASE::tablename);
|
|
|
+ countsql.append(" SET ");
|
|
|
+ countsql.append(colname);
|
|
|
+ if (num > 0)
|
|
|
+ {
|
|
|
+ countsql.append(" = ");
|
|
|
+ countsql.append(colname);
|
|
|
+ countsql.push_back(' ');
|
|
|
+ countsql.push_back(symbol);
|
|
|
+ countsql.append(std::to_string(num));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ countsql.append(" = ");
|
|
|
+ countsql.append(colname);
|
|
|
+ countsql.push_back(' ');
|
|
|
+ countsql.push_back(symbol);
|
|
|
+ countsql.push_back('(');
|
|
|
+ countsql.push_back('-');
|
|
|
+ countsql.append(std::to_string(std::abs(num)));
|
|
|
+ countsql.push_back(')');
|
|
|
+ }
|
|
|
+ countsql.append(" where ");
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ if (B_BASE::getPK() > 0)
|
|
|
+ {
|
|
|
+ std::ostringstream tempsql;
|
|
|
+ tempsql << " ";
|
|
|
+ tempsql << B_BASE::getPKname();
|
|
|
+ tempsql << " = '";
|
|
|
+ tempsql << B_BASE::getPK();
|
|
|
+ tempsql << "' ";
|
|
|
+ countsql.append(tempsql.str());
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ countsql.append(wheresql);
|
|
|
+ }
|
|
|
+ if (!groupsql.empty())
|
|
|
+ {
|
|
|
+ countsql.append(groupsql);
|
|
|
+ }
|
|
|
+ if (!limitsql.empty())
|
|
|
+ {
|
|
|
+ countsql.append(limitsql);
|
|
|
+ }
|
|
|
+ if (iscommit)
|
|
|
+ {
|
|
|
+ iscommit = false;
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iserror)
|
|
|
+ {
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+
|
|
|
+ if (conn_empty())
|
|
|
+ {
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ auto conn = co_await conn_obj->async_get_edit_conn();
|
|
|
+
|
|
|
+ unsigned int querysql_len = countsql.length() + 1;
|
|
|
+
|
|
|
+ conn->send_data.clear();
|
|
|
+ conn->send_data.push_back((querysql_len & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 8 & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 16 & 0xFF));
|
|
|
+ conn->send_data.push_back(0x00);
|
|
|
+ conn->send_data.push_back(0x03);
|
|
|
+ conn->send_data.append(countsql);
|
|
|
+
|
|
|
+ std::size_t n = co_await asio::async_write(*conn->socket, asio::buffer(conn->send_data), asio::use_awaitable);
|
|
|
+
|
|
|
+ unsigned int offset = 0;
|
|
|
+ n = co_await conn->async_read_loop();
|
|
|
+
|
|
|
+ pack_info_t temp_pack_data;
|
|
|
+ temp_pack_data.seq_id = 1;
|
|
|
+ conn->read_field_pack(conn->_cache_data, n, offset, temp_pack_data);
|
|
|
+
|
|
|
+ conn_obj->back_edit_conn(conn);
|
|
|
+
|
|
|
+ if ((unsigned char)temp_pack_data.data[0] == 0xFF)
|
|
|
+ {
|
|
|
+ error_msg = temp_pack_data.data.substr(3);
|
|
|
+ }
|
|
|
+ else if ((unsigned char)temp_pack_data.data[0] == 0x00)
|
|
|
+ {
|
|
|
+
|
|
|
+ unsigned int d_offset = 1;
|
|
|
+ effect_num = conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], d_offset);
|
|
|
+ //insertid = pack_real_num((unsigned char *)&temp_pack_data.data[0], d_offset);
|
|
|
+ co_return effect_num;
|
|
|
+ }
|
|
|
+
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ catch (const std::exception &e)
|
|
|
+ {
|
|
|
+ error_msg = std::string(e.what());
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ catch (const std::string &e)
|
|
|
+ {
|
|
|
+ error_msg = e;
|
|
|
+ }
|
|
|
+ catch (...)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ int replace_col(std::string colname, const std::string &old_string, const std::string &new_string)
|
|
|
+ {
|
|
|
+ effect_num = 0;
|
|
|
+ std::string countsql;
|
|
|
+ countsql = "UPDATE ";
|
|
|
+ countsql.append(B_BASE::tablename);
|
|
|
+ countsql.append(" SET ");
|
|
|
+ countsql.append(colname);
|
|
|
+
|
|
|
+ countsql.append(" = REPLACE(");
|
|
|
+ countsql.append(colname);
|
|
|
+ countsql.append(",'");
|
|
|
+ countsql.append(old_string);
|
|
|
+ countsql.append("','");
|
|
|
+ countsql.append(new_string);
|
|
|
+ countsql.append("') ");
|
|
|
+
|
|
|
+ countsql.append(" where ");
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ if (B_BASE::getPK() > 0)
|
|
|
+ {
|
|
|
+ std::ostringstream tempsql;
|
|
|
+ tempsql << " ";
|
|
|
+ tempsql << B_BASE::getPKname();
|
|
|
+ tempsql << " = '";
|
|
|
+ tempsql << B_BASE::getPK();
|
|
|
+ tempsql << "' ";
|
|
|
+ countsql.append(tempsql.str());
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ countsql.append(wheresql);
|
|
|
+ }
|
|
|
+ if (!groupsql.empty())
|
|
|
+ {
|
|
|
+ countsql.append(groupsql);
|
|
|
+ }
|
|
|
+ if (!limitsql.empty())
|
|
|
+ {
|
|
|
+ countsql.append(limitsql);
|
|
|
+ }
|
|
|
+ if (iscommit)
|
|
|
+ {
|
|
|
+ iscommit = false;
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iserror)
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (conn_empty())
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ auto conn = conn_obj->get_edit_conn();
|
|
|
+
|
|
|
+ unsigned int querysql_len = countsql.length() + 1;
|
|
|
+
|
|
|
+ conn->send_data.clear();
|
|
|
+ conn->send_data.push_back((querysql_len & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 8 & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 16 & 0xFF));
|
|
|
+ conn->send_data.push_back(0x00);
|
|
|
+ conn->send_data.push_back(0x03);
|
|
|
+ conn->send_data.append(countsql);
|
|
|
+
|
|
|
+ std::size_t n = asio::write(*conn->socket, asio::buffer(conn->send_data), conn->ec);
|
|
|
+
|
|
|
+ unsigned int offset = 0;
|
|
|
+ n = conn->read_loop();
|
|
|
+
|
|
|
+ pack_info_t temp_pack_data;
|
|
|
+ temp_pack_data.seq_id = 1;
|
|
|
+ conn->read_field_pack(conn->_cache_data, n, offset, temp_pack_data);
|
|
|
+
|
|
|
+ conn_obj->back_edit_conn(conn);
|
|
|
+
|
|
|
+ if ((unsigned char)temp_pack_data.data[0] == 0xFF)
|
|
|
+ {
|
|
|
+ error_msg = temp_pack_data.data.substr(3);
|
|
|
+ }
|
|
|
+ else if ((unsigned char)temp_pack_data.data[0] == 0x00)
|
|
|
+ {
|
|
|
+
|
|
|
+ unsigned int d_offset = 1;
|
|
|
+ effect_num = conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], d_offset);
|
|
|
+ //insertid = pack_real_num((unsigned char *)&temp_pack_data.data[0], d_offset);
|
|
|
+ return effect_num;
|
|
|
+ }
|
|
|
+
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ catch (const std::exception &e)
|
|
|
+ {
|
|
|
+ error_msg = std::string(e.what());
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ catch (const std::string &e)
|
|
|
+ {
|
|
|
+ error_msg = e;
|
|
|
+ }
|
|
|
+ catch (...)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ void assign_field_value(unsigned char index_pos, unsigned char *result_temp_data, unsigned int value_size, typename B_BASE::meta &data_temp)
|
|
|
+ {
|
|
|
+ switch(index_pos)
|
|
|
+ {
|
|
|
+ case 0:
|
|
|
+ data_temp.id=0;
|
|
|
+
|
|
|
+ for(unsigned int i=0; i< value_size; i++)
|
|
|
+ {
|
|
|
+ if(result_temp_data[i]>='0'&&result_temp_data[i]<='9')
|
|
|
+ {
|
|
|
+
|
|
|
+ data_temp.id= data_temp.id * 10 + (result_temp_data[i]-'0');
|
|
|
+ }
|
|
|
+ if(i>32)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ data_temp.message.clear();
|
|
|
+ data_temp.message.resize(value_size);
|
|
|
+
|
|
|
+ std::memcpy(data_temp.message.data(), result_temp_data, value_size);
|
|
|
+ break;
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& eqId(const std::string &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" id = ");
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ wheresql.append(std::to_string(std::stoll(val)));
|
|
|
+ }
|
|
|
+ catch (std::invalid_argument const& ex)
|
|
|
+ {
|
|
|
+ wheresql.push_back('0');
|
|
|
+ }
|
|
|
+ catch (std::out_of_range const& ex)
|
|
|
+ {
|
|
|
+ wheresql.push_back('0');
|
|
|
+ }
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& nqId(const std::string &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" id != ");
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ wheresql.append(std::to_string(std::stoll(val)));
|
|
|
+ }
|
|
|
+ catch (std::invalid_argument const& ex)
|
|
|
+ {
|
|
|
+ wheresql.push_back('0');
|
|
|
+ }
|
|
|
+ catch (std::out_of_range const& ex)
|
|
|
+ {
|
|
|
+ wheresql.push_back('0');
|
|
|
+ }
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& inId(const std::string &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" id IN(");
|
|
|
+
|
|
|
+ wheresql.append(val);
|
|
|
+ wheresql.push_back(')');
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+template <typename T>
|
|
|
+ requires std::is_integral_v<T>
|
|
|
+M_MODEL& inId(const std::vector<T>& val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" id IN(");
|
|
|
+
|
|
|
+ for(unsigned int i=0;i<val.size(); i++)
|
|
|
+ {
|
|
|
+ if(i > 0)
|
|
|
+ {
|
|
|
+ wheresql.push_back(',');
|
|
|
+ }
|
|
|
+ wheresql.append(std::to_string(val[i]));
|
|
|
+ }
|
|
|
+ wheresql.push_back(')');
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& inId(const std::vector<std::string>& val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" id IN(");
|
|
|
+
|
|
|
+ for(unsigned int i=0;i<val.size(); i++)
|
|
|
+ {
|
|
|
+ if(i > 0)
|
|
|
+ {
|
|
|
+ wheresql.push_back(',');
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ wheresql.append(std::to_string(std::stoll(val[i])));
|
|
|
+ }
|
|
|
+ catch (std::invalid_argument const& ex)
|
|
|
+ {
|
|
|
+ wheresql.push_back('0');
|
|
|
+ }
|
|
|
+ catch (std::out_of_range const& ex)
|
|
|
+ {
|
|
|
+ wheresql.push_back('0');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ wheresql.push_back(')');
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& ninId(const std::string &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" id NOT IN(");
|
|
|
+
|
|
|
+ wheresql.append(val);
|
|
|
+ wheresql.push_back(')');
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+template <typename T>
|
|
|
+ requires std::is_integral_v<T>
|
|
|
+M_MODEL& ninId(const std::vector<T>& val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" id NOT IN(");
|
|
|
+
|
|
|
+ for(unsigned int i=0;i<val.size(); i++)
|
|
|
+ {
|
|
|
+ if(i > 0)
|
|
|
+ {
|
|
|
+ wheresql.push_back(',');
|
|
|
+ }
|
|
|
+ wheresql.append(std::to_string(val[i]));
|
|
|
+ }
|
|
|
+ wheresql.push_back(')');
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& ninId(const std::vector<std::string>& val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" id NOT IN(");
|
|
|
+
|
|
|
+ for(unsigned int i=0;i<val.size(); i++)
|
|
|
+ {
|
|
|
+ if(i > 0)
|
|
|
+ {
|
|
|
+ wheresql.push_back(',');
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ wheresql.append(std::to_string(std::stoll(val[i])));
|
|
|
+ }
|
|
|
+ catch (std::invalid_argument const& ex)
|
|
|
+ {
|
|
|
+ wheresql.push_back('0');
|
|
|
+ }
|
|
|
+ catch (std::out_of_range const& ex)
|
|
|
+ {
|
|
|
+ wheresql.push_back('0');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ wheresql.push_back(')');
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& btId(const std::string &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" id > ");
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ wheresql.append(std::to_string(std::stoll(val)));
|
|
|
+ }
|
|
|
+ catch (std::invalid_argument const& ex)
|
|
|
+ {
|
|
|
+ wheresql.push_back('0');
|
|
|
+ }
|
|
|
+ catch (std::out_of_range const& ex)
|
|
|
+ {
|
|
|
+ wheresql.push_back('0');
|
|
|
+ }
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& beId(const std::string &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" id >= ");
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ wheresql.append(std::to_string(std::stoll(val)));
|
|
|
+ }
|
|
|
+ catch (std::invalid_argument const& ex)
|
|
|
+ {
|
|
|
+ wheresql.push_back('0');
|
|
|
+ }
|
|
|
+ catch (std::out_of_range const& ex)
|
|
|
+ {
|
|
|
+ wheresql.push_back('0');
|
|
|
+ }
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& ltId(const std::string &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" id < ");
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ wheresql.append(std::to_string(std::stoll(val)));
|
|
|
+ }
|
|
|
+ catch (std::invalid_argument const& ex)
|
|
|
+ {
|
|
|
+ wheresql.push_back('0');
|
|
|
+ }
|
|
|
+ catch (std::out_of_range const& ex)
|
|
|
+ {
|
|
|
+ wheresql.push_back('0');
|
|
|
+ }
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& leId(const std::string &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" id <= ");
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ wheresql.append(std::to_string(std::stoll(val)));
|
|
|
+ }
|
|
|
+ catch (std::invalid_argument const& ex)
|
|
|
+ {
|
|
|
+ wheresql.push_back('0');
|
|
|
+ }
|
|
|
+ catch (std::out_of_range const& ex)
|
|
|
+ {
|
|
|
+ wheresql.push_back('0');
|
|
|
+ }
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& or_eqId(const std::string &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" id = ");
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ wheresql.append(std::to_string(std::stoll(val)));
|
|
|
+ }
|
|
|
+ catch (std::invalid_argument const& ex)
|
|
|
+ {
|
|
|
+ wheresql.push_back('0');
|
|
|
+ }
|
|
|
+ catch (std::out_of_range const& ex)
|
|
|
+ {
|
|
|
+ wheresql.push_back('0');
|
|
|
+ }
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& or_nqId(const std::string &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" id != ");
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ wheresql.append(std::to_string(std::stoll(val)));
|
|
|
+ }
|
|
|
+ catch (std::invalid_argument const& ex)
|
|
|
+ {
|
|
|
+ wheresql.push_back('0');
|
|
|
+ }
|
|
|
+ catch (std::out_of_range const& ex)
|
|
|
+ {
|
|
|
+ wheresql.push_back('0');
|
|
|
+ }
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& or_inId(const std::string &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" id IN(");
|
|
|
+
|
|
|
+ wheresql.append(val);
|
|
|
+ wheresql.push_back(')');
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+template <typename T>
|
|
|
+ requires std::is_integral_v<T>
|
|
|
+M_MODEL& or_inId(const std::vector<T>& val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" id IN(");
|
|
|
+
|
|
|
+ for(unsigned int i=0;i<val.size(); i++)
|
|
|
+ {
|
|
|
+ if(i > 0)
|
|
|
+ {
|
|
|
+ wheresql.push_back(',');
|
|
|
+ }
|
|
|
+ wheresql.append(std::to_string(val[i]));
|
|
|
+ }
|
|
|
+ wheresql.push_back(')');
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& or_inId(const std::vector<std::string>& val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" id IN(");
|
|
|
+
|
|
|
+ for(unsigned int i=0;i<val.size(); i++)
|
|
|
+ {
|
|
|
+ if(i > 0)
|
|
|
+ {
|
|
|
+ wheresql.push_back(',');
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ wheresql.append(std::to_string(std::stoll(val[i])));
|
|
|
+ }
|
|
|
+ catch (std::invalid_argument const& ex)
|
|
|
+ {
|
|
|
+ wheresql.push_back('0');
|
|
|
+ }
|
|
|
+ catch (std::out_of_range const& ex)
|
|
|
+ {
|
|
|
+ wheresql.push_back('0');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ wheresql.push_back(')');
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& or_ninId(const std::string &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" id NOT IN(");
|
|
|
+
|
|
|
+ wheresql.append(val);
|
|
|
+ wheresql.push_back(')');
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+template <typename T>
|
|
|
+ requires std::is_integral_v<T>
|
|
|
+M_MODEL& or_ninId(const std::vector<T>& val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" id NOT IN(");
|
|
|
+
|
|
|
+ for(unsigned int i=0;i<val.size(); i++)
|
|
|
+ {
|
|
|
+ if(i > 0)
|
|
|
+ {
|
|
|
+ wheresql.push_back(',');
|
|
|
+ }
|
|
|
+ wheresql.append(std::to_string(val[i]));
|
|
|
+ }
|
|
|
+ wheresql.push_back(')');
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& or_ninId(const std::vector<std::string>& val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" id NOT IN(");
|
|
|
+
|
|
|
+ for(unsigned int i=0;i<val.size(); i++)
|
|
|
+ {
|
|
|
+ if(i > 0)
|
|
|
+ {
|
|
|
+ wheresql.push_back(',');
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ wheresql.append(std::to_string(std::stoll(val[i])));
|
|
|
+ }
|
|
|
+ catch (std::invalid_argument const& ex)
|
|
|
+ {
|
|
|
+ wheresql.push_back('0');
|
|
|
+ }
|
|
|
+ catch (std::out_of_range const& ex)
|
|
|
+ {
|
|
|
+ wheresql.push_back('0');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ wheresql.push_back(')');
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& or_btId(const std::string &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" id > ");
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ wheresql.append(std::to_string(std::stoll(val)));
|
|
|
+ }
|
|
|
+ catch (std::invalid_argument const& ex)
|
|
|
+ {
|
|
|
+ wheresql.push_back('0');
|
|
|
+ }
|
|
|
+ catch (std::out_of_range const& ex)
|
|
|
+ {
|
|
|
+ wheresql.push_back('0');
|
|
|
+ }
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& or_beId(const std::string &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" id >= ");
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ wheresql.append(std::to_string(std::stoll(val)));
|
|
|
+ }
|
|
|
+ catch (std::invalid_argument const& ex)
|
|
|
+ {
|
|
|
+ wheresql.push_back('0');
|
|
|
+ }
|
|
|
+ catch (std::out_of_range const& ex)
|
|
|
+ {
|
|
|
+ wheresql.push_back('0');
|
|
|
+ }
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& or_ltId(const std::string &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" id < ");
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ wheresql.append(std::to_string(std::stoll(val)));
|
|
|
+ }
|
|
|
+ catch (std::invalid_argument const& ex)
|
|
|
+ {
|
|
|
+ wheresql.push_back('0');
|
|
|
+ }
|
|
|
+ catch (std::out_of_range const& ex)
|
|
|
+ {
|
|
|
+ wheresql.push_back('0');
|
|
|
+ }
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& or_leId(const std::string &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" id <= ");
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ wheresql.append(std::to_string(std::stoll(val)));
|
|
|
+ }
|
|
|
+ catch (std::invalid_argument const& ex)
|
|
|
+ {
|
|
|
+ wheresql.push_back('0');
|
|
|
+ }
|
|
|
+ catch (std::out_of_range const& ex)
|
|
|
+ {
|
|
|
+ wheresql.push_back('0');
|
|
|
+ }
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+template <typename T>
|
|
|
+ requires std::is_integral_v<T>
|
|
|
+M_MODEL& eqId(T val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" id = ");
|
|
|
+
|
|
|
+ wheresql.append(std::to_string(val));
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+template <typename T>
|
|
|
+ requires std::is_integral_v<T>
|
|
|
+M_MODEL& nqId(T val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" id != ");
|
|
|
+
|
|
|
+ wheresql.append(std::to_string(val));
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+template <typename T>
|
|
|
+ requires std::is_integral_v<T>
|
|
|
+M_MODEL& btId(T val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" id > ");
|
|
|
+
|
|
|
+ wheresql.append(std::to_string(val));
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+template <typename T>
|
|
|
+ requires std::is_integral_v<T>
|
|
|
+M_MODEL& beId(T val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" id >= ");
|
|
|
+
|
|
|
+ wheresql.append(std::to_string(val));
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+template <typename T>
|
|
|
+ requires std::is_integral_v<T>
|
|
|
+M_MODEL& ltId(T val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" id < ");
|
|
|
+
|
|
|
+ wheresql.append(std::to_string(val));
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+template <typename T>
|
|
|
+ requires std::is_integral_v<T>
|
|
|
+M_MODEL& leId(T val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" id <= ");
|
|
|
+
|
|
|
+ wheresql.append(std::to_string(val));
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+template <typename T>
|
|
|
+ requires std::is_integral_v<T>
|
|
|
+M_MODEL& or_eqId(T val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" id = ");
|
|
|
+
|
|
|
+ wheresql.append(std::to_string(val));
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+template <typename T>
|
|
|
+ requires std::is_integral_v<T>
|
|
|
+M_MODEL& or_nqId(T val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" id != ");
|
|
|
+
|
|
|
+ wheresql.append(std::to_string(val));
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+template <typename T>
|
|
|
+ requires std::is_integral_v<T>
|
|
|
+M_MODEL& or_btId(T val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" id > ");
|
|
|
+
|
|
|
+ wheresql.append(std::to_string(val));
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+template <typename T>
|
|
|
+ requires std::is_integral_v<T>
|
|
|
+M_MODEL& or_beId(T val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" id >= ");
|
|
|
+
|
|
|
+ wheresql.append(std::to_string(val));
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+template <typename T>
|
|
|
+ requires std::is_integral_v<T>
|
|
|
+M_MODEL& or_ltId(T val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" id < ");
|
|
|
+
|
|
|
+ wheresql.append(std::to_string(val));
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+template <typename T>
|
|
|
+ requires std::is_integral_v<T>
|
|
|
+M_MODEL& or_leId(T val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" id <= ");
|
|
|
+
|
|
|
+ wheresql.append(std::to_string(val));
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& nullMessage()
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message = NULL ");
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& nnullMessage()
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message != NULL ");
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& eqMessage(const std::string &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message = '");
|
|
|
+ wheresql.append(B_BASE::stringaddslash(val));
|
|
|
+ wheresql.push_back('\'');
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& nqMessage(const std::string &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message != '");
|
|
|
+ wheresql.append(B_BASE::stringaddslash(val));
|
|
|
+ wheresql.push_back('\'');
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& inMessage(const std::string &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message IN(");
|
|
|
+ wheresql.append(val);
|
|
|
+ wheresql.push_back(')');
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& inMessage(const std::vector<std::string> &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message IN(");
|
|
|
+
|
|
|
+ for(unsigned int i=0;i<val.size(); i++)
|
|
|
+ {
|
|
|
+ if(i>0)
|
|
|
+ {
|
|
|
+ wheresql.push_back(',');
|
|
|
+ }
|
|
|
+ wheresql.push_back('\'');
|
|
|
+ wheresql.append(B_BASE::stringaddslash(val[i]));
|
|
|
+ wheresql.push_back('\'');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+template <typename T>
|
|
|
+ requires std::is_integral_v<T>
|
|
|
+M_MODEL& inMessage(const std::vector<T> &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message IN(");
|
|
|
+
|
|
|
+ for(unsigned int i=0;i<val.size(); i++)
|
|
|
+ {
|
|
|
+ if(i>0)
|
|
|
+ {
|
|
|
+ wheresql.push_back(',');
|
|
|
+ }
|
|
|
+ wheresql.push_back('\'');
|
|
|
+ wheresql.append(std::to_string(val[i]));
|
|
|
+ wheresql.push_back('\'');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& ninMessage(const std::string &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message NOT IN(");
|
|
|
+ wheresql.append(val);
|
|
|
+ wheresql.push_back(')');
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& ninMessage(const std::vector<std::string> &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message NOT IN(");
|
|
|
+
|
|
|
+ for(unsigned int i=0;i<val.size(); i++)
|
|
|
+ {
|
|
|
+ if(i>0)
|
|
|
+ {
|
|
|
+ wheresql.push_back(',');
|
|
|
+ }
|
|
|
+ wheresql.push_back('\'');
|
|
|
+ wheresql.append(B_BASE::stringaddslash(val[i]));
|
|
|
+ wheresql.push_back('\'');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+template <typename T>
|
|
|
+ requires std::is_integral_v<T>
|
|
|
+M_MODEL& ninMessage(const std::vector<T> &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message NOT IN(");
|
|
|
+
|
|
|
+ for(unsigned int i=0;i<val.size(); i++)
|
|
|
+ {
|
|
|
+ if(i>0)
|
|
|
+ {
|
|
|
+ wheresql.push_back(',');
|
|
|
+ }
|
|
|
+ wheresql.push_back('\'');
|
|
|
+ wheresql.append(std::to_string(val[i]));
|
|
|
+ wheresql.push_back('\'');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& likeMessage(const std::string &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message LIKE '%");
|
|
|
+ wheresql.append(B_BASE::stringaddslash(val));
|
|
|
+ wheresql.append("%'");
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& l_likeMessage(const std::string &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message LIKE '%");
|
|
|
+ wheresql.append(B_BASE::stringaddslash(val));
|
|
|
+ wheresql.append("'");
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& r_likeMessage(const std::string &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message LIKE '");
|
|
|
+ wheresql.append(B_BASE::stringaddslash(val));
|
|
|
+ wheresql.append("%'");
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& btMessage(const std::string &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message > '");
|
|
|
+ wheresql.append(B_BASE::stringaddslash(val));
|
|
|
+ wheresql.push_back('\'');
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& beMessage(const std::string &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message >= '");
|
|
|
+ wheresql.append(B_BASE::stringaddslash(val));
|
|
|
+ wheresql.push_back('\'');
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& ltMessage(const std::string &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message < '");
|
|
|
+ wheresql.append(B_BASE::stringaddslash(val));
|
|
|
+ wheresql.push_back('\'');
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& leMessage(const std::string &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message <= '");
|
|
|
+ wheresql.append(B_BASE::stringaddslash(val));
|
|
|
+ wheresql.push_back('\'');
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& or_nullMessage()
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message = NULL ");
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& or_nnullMessage()
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message != NULL ");
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& or_eqMessage(const std::string &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message = '");
|
|
|
+ wheresql.append(B_BASE::stringaddslash(val));
|
|
|
+ wheresql.push_back('\'');
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& or_nqMessage(const std::string &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message != '");
|
|
|
+ wheresql.append(B_BASE::stringaddslash(val));
|
|
|
+ wheresql.push_back('\'');
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& or_inMessage(const std::string &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message IN(");
|
|
|
+ wheresql.append(val);
|
|
|
+ wheresql.push_back(')');
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& or_inMessage(const std::vector<std::string> &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message IN(");
|
|
|
+
|
|
|
+ for(unsigned int i=0;i<val.size(); i++)
|
|
|
+ {
|
|
|
+ if(i>0)
|
|
|
+ {
|
|
|
+ wheresql.push_back(',');
|
|
|
+ }
|
|
|
+ wheresql.push_back('\'');
|
|
|
+ wheresql.append(B_BASE::stringaddslash(val[i]));
|
|
|
+ wheresql.push_back('\'');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+template <typename T>
|
|
|
+ requires std::is_integral_v<T>
|
|
|
+M_MODEL& or_inMessage(const std::vector<T> &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message IN(");
|
|
|
+
|
|
|
+ for(unsigned int i=0;i<val.size(); i++)
|
|
|
+ {
|
|
|
+ if(i>0)
|
|
|
+ {
|
|
|
+ wheresql.push_back(',');
|
|
|
+ }
|
|
|
+ wheresql.push_back('\'');
|
|
|
+ wheresql.append(std::to_string(val[i]));
|
|
|
+ wheresql.push_back('\'');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& or_ninMessage(const std::string &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message NOT IN(");
|
|
|
+ wheresql.append(val);
|
|
|
+ wheresql.push_back(')');
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& or_ninMessage(const std::vector<std::string> &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message NOT IN(");
|
|
|
+
|
|
|
+ for(unsigned int i=0;i<val.size(); i++)
|
|
|
+ {
|
|
|
+ if(i>0)
|
|
|
+ {
|
|
|
+ wheresql.push_back(',');
|
|
|
+ }
|
|
|
+ wheresql.push_back('\'');
|
|
|
+ wheresql.append(B_BASE::stringaddslash(val[i]));
|
|
|
+ wheresql.push_back('\'');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+template <typename T>
|
|
|
+ requires std::is_integral_v<T>
|
|
|
+M_MODEL& or_ninMessage(const std::vector<T> &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message NOT IN(");
|
|
|
+
|
|
|
+ for(unsigned int i=0;i<val.size(); i++)
|
|
|
+ {
|
|
|
+ if(i>0)
|
|
|
+ {
|
|
|
+ wheresql.push_back(',');
|
|
|
+ }
|
|
|
+ wheresql.push_back('\'');
|
|
|
+ wheresql.append(std::to_string(val[i]));
|
|
|
+ wheresql.push_back('\'');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& or_likeMessage(const std::string &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message LIKE '%");
|
|
|
+ wheresql.append(B_BASE::stringaddslash(val));
|
|
|
+ wheresql.append("%'");
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& orl_likeMessage(const std::string &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message LIKE '%");
|
|
|
+ wheresql.append(B_BASE::stringaddslash(val));
|
|
|
+ wheresql.append("'");
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& orr_likeMessage(const std::string &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message LIKE '");
|
|
|
+ wheresql.append(B_BASE::stringaddslash(val));
|
|
|
+ wheresql.append("%'");
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& or_btMessage(const std::string &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message > '");
|
|
|
+ wheresql.append(B_BASE::stringaddslash(val));
|
|
|
+ wheresql.push_back('\'');
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& or_beMessage(const std::string &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message >= '");
|
|
|
+ wheresql.append(B_BASE::stringaddslash(val));
|
|
|
+ wheresql.push_back('\'');
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& or_ltMessage(const std::string &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message < '");
|
|
|
+ wheresql.append(B_BASE::stringaddslash(val));
|
|
|
+ wheresql.push_back('\'');
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+M_MODEL& or_leMessage(const std::string &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message <= '");
|
|
|
+ wheresql.append(B_BASE::stringaddslash(val));
|
|
|
+ wheresql.push_back('\'');
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+template <typename T>
|
|
|
+ requires std::is_floating_point_v<T>||std::is_integral_v<T>
|
|
|
+M_MODEL& eqMessage(T val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message = '");
|
|
|
+ wheresql.append(std::to_string(val));
|
|
|
+ wheresql.push_back('\'');
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+template <typename T>
|
|
|
+ requires std::is_floating_point_v<T>||std::is_integral_v<T>
|
|
|
+M_MODEL& nqMessage(T val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message != '");
|
|
|
+ wheresql.append(std::to_string(val));
|
|
|
+ wheresql.push_back('\'');
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+template <typename T>
|
|
|
+ requires std::is_floating_point_v<T>||std::is_integral_v<T>
|
|
|
+M_MODEL& btMessage(T val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message > '");
|
|
|
+ wheresql.append(std::to_string(val));
|
|
|
+ wheresql.push_back('\'');
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+template <typename T>
|
|
|
+ requires std::is_floating_point_v<T>||std::is_integral_v<T>
|
|
|
+M_MODEL& beMessage(T val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message >= '");
|
|
|
+ wheresql.append(std::to_string(val));
|
|
|
+ wheresql.push_back('\'');
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+template <typename T>
|
|
|
+ requires std::is_floating_point_v<T>||std::is_integral_v<T>
|
|
|
+M_MODEL& ltMessage(T val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message < '");
|
|
|
+ wheresql.append(std::to_string(val));
|
|
|
+ wheresql.push_back('\'');
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+template <typename T>
|
|
|
+ requires std::is_floating_point_v<T>||std::is_integral_v<T>
|
|
|
+M_MODEL& leMessage(T val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message <= '");
|
|
|
+ wheresql.append(std::to_string(val));
|
|
|
+ wheresql.push_back('\'');
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+template <typename T>
|
|
|
+ requires std::is_floating_point_v<T>||std::is_integral_v<T>
|
|
|
+M_MODEL& or_eqMessage(T val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message = '");
|
|
|
+ wheresql.append(std::to_string(val));
|
|
|
+ wheresql.push_back('\'');
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+template <typename T>
|
|
|
+ requires std::is_floating_point_v<T>||std::is_integral_v<T>
|
|
|
+M_MODEL& or_nqMessage(T val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message != '");
|
|
|
+ wheresql.append(std::to_string(val));
|
|
|
+ wheresql.push_back('\'');
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+template <typename T>
|
|
|
+ requires std::is_floating_point_v<T>||std::is_integral_v<T>
|
|
|
+M_MODEL& or_btMessage(T val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message > '");
|
|
|
+ wheresql.append(std::to_string(val));
|
|
|
+ wheresql.push_back('\'');
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+template <typename T>
|
|
|
+ requires std::is_floating_point_v<T>||std::is_integral_v<T>
|
|
|
+M_MODEL& or_beMessage(T val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message >= '");
|
|
|
+ wheresql.append(std::to_string(val));
|
|
|
+ wheresql.push_back('\'');
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+template <typename T>
|
|
|
+ requires std::is_floating_point_v<T>||std::is_integral_v<T>
|
|
|
+M_MODEL& or_ltMessage(T val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message < '");
|
|
|
+ wheresql.append(std::to_string(val));
|
|
|
+ wheresql.push_back('\'');
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+template <typename T>
|
|
|
+ requires std::is_floating_point_v<T>||std::is_integral_v<T>
|
|
|
+M_MODEL& or_leMessage(T val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" message <= '");
|
|
|
+ wheresql.append(std::to_string(val));
|
|
|
+ wheresql.push_back('\'');
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ M_MODEL &select(const std::string &fieldname)
|
|
|
+ {
|
|
|
+ if (selectsql.size() > 0)
|
|
|
+ {
|
|
|
+ selectsql.push_back(',');
|
|
|
+ }
|
|
|
+ selectsql.append(fieldname);
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+ M_MODEL &where(const std::string &wq)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ wheresql.append(wq);
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+ template <typename _SQL_Value>
|
|
|
+ requires std::is_integral_v<_SQL_Value> || std::is_floating_point_v<_SQL_Value>
|
|
|
+ M_MODEL &where(const std::string &wq, _SQL_Value val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(wq);
|
|
|
+ char bi = wq.back();
|
|
|
+ if (bi == '=' || bi == '>' || bi == '<')
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ wheresql.push_back('=');
|
|
|
+ }
|
|
|
+
|
|
|
+ std::stringstream _stream;
|
|
|
+ _stream << val;
|
|
|
+ wheresql.append(_stream.str());
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+ M_MODEL &where(const std::string &wq, char bi, http::OBJ_VALUE &obj)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(wq);
|
|
|
+ wheresql.push_back(bi);
|
|
|
+ if (obj.is_string())
|
|
|
+ {
|
|
|
+ wheresql.push_back('\'');
|
|
|
+ wheresql.append(obj.as_string());
|
|
|
+ wheresql.push_back('\'');
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ wheresql.append(obj.to_string());
|
|
|
+ }
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+ M_MODEL &where(const std::string &wq, http::OBJ_VALUE &obj)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(wq);
|
|
|
+ char bi = wq.back();
|
|
|
+ if (bi == '=' || bi == '>' || bi == '<')
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ wheresql.push_back('=');
|
|
|
+ }
|
|
|
+
|
|
|
+ if (obj.is_string())
|
|
|
+ {
|
|
|
+ wheresql.push_back('\'');
|
|
|
+ wheresql.append(obj.as_string());
|
|
|
+ wheresql.push_back('\'');
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ wheresql.append(obj.to_string());
|
|
|
+ }
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+ template <typename _SQL_Value>
|
|
|
+ requires std::is_integral_v<_SQL_Value> || std::is_floating_point_v<_SQL_Value>
|
|
|
+ M_MODEL &where(const std::string &wq, char bi, _SQL_Value val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(wq);
|
|
|
+ wheresql.push_back(bi);
|
|
|
+ std::stringstream _stream;
|
|
|
+ _stream << val;
|
|
|
+ wheresql.append(_stream.str());
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+ M_MODEL &where(const std::string &wq, char bi, const std::string &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(wq);
|
|
|
+ wheresql.push_back(bi);
|
|
|
+ wheresql.push_back('\'');
|
|
|
+
|
|
|
+ wheresql.append(val);
|
|
|
+ wheresql.push_back('\'');
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+ M_MODEL &where(const std::string &wq, const std::string &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(wq);
|
|
|
+ char bi = wq.back();
|
|
|
+ if (bi == '=' || bi == '>' || bi == '<')
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ wheresql.push_back('=');
|
|
|
+ }
|
|
|
+
|
|
|
+ wheresql.push_back('\'');
|
|
|
+ wheresql.append(val);
|
|
|
+ wheresql.push_back('\'');
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+ M_MODEL &between(const std::string &wq, const std::string &a, const std::string &b)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" (");
|
|
|
+ wheresql.append(wq);
|
|
|
+ wheresql.append(" BETWEEN '");
|
|
|
+ std::stringstream _stream;
|
|
|
+ _stream << a;
|
|
|
+ _stream << "' AND '";
|
|
|
+ _stream << b;
|
|
|
+ _stream << "' ) ";
|
|
|
+ wheresql.append(_stream.str());
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+ template <typename _SQL_Value>
|
|
|
+ requires std::is_integral_v<_SQL_Value> || std::is_floating_point_v<_SQL_Value>
|
|
|
+ M_MODEL &between(const std::string &wq, _SQL_Value a, _SQL_Value b)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" (");
|
|
|
+ wheresql.append(wq);
|
|
|
+ wheresql.append(" BETWEEN ");
|
|
|
+ std::stringstream _stream;
|
|
|
+ _stream << a;
|
|
|
+ _stream << " AND ";
|
|
|
+ _stream << b;
|
|
|
+ _stream << " ) ";
|
|
|
+ wheresql.append(_stream.str());
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+ template <typename _SQL_Value>
|
|
|
+ requires std::is_integral_v<_SQL_Value> || std::is_floating_point_v<_SQL_Value>
|
|
|
+ M_MODEL &orBetween(const std::string &wq, _SQL_Value a, _SQL_Value b)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(" (");
|
|
|
+ wheresql.append(wq);
|
|
|
+ wheresql.append(" BETWEEN ");
|
|
|
+ std::stringstream _stream;
|
|
|
+ _stream << a;
|
|
|
+ _stream << " AND ";
|
|
|
+ _stream << b;
|
|
|
+ _stream << " ) ";
|
|
|
+ wheresql.append(_stream.str());
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+ M_MODEL &whereLike(const std::string &wq, const std::string &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(wq);
|
|
|
+ wheresql.append(" like '");
|
|
|
+ if (val.size() > 0 && (val[0] == '%' || val.back() == '%'))
|
|
|
+ {
|
|
|
+ wheresql.append(val);
|
|
|
+ wheresql.append("' ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ wheresql.push_back('%');
|
|
|
+ wheresql.append(val);
|
|
|
+ wheresql.append("%' ");
|
|
|
+ }
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+ M_MODEL &whereLikeLeft(const std::string &wq, const std::string &val)
|
|
|
+ {
|
|
|
+
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(wq);
|
|
|
+ wheresql.append(" like '");
|
|
|
+ wheresql.push_back('%');
|
|
|
+ wheresql.append(val);
|
|
|
+ wheresql.append("' ");
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+ M_MODEL &whereLikeRight(const std::string &wq, const std::string &val)
|
|
|
+ {
|
|
|
+
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(wq);
|
|
|
+ wheresql.append(" like '");
|
|
|
+ wheresql.append(val);
|
|
|
+ wheresql.append("%' ");
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+ M_MODEL &whereOrLike(const std::string &wq, const std::string &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(wq);
|
|
|
+ wheresql.append(" like '");
|
|
|
+ if (val[0] == '%' || val.back() == '%')
|
|
|
+ {
|
|
|
+ wheresql.append(val);
|
|
|
+ wheresql.append("' ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ wheresql.push_back('%');
|
|
|
+ wheresql.append(val);
|
|
|
+ wheresql.append("%' ");
|
|
|
+ }
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+ M_MODEL &whereAnd(const std::string &wq)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(wq);
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+ template <typename _SQL_Value>
|
|
|
+ requires std::is_integral_v<_SQL_Value> || std::is_floating_point_v<_SQL_Value>
|
|
|
+ M_MODEL &whereAnd(const std::string &wq, _SQL_Value val)
|
|
|
+ {
|
|
|
+
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(wq);
|
|
|
+ char bi = wq.back();
|
|
|
+ if (bi == '=' || bi == '>' || bi == '<')
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ wheresql.push_back('=');
|
|
|
+ }
|
|
|
+ std::stringstream _stream;
|
|
|
+ _stream << val;
|
|
|
+ wheresql.append(_stream.str());
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+ M_MODEL &whereAnd(const std::string &wq, const std::string &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(wq);
|
|
|
+ char bi = wq.back();
|
|
|
+ if (bi == '=' || bi == '>' || bi == '<')
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ wheresql.push_back('=');
|
|
|
+ }
|
|
|
+
|
|
|
+ wheresql.push_back('\'');
|
|
|
+ wheresql.append(val);
|
|
|
+ wheresql.push_back('\'');
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+ M_MODEL &whereOr(const std::string &wq)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(wq);
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+ template <typename _SQL_Value>
|
|
|
+ requires std::is_integral_v<_SQL_Value> || std::is_floating_point_v<_SQL_Value>
|
|
|
+ M_MODEL &whereOr(const std::string &wq, _SQL_Value val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(wq);
|
|
|
+ char bi = wq.back();
|
|
|
+ if (bi == '=' || bi == '>' || bi == '<')
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ wheresql.push_back('=');
|
|
|
+ }
|
|
|
+ std::stringstream _stream;
|
|
|
+ _stream << val;
|
|
|
+ wheresql.append(_stream.str());
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+ M_MODEL &whereOr(const std::string &wq, const std::string &val)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" OR ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(wq);
|
|
|
+ char bi = wq.back();
|
|
|
+ if (bi == '=' || bi == '>' || bi == '<')
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ wheresql.push_back('=');
|
|
|
+ }
|
|
|
+
|
|
|
+ wheresql.push_back('\'');
|
|
|
+ wheresql.append(val);
|
|
|
+ wheresql.push_back('\'');
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+ M_MODEL &whereIn(const std::string &k)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(k);
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+ M_MODEL &whereIn(const std::string &k, const std::string &a)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ wheresql.append(k);
|
|
|
+ wheresql.append(" IN(");
|
|
|
+ wheresql.append(a);
|
|
|
+ wheresql.append(") ");
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+ M_MODEL &whereIn(const std::string &k, const std::vector<std::string> &a)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+ wheresql.append(k);
|
|
|
+ wheresql.append(" in(");
|
|
|
+ int i = 0;
|
|
|
+ for (auto &key : a)
|
|
|
+ {
|
|
|
+ if (i > 0)
|
|
|
+ {
|
|
|
+ wheresql.append(",\'");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ wheresql.append("\'");
|
|
|
+ }
|
|
|
+ wheresql.append(key);
|
|
|
+ wheresql.append("\'");
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ wheresql.append(") ");
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+ M_MODEL &whereNotIn(const std::string &k, const std::vector<std::string> &a)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ wheresql.append(k);
|
|
|
+ wheresql.append(" NOT IN(");
|
|
|
+ int i = 0;
|
|
|
+ for (auto &key : a)
|
|
|
+ {
|
|
|
+ if (i > 0)
|
|
|
+ {
|
|
|
+ wheresql.append(",\'");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ wheresql.append("\'");
|
|
|
+ }
|
|
|
+ wheresql.append(key);
|
|
|
+ wheresql.append("\'");
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ wheresql.append(") ");
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+ template <typename _SQL_Value>
|
|
|
+ requires std::is_integral_v<_SQL_Value> || std::is_floating_point_v<_SQL_Value>
|
|
|
+ M_MODEL &whereIn(const std::string &k, const std::list<_SQL_Value> &a)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ wheresql.append(k);
|
|
|
+ wheresql.append(" in(");
|
|
|
+ int i = 0;
|
|
|
+ std::stringstream _stream;
|
|
|
+ for (auto &key : a)
|
|
|
+ {
|
|
|
+ if (i > 0)
|
|
|
+ {
|
|
|
+ wheresql.append(",");
|
|
|
+ }
|
|
|
+ _stream << key;
|
|
|
+ wheresql.append(_stream.str());
|
|
|
+ i++;
|
|
|
+ _stream.str("");
|
|
|
+ }
|
|
|
+ wheresql.append(") ");
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+ template <typename _SQL_Value>
|
|
|
+ requires std::is_integral_v<_SQL_Value> || std::is_floating_point_v<_SQL_Value>
|
|
|
+ M_MODEL &whereIn(const std::string &k, const std::vector<_SQL_Value> &a)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ wheresql.append(k);
|
|
|
+ wheresql.append(" IN(");
|
|
|
+ int i = 0;
|
|
|
+ std::stringstream _stream;
|
|
|
+ for (auto &key : a)
|
|
|
+ {
|
|
|
+ if (i > 0)
|
|
|
+ {
|
|
|
+ wheresql.append(",");
|
|
|
+ }
|
|
|
+ _stream << key;
|
|
|
+ wheresql.append(_stream.str());
|
|
|
+ i++;
|
|
|
+ _stream.str("");
|
|
|
+ }
|
|
|
+ wheresql.append(") ");
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+ template <typename _SQL_Value>
|
|
|
+ requires std::is_integral_v<_SQL_Value> || std::is_floating_point_v<_SQL_Value>
|
|
|
+ M_MODEL &whereNotIn(const std::string &k, const std::vector<_SQL_Value> &a)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (ishascontent)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!iskuohao)
|
|
|
+ {
|
|
|
+ wheresql.append(" AND ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (iskuohao)
|
|
|
+ {
|
|
|
+ ishascontent = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ wheresql.append(k);
|
|
|
+ wheresql.append(" NOT IN(");
|
|
|
+ int i = 0;
|
|
|
+ std::stringstream _stream;
|
|
|
+ for (auto &key : a)
|
|
|
+ {
|
|
|
+ if (i > 0)
|
|
|
+ {
|
|
|
+ wheresql.append(",");
|
|
|
+ }
|
|
|
+ _stream << key;
|
|
|
+ wheresql.append(_stream.str());
|
|
|
+ i++;
|
|
|
+ _stream.str("");
|
|
|
+ }
|
|
|
+ wheresql.append(") ");
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+ M_MODEL &order(const std::string &wq)
|
|
|
+ {
|
|
|
+ ordersql.append(" ORDER by ");
|
|
|
+ ordersql.append(wq);
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+ M_MODEL &asc(const std::string &wq)
|
|
|
+ {
|
|
|
+
|
|
|
+ ordersql.append(" ORDER by ");
|
|
|
+ ordersql.append(wq);
|
|
|
+ ordersql.append(" ASC ");
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+ M_MODEL &desc(const std::string &wq)
|
|
|
+ {
|
|
|
+
|
|
|
+ ordersql.append(" ORDER by ");
|
|
|
+ ordersql.append(wq);
|
|
|
+ ordersql.append(" DESC ");
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+ M_MODEL &having(const std::string &wq)
|
|
|
+ {
|
|
|
+
|
|
|
+ groupsql.append(" HAVING by ");
|
|
|
+ groupsql.append(wq);
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+ M_MODEL &group(const std::string &wq)
|
|
|
+ {
|
|
|
+
|
|
|
+ groupsql.append(" GROUP BY ");
|
|
|
+ groupsql.append(wq);
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+ M_MODEL &orsub()
|
|
|
+ {
|
|
|
+
|
|
|
+ if (iskuohao == true)
|
|
|
+ {
|
|
|
+ iskuohao = false;
|
|
|
+ ishascontent = false;
|
|
|
+ wheresql.append(" )");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ wheresql.append(" OR (");
|
|
|
+ iskuohao = true;
|
|
|
+ ishascontent = false;
|
|
|
+ }
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+ M_MODEL &andsub()
|
|
|
+ {
|
|
|
+
|
|
|
+ if (iskuohao == true)
|
|
|
+ {
|
|
|
+ iskuohao = false;
|
|
|
+ wheresql.append(" )");
|
|
|
+ ishascontent = false;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ wheresql.append(" AND (");
|
|
|
+ iskuohao = true;
|
|
|
+ ishascontent = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+ M_MODEL &endsub()
|
|
|
+ {
|
|
|
+ if (iskuohao == true)
|
|
|
+ {
|
|
|
+ iskuohao = false;
|
|
|
+ ishascontent = false;
|
|
|
+ wheresql.append(" )");
|
|
|
+ }
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+ M_MODEL &or_b()
|
|
|
+ {
|
|
|
+
|
|
|
+ if (iskuohao == true)
|
|
|
+ {
|
|
|
+ iskuohao = false;
|
|
|
+ ishascontent = false;
|
|
|
+ wheresql.append(" )");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ wheresql.append(" OR (");
|
|
|
+ iskuohao = true;
|
|
|
+ ishascontent = false;
|
|
|
+ }
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+ M_MODEL &and_b()
|
|
|
+ {
|
|
|
+
|
|
|
+ if (iskuohao == true)
|
|
|
+ {
|
|
|
+ iskuohao = false;
|
|
|
+ wheresql.append(" )");
|
|
|
+ ishascontent = false;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ wheresql.append(" AND (");
|
|
|
+ iskuohao = true;
|
|
|
+ ishascontent = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+ M_MODEL &or_e()
|
|
|
+ {
|
|
|
+ if (iskuohao == true)
|
|
|
+ {
|
|
|
+ iskuohao = false;
|
|
|
+ ishascontent = false;
|
|
|
+ wheresql.append(" )");
|
|
|
+ }
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+ M_MODEL &and_e()
|
|
|
+ {
|
|
|
+ if (iskuohao == true)
|
|
|
+ {
|
|
|
+ iskuohao = false;
|
|
|
+ ishascontent = false;
|
|
|
+ wheresql.append(" )");
|
|
|
+ }
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+ M_MODEL &limit(unsigned int num)
|
|
|
+ {
|
|
|
+ limitsql.clear();
|
|
|
+ limitsql.append(" limit ");
|
|
|
+ limitsql.append(std::to_string(num));
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+ M_MODEL &limit(unsigned int num, unsigned int endnum)
|
|
|
+ {
|
|
|
+ limitsql.clear();
|
|
|
+ limitsql.append(" limit ");
|
|
|
+ limitsql.append(std::to_string(num));
|
|
|
+ limitsql.push_back(',');
|
|
|
+ limitsql.append(std::to_string(endnum));
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+ std::vector<std::map<std::string, std::string>> fetch_obj()
|
|
|
+ {
|
|
|
+ effect_num = 0;
|
|
|
+ if (selectsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring = "SELECT * FROM ";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sqlstring = "SELECT ";
|
|
|
+ sqlstring.append(selectsql);
|
|
|
+ sqlstring.append(" FROM ");
|
|
|
+ }
|
|
|
+
|
|
|
+ sqlstring.append(B_BASE::tablename);
|
|
|
+ sqlstring.append(" WHERE ");
|
|
|
+
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(" 1 ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sqlstring.append(wheresql);
|
|
|
+ }
|
|
|
+ if (!groupsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(groupsql);
|
|
|
+ }
|
|
|
+ if (!ordersql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(ordersql);
|
|
|
+ }
|
|
|
+ if (!limitsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(limitsql);
|
|
|
+ }
|
|
|
+
|
|
|
+ std::vector<std::map<std::string, std::string>> temprecord;
|
|
|
+
|
|
|
+ if (iserror)
|
|
|
+ {
|
|
|
+ return temprecord;
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ effect_num = 0;
|
|
|
+ if (conn_empty())
|
|
|
+ {
|
|
|
+ return temprecord;
|
|
|
+ }
|
|
|
+ auto conn = conn_obj->get_select_conn();
|
|
|
+
|
|
|
+ unsigned int querysql_len = sqlstring.length() + 1;
|
|
|
+
|
|
|
+ conn->send_data.clear();
|
|
|
+ conn->send_data.push_back((querysql_len & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 8 & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 16 & 0xFF));
|
|
|
+ conn->send_data.push_back(0x00);
|
|
|
+ conn->send_data.push_back(0x03);
|
|
|
+ conn->send_data.append(sqlstring);
|
|
|
+
|
|
|
+ std::size_t n = asio::write(*conn->socket, asio::buffer(conn->send_data), conn->ec);
|
|
|
+
|
|
|
+ if(conn->ec)
|
|
|
+ {
|
|
|
+ error_msg = conn->ec.message();
|
|
|
+ iserror = true;
|
|
|
+ return temprecord;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ pack_info_t temp_pack_data;
|
|
|
+ temp_pack_data.seq_id = 1;
|
|
|
+ bool is_sql_item = false;
|
|
|
+ std::vector<field_info_t> field_array;
|
|
|
+ unsigned char action_setup = 0;
|
|
|
+ unsigned int column_num = 0;
|
|
|
+ unsigned int offset = 0;
|
|
|
+
|
|
|
+ std::vector<unsigned char> field_pos;
|
|
|
+
|
|
|
+ for (; is_sql_item == false;)
|
|
|
+ {
|
|
|
+ n = conn->read_loop();
|
|
|
+ offset = 0;
|
|
|
+ for (; offset < n;)
|
|
|
+ {
|
|
|
+ conn->read_field_pack(conn->_cache_data, n, offset, temp_pack_data);
|
|
|
+ if (temp_pack_data.length == temp_pack_data.current_length)
|
|
|
+ {
|
|
|
+ if (conn->pack_eof_check(temp_pack_data))
|
|
|
+ {
|
|
|
+ is_sql_item = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (action_setup == 0)
|
|
|
+ {
|
|
|
+ if (temp_pack_data.length == 2 && (unsigned char)temp_pack_data.data[0] < 251 && (unsigned char)temp_pack_data.data[0] > 0)
|
|
|
+ {
|
|
|
+ action_setup = 1;
|
|
|
+ column_num = (unsigned char)temp_pack_data.data[0];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (action_setup == 1)
|
|
|
+ {
|
|
|
+ field_info_t temp_filed_col;
|
|
|
+ conn->read_col_info(temp_pack_data.data, temp_filed_col);
|
|
|
+
|
|
|
+ field_array.emplace_back(std::move(temp_filed_col));
|
|
|
+ column_num--;
|
|
|
+ if (column_num == 0)
|
|
|
+ {
|
|
|
+ action_setup = 2;
|
|
|
+ for (unsigned int ii = 0; ii < field_array.size(); ii++)
|
|
|
+ {
|
|
|
+ field_pos.push_back(B_BASE::findcolpos(field_array[ii].org_name));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (action_setup == 2)
|
|
|
+ {
|
|
|
+ unsigned int column_num = field_array.size();
|
|
|
+ unsigned int tempnum = 0;
|
|
|
+
|
|
|
+ std::map<std::string, std::string> data_temp;
|
|
|
+ for (unsigned int ij = 0; ij < column_num; ij++)
|
|
|
+ {
|
|
|
+ unsigned long long name_length = 0;
|
|
|
+ name_length = conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], tempnum);
|
|
|
+
|
|
|
+ std::string temp_str;
|
|
|
+ temp_str.resize(name_length);
|
|
|
+ std::memcpy(temp_str.data(), (unsigned char *)&temp_pack_data.data[tempnum], name_length);
|
|
|
+ if (field_array[ij].name.size() > 0)
|
|
|
+ {
|
|
|
+ data_temp.insert({field_array[ij].name, std::move(temp_str)});
|
|
|
+ }
|
|
|
+ else if (field_array[ij].org_name.size() > 0)
|
|
|
+ {
|
|
|
+ data_temp.insert({field_array[ij].org_name, std::move(temp_str)});
|
|
|
+ }
|
|
|
+
|
|
|
+ tempnum = tempnum + name_length;
|
|
|
+ }
|
|
|
+ temprecord.emplace_back(std::move(data_temp));
|
|
|
+ effect_num++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (offset >= n)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ is_sql_item = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ conn_obj->back_select_conn(conn);
|
|
|
+
|
|
|
+ if (iscache)
|
|
|
+ {
|
|
|
+ if (exptime > 0)
|
|
|
+ {
|
|
|
+ save_cache(exptime);
|
|
|
+ exptime = 0;
|
|
|
+ iscache = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (const std::exception &e)
|
|
|
+ {
|
|
|
+ error_msg = std::string(e.what());
|
|
|
+ }
|
|
|
+ catch (const std::string &e)
|
|
|
+ {
|
|
|
+ error_msg = e;
|
|
|
+ }
|
|
|
+ catch (...)
|
|
|
+ {
|
|
|
+ }
|
|
|
+ return temprecord;
|
|
|
+ }
|
|
|
+ std::tuple<std::vector<std::string>, std::map<std::string, unsigned int>, std::vector<std::vector<std::string>>>
|
|
|
+ fetch_row()
|
|
|
+ {
|
|
|
+ effect_num = 0;
|
|
|
+ if (selectsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring = "SELECT * FROM ";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sqlstring = "SELECT ";
|
|
|
+ sqlstring.append(selectsql);
|
|
|
+ sqlstring.append(" FROM ");
|
|
|
+ }
|
|
|
+
|
|
|
+ sqlstring.append(B_BASE::tablename);
|
|
|
+ sqlstring.append(" WHERE ");
|
|
|
+
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(" 1 ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sqlstring.append(wheresql);
|
|
|
+ }
|
|
|
+ if (!groupsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(groupsql);
|
|
|
+ }
|
|
|
+ if (!ordersql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(ordersql);
|
|
|
+ }
|
|
|
+ if (!limitsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(limitsql);
|
|
|
+ }
|
|
|
+
|
|
|
+ std::vector<std::vector<std::string>> temprecord;
|
|
|
+ std::vector<std::string> table_fieldname;
|
|
|
+ std::map<std::string, unsigned int> table_fieldmap;
|
|
|
+
|
|
|
+ if (iscache)
|
|
|
+ {
|
|
|
+ std::size_t sqlhashid = std::hash<std::string>{}(sqlstring);
|
|
|
+
|
|
|
+ model_meta_cache<std::vector<std::string>> &temp_cache =
|
|
|
+ model_meta_cache<std::vector<std::string>>::getinstance();
|
|
|
+ temprecord = temp_cache.get(sqlhashid);
|
|
|
+ if (temprecord.size() > 0)
|
|
|
+ {
|
|
|
+ iscache = false;
|
|
|
+ model_meta_cache<std::string> &table_cache = model_meta_cache<std::string>::getinstance();
|
|
|
+ table_fieldname = table_cache.get(sqlhashid);
|
|
|
+
|
|
|
+ model_meta_cache<std::map<std::string, unsigned int>> &tablemap_cache =
|
|
|
+ model_meta_cache<std::map<std::string, unsigned int>>::getinstance();
|
|
|
+ table_fieldmap = tablemap_cache.get_obj(sqlhashid);
|
|
|
+
|
|
|
+ return std::make_tuple(table_fieldname, table_fieldmap, temprecord);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iserror)
|
|
|
+ {
|
|
|
+ return std::make_tuple(table_fieldname, table_fieldmap, temprecord);
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (conn_empty())
|
|
|
+ {
|
|
|
+ return std::make_tuple(table_fieldname, table_fieldmap, temprecord);
|
|
|
+ }
|
|
|
+ auto conn = conn_obj->get_select_conn();
|
|
|
+
|
|
|
+ unsigned int querysql_len = sqlstring.length() + 1;
|
|
|
+
|
|
|
+ conn->send_data.clear();
|
|
|
+
|
|
|
+ conn->send_data.push_back((querysql_len & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 8 & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 16 & 0xFF));
|
|
|
+ conn->send_data.push_back(0x00);
|
|
|
+ conn->send_data.push_back(0x03);
|
|
|
+ conn->send_data.append(sqlstring);
|
|
|
+
|
|
|
+ std::size_t n = asio::write(*conn->socket, asio::buffer(conn->send_data), conn->ec);
|
|
|
+
|
|
|
+ if(conn->ec)
|
|
|
+ {
|
|
|
+ error_msg = conn->ec.message();
|
|
|
+ iserror = true;
|
|
|
+ return std::make_tuple(table_fieldname, table_fieldmap, temprecord);
|
|
|
+ }
|
|
|
+
|
|
|
+ pack_info_t temp_pack_data;
|
|
|
+ temp_pack_data.seq_id = 1;
|
|
|
+ bool is_sql_item = false;
|
|
|
+ std::vector<field_info_t> field_array;
|
|
|
+ // std::vector<std::vector<std::string>> field_value;
|
|
|
+
|
|
|
+ unsigned char action_setup = 0;
|
|
|
+ unsigned int column_num = 0;
|
|
|
+
|
|
|
+ unsigned int offset = 0;
|
|
|
+
|
|
|
+ std::vector<unsigned char> field_pos;
|
|
|
+
|
|
|
+ for (; is_sql_item == false;)
|
|
|
+ {
|
|
|
+ n = conn->read_loop();
|
|
|
+ offset = 0;
|
|
|
+ for (; offset < n;)
|
|
|
+ {
|
|
|
+ conn->read_field_pack(conn->_cache_data, n, offset, temp_pack_data);
|
|
|
+ if (temp_pack_data.length == temp_pack_data.current_length)
|
|
|
+ {
|
|
|
+ if (conn->pack_eof_check(temp_pack_data))
|
|
|
+ {
|
|
|
+ is_sql_item = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (action_setup == 0)
|
|
|
+ {
|
|
|
+ if (temp_pack_data.length == 2 && (unsigned char)temp_pack_data.data[0] < 251 && (unsigned char)temp_pack_data.data[0] > 0)
|
|
|
+ {
|
|
|
+ action_setup = 1;
|
|
|
+ column_num = (unsigned char)temp_pack_data.data[0];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (action_setup == 1)
|
|
|
+ {
|
|
|
+ field_info_t temp_filed_col;
|
|
|
+ conn->read_col_info(temp_pack_data.data, temp_filed_col);
|
|
|
+
|
|
|
+ field_array.emplace_back(std::move(temp_filed_col));
|
|
|
+ column_num--;
|
|
|
+ if (column_num == 0)
|
|
|
+ {
|
|
|
+ action_setup = 2;
|
|
|
+ for (unsigned int ii = 0; ii < field_array.size(); ii++)
|
|
|
+ {
|
|
|
+ field_pos.push_back(B_BASE::findcolpos(field_array[ii].org_name));
|
|
|
+ table_fieldmap.insert({field_array[ii].org_name,table_fieldname.size()});
|
|
|
+ table_fieldname.push_back(field_array[ii].org_name);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (action_setup == 2)
|
|
|
+ {
|
|
|
+ unsigned int column_num = field_array.size();
|
|
|
+ unsigned int tempnum = 0;
|
|
|
+
|
|
|
+ std::vector<std::string> temp_v_record;
|
|
|
+ for (unsigned int ij = 0; ij < column_num; ij++)
|
|
|
+ {
|
|
|
+ unsigned long long name_length = 0;
|
|
|
+ name_length = conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], tempnum);
|
|
|
+ std::string tempstr;
|
|
|
+ tempstr.resize(name_length);
|
|
|
+ std::memcpy(tempstr.data(), (unsigned char *)&temp_pack_data.data[tempnum], name_length);
|
|
|
+ temp_v_record.push_back(std::move(tempstr));
|
|
|
+ tempnum = tempnum + name_length;
|
|
|
+ }
|
|
|
+ temprecord.push_back(temp_v_record);
|
|
|
+ effect_num++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (offset >= n)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ is_sql_item = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ conn_obj->back_select_conn(conn);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (iscache)
|
|
|
+ {
|
|
|
+ if (exptime > 0)
|
|
|
+ {
|
|
|
+ if (temprecord.size() > 0)
|
|
|
+ {
|
|
|
+ std::size_t sqlhashid = std::hash<std::string>{}(sqlstring);
|
|
|
+
|
|
|
+ model_meta_cache<std::vector<std::string>> &temp_cache =
|
|
|
+ model_meta_cache<std::vector<std::string>>::getinstance();
|
|
|
+ temp_cache.save(sqlhashid, temprecord, exptime);
|
|
|
+
|
|
|
+ exptime += 1;
|
|
|
+ model_meta_cache<std::string> &table_cache = model_meta_cache<std::string>::getinstance();
|
|
|
+ table_cache.save(sqlhashid, table_fieldname, exptime);
|
|
|
+
|
|
|
+ model_meta_cache<std::map<std::string, unsigned int>> &tablemap_cache =
|
|
|
+ model_meta_cache<std::map<std::string, unsigned int>>::getinstance();
|
|
|
+ tablemap_cache.save(sqlhashid, table_fieldmap, exptime);
|
|
|
+ exptime = 0;
|
|
|
+ iscache = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return std::make_tuple(std::move(table_fieldname), std::move(table_fieldmap), std::move(temprecord));
|
|
|
+ }
|
|
|
+ catch (const std::exception &e)
|
|
|
+ {
|
|
|
+ error_msg = std::string(e.what());
|
|
|
+ }
|
|
|
+ catch (const std::string &e)
|
|
|
+ {
|
|
|
+ error_msg = e;
|
|
|
+ }
|
|
|
+ catch (...)
|
|
|
+ {
|
|
|
+ }
|
|
|
+ return std::make_tuple(table_fieldname, table_fieldmap, temprecord);
|
|
|
+ }
|
|
|
+ M_MODEL &fetch()
|
|
|
+ {
|
|
|
+ effect_num = 0;
|
|
|
+ if (selectsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring = "SELECT * FROM ";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sqlstring = "SELECT ";
|
|
|
+ sqlstring.append(selectsql);
|
|
|
+ sqlstring.append(" FROM ");
|
|
|
+ }
|
|
|
+
|
|
|
+ sqlstring.append(B_BASE::tablename);
|
|
|
+ sqlstring.append(" WHERE ");
|
|
|
+
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(" 1 ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sqlstring.append(wheresql);
|
|
|
+ }
|
|
|
+ if (!groupsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(groupsql);
|
|
|
+ }
|
|
|
+ if (!ordersql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(ordersql);
|
|
|
+ }
|
|
|
+ if (!limitsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(limitsql);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iscache)
|
|
|
+ {
|
|
|
+ std::size_t sqlhashid = std::hash<std::string>{}(sqlstring);
|
|
|
+ if (get_cacherecord(sqlhashid))
|
|
|
+ {
|
|
|
+ iscache = false;
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ B_BASE::record_reset();
|
|
|
+ if (iserror)
|
|
|
+ {
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (conn_empty())
|
|
|
+ {
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+ auto conn = conn_obj->get_select_conn();
|
|
|
+
|
|
|
+ unsigned int querysql_len = sqlstring.length() + 1;
|
|
|
+
|
|
|
+ conn->send_data.clear();
|
|
|
+
|
|
|
+ conn->send_data.push_back((querysql_len & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 8 & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 16 & 0xFF));
|
|
|
+ conn->send_data.push_back(0x00);
|
|
|
+ conn->send_data.push_back(0x03);
|
|
|
+ conn->send_data.append(sqlstring);
|
|
|
+
|
|
|
+ std::size_t n = asio::write(*conn->socket, asio::buffer(conn->send_data), conn->ec);
|
|
|
+
|
|
|
+ if(conn->ec)
|
|
|
+ {
|
|
|
+ error_msg = conn->ec.message();
|
|
|
+ iserror = true;
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+ pack_info_t temp_pack_data;
|
|
|
+ temp_pack_data.seq_id = 1;
|
|
|
+ bool is_sql_item = false;
|
|
|
+ std::vector<field_info_t> field_array;
|
|
|
+
|
|
|
+ unsigned char action_setup = 0;
|
|
|
+ unsigned int column_num = 0;
|
|
|
+
|
|
|
+ unsigned int offset = 0;
|
|
|
+
|
|
|
+ std::vector<unsigned char> field_pos;
|
|
|
+
|
|
|
+ for (; is_sql_item == false;)
|
|
|
+ {
|
|
|
+ n = conn->read_loop();
|
|
|
+ offset = 0;
|
|
|
+ for (; offset < n;)
|
|
|
+ {
|
|
|
+ conn->read_field_pack(conn->_cache_data, n, offset, temp_pack_data);
|
|
|
+ if (temp_pack_data.length == temp_pack_data.current_length)
|
|
|
+ {
|
|
|
+ if (conn->pack_eof_check(temp_pack_data))
|
|
|
+ {
|
|
|
+ is_sql_item = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (action_setup == 0)
|
|
|
+ {
|
|
|
+ if (temp_pack_data.length == 2 && (unsigned char)temp_pack_data.data[0] < 251 && (unsigned char)temp_pack_data.data[0] > 0)
|
|
|
+ {
|
|
|
+ action_setup = 1;
|
|
|
+ column_num = (unsigned char)temp_pack_data.data[0];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (action_setup == 1)
|
|
|
+ {
|
|
|
+ field_info_t temp_filed_col;
|
|
|
+ conn->read_col_info(temp_pack_data.data, temp_filed_col);
|
|
|
+
|
|
|
+ field_array.emplace_back(std::move(temp_filed_col));
|
|
|
+ column_num--;
|
|
|
+ if (column_num == 0)
|
|
|
+ {
|
|
|
+ action_setup = 2;
|
|
|
+ for (unsigned int ii = 0; ii < field_array.size(); ii++)
|
|
|
+ {
|
|
|
+ field_pos.push_back(B_BASE::findcolpos(field_array[ii].org_name));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (action_setup == 2)
|
|
|
+ {
|
|
|
+ unsigned int column_num = field_array.size();
|
|
|
+ unsigned int tempnum = 0;
|
|
|
+
|
|
|
+ typename B_BASE::meta data_temp;
|
|
|
+ for (unsigned int ij = 0; ij < column_num; ij++)
|
|
|
+ {
|
|
|
+ unsigned long long name_length = 0;
|
|
|
+ name_length = conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], tempnum);
|
|
|
+
|
|
|
+ assign_field_value(field_pos[ij], (unsigned char *)&temp_pack_data.data[tempnum], name_length, data_temp);
|
|
|
+ tempnum = tempnum + name_length;
|
|
|
+ }
|
|
|
+ B_BASE::record.emplace_back(std::move(data_temp));
|
|
|
+ effect_num++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (offset >= n)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ is_sql_item = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ conn_obj->back_select_conn(conn);
|
|
|
+
|
|
|
+ if (iscache)
|
|
|
+ {
|
|
|
+ if (exptime > 0)
|
|
|
+ {
|
|
|
+ save_cache(exptime);
|
|
|
+ exptime = 0;
|
|
|
+ iscache = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+ catch (const std::exception &e)
|
|
|
+ {
|
|
|
+ error_msg = std::string(e.what());
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+ catch (const std::string &e)
|
|
|
+ {
|
|
|
+ error_msg = e;
|
|
|
+ }
|
|
|
+ catch (...)
|
|
|
+ {
|
|
|
+ }
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+ asio::awaitable<unsigned int> async_fetch()
|
|
|
+ {
|
|
|
+ effect_num = 0;
|
|
|
+ if (selectsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring = "SELECT * FROM ";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sqlstring = "SELECT ";
|
|
|
+ sqlstring.append(selectsql);
|
|
|
+ sqlstring.append(" FROM ");
|
|
|
+ }
|
|
|
+
|
|
|
+ sqlstring.append(B_BASE::tablename);
|
|
|
+ sqlstring.append(" WHERE ");
|
|
|
+
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(" 1 ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sqlstring.append(wheresql);
|
|
|
+ }
|
|
|
+ if (!groupsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(groupsql);
|
|
|
+ }
|
|
|
+ if (!ordersql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(ordersql);
|
|
|
+ }
|
|
|
+ if (!limitsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(limitsql);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iscache)
|
|
|
+ {
|
|
|
+ std::size_t sqlhashid = std::hash<std::string>{}(sqlstring);
|
|
|
+ if (get_cacherecord(sqlhashid))
|
|
|
+ {
|
|
|
+ iscache = false;
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ B_BASE::record_reset();
|
|
|
+ if (iserror)
|
|
|
+ {
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (conn_empty())
|
|
|
+ {
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ auto conn = co_await conn_obj->async_get_select_conn();
|
|
|
+
|
|
|
+ unsigned int querysql_len = sqlstring.length() + 1;
|
|
|
+
|
|
|
+ conn->send_data.clear();
|
|
|
+
|
|
|
+ conn->send_data.push_back((querysql_len & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 8 & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 16 & 0xFF));
|
|
|
+ conn->send_data.push_back(0x00);
|
|
|
+ conn->send_data.push_back(0x03);
|
|
|
+ conn->send_data.append(sqlstring);
|
|
|
+
|
|
|
+ std::size_t n = co_await asio::async_write(*conn->socket, asio::buffer(conn->send_data), asio::use_awaitable);
|
|
|
+
|
|
|
+
|
|
|
+ pack_info_t temp_pack_data;
|
|
|
+ temp_pack_data.seq_id = 1;
|
|
|
+ bool is_sql_item = false;
|
|
|
+ std::vector<field_info_t> field_array;
|
|
|
+
|
|
|
+ unsigned char action_setup = 0;
|
|
|
+ unsigned int column_num = 0;
|
|
|
+
|
|
|
+ unsigned int offset = 0;
|
|
|
+
|
|
|
+ std::vector<unsigned char> field_pos;
|
|
|
+
|
|
|
+ for (; is_sql_item == false;)
|
|
|
+ {
|
|
|
+ n = co_await conn->async_read_loop();
|
|
|
+ offset = 0;
|
|
|
+ for (; offset < n;)
|
|
|
+ {
|
|
|
+ conn->read_field_pack(conn->_cache_data, n, offset, temp_pack_data);
|
|
|
+ if (temp_pack_data.length == temp_pack_data.current_length)
|
|
|
+ {
|
|
|
+ if (conn->pack_eof_check(temp_pack_data))
|
|
|
+ {
|
|
|
+ is_sql_item = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (action_setup == 0)
|
|
|
+ {
|
|
|
+ if (temp_pack_data.length == 2 && (unsigned char)temp_pack_data.data[0] < 251 && (unsigned char)temp_pack_data.data[0] > 0)
|
|
|
+ {
|
|
|
+ action_setup = 1;
|
|
|
+ column_num = (unsigned char)temp_pack_data.data[0];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (action_setup == 1)
|
|
|
+ {
|
|
|
+ field_info_t temp_filed_col;
|
|
|
+ conn->read_col_info(temp_pack_data.data, temp_filed_col);
|
|
|
+
|
|
|
+ field_array.emplace_back(std::move(temp_filed_col));
|
|
|
+ column_num--;
|
|
|
+ if (column_num == 0)
|
|
|
+ {
|
|
|
+ action_setup = 2;
|
|
|
+ for (unsigned int ii = 0; ii < field_array.size(); ii++)
|
|
|
+ {
|
|
|
+ field_pos.push_back(B_BASE::findcolpos(field_array[ii].org_name));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (action_setup == 2)
|
|
|
+ {
|
|
|
+ unsigned int column_num = field_array.size();
|
|
|
+ unsigned int tempnum = 0;
|
|
|
+
|
|
|
+ typename B_BASE::meta data_temp;
|
|
|
+ for (unsigned int ij = 0; ij < column_num; ij++)
|
|
|
+ {
|
|
|
+ unsigned long long name_length = 0;
|
|
|
+ name_length = conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], tempnum);
|
|
|
+
|
|
|
+ assign_field_value(field_pos[ij], (unsigned char *)&temp_pack_data.data[tempnum], name_length, data_temp);
|
|
|
+ tempnum = tempnum + name_length;
|
|
|
+ }
|
|
|
+ B_BASE::record.emplace_back(std::move(data_temp));
|
|
|
+ effect_num++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (offset >= n)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ is_sql_item = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ conn_obj->back_select_conn(conn);
|
|
|
+
|
|
|
+ if (iscache)
|
|
|
+ {
|
|
|
+ if (exptime > 0)
|
|
|
+ {
|
|
|
+ save_cache(exptime);
|
|
|
+ exptime = 0;
|
|
|
+ iscache = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ co_return effect_num;
|
|
|
+ }
|
|
|
+ catch (const std::exception &e)
|
|
|
+ {
|
|
|
+ error_msg = std::string(e.what());
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ catch (const std::string &e)
|
|
|
+ {
|
|
|
+ error_msg = e;
|
|
|
+ }
|
|
|
+ catch (...)
|
|
|
+ {
|
|
|
+ }
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ M_MODEL &fetch_append()
|
|
|
+ {
|
|
|
+ effect_num = 0;
|
|
|
+ if (selectsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring = "SELECT * FROM ";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sqlstring = "SELECT ";
|
|
|
+ sqlstring.append(selectsql);
|
|
|
+ sqlstring.append(" FROM ");
|
|
|
+ }
|
|
|
+
|
|
|
+ sqlstring.append(B_BASE::tablename);
|
|
|
+ sqlstring.append(" WHERE ");
|
|
|
+
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(" 1 ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sqlstring.append(wheresql);
|
|
|
+ }
|
|
|
+ if (!groupsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(groupsql);
|
|
|
+ }
|
|
|
+ if (!ordersql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(ordersql);
|
|
|
+ }
|
|
|
+ if (!limitsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(limitsql);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iscache)
|
|
|
+ {
|
|
|
+ std::size_t sqlhashid = std::hash<std::string>{}(sqlstring);
|
|
|
+ if (get_cacherecord(sqlhashid))
|
|
|
+ {
|
|
|
+ iscache = false;
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iserror)
|
|
|
+ {
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+
|
|
|
+ if (conn_empty())
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ auto conn = conn_obj->get_select_conn();
|
|
|
+
|
|
|
+ unsigned int querysql_len = sqlstring.length() + 1;
|
|
|
+
|
|
|
+ conn->send_data.clear();
|
|
|
+
|
|
|
+ conn->send_data.push_back((querysql_len & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 8 & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 16 & 0xFF));
|
|
|
+ conn->send_data.push_back(0x00);
|
|
|
+ conn->send_data.push_back(0x03);
|
|
|
+ conn->send_data.append(sqlstring);
|
|
|
+
|
|
|
+ std::size_t n = asio::write(*conn->socket, asio::buffer(conn->send_data), conn->ec);
|
|
|
+
|
|
|
+ if(conn->ec)
|
|
|
+ {
|
|
|
+ error_msg = conn->ec.message();
|
|
|
+ iserror = true;
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ pack_info_t temp_pack_data;
|
|
|
+ temp_pack_data.seq_id = 1;
|
|
|
+ bool is_sql_item = false;
|
|
|
+ std::vector<field_info_t> field_array;
|
|
|
+
|
|
|
+ unsigned char action_setup = 0;
|
|
|
+ unsigned int column_num = 0;
|
|
|
+
|
|
|
+ unsigned int offset = 0;
|
|
|
+
|
|
|
+ std::vector<unsigned char> field_pos;
|
|
|
+
|
|
|
+ for (; is_sql_item == false;)
|
|
|
+ {
|
|
|
+ n = conn->read_loop();
|
|
|
+ offset = 0;
|
|
|
+ for (; offset < n;)
|
|
|
+ {
|
|
|
+ conn->read_field_pack(conn->_cache_data, n, offset, temp_pack_data);
|
|
|
+ if (temp_pack_data.length == temp_pack_data.current_length)
|
|
|
+ {
|
|
|
+ if (conn->pack_eof_check(temp_pack_data))
|
|
|
+ {
|
|
|
+ is_sql_item = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (action_setup == 0)
|
|
|
+ {
|
|
|
+ if (temp_pack_data.length == 2 && (unsigned char)temp_pack_data.data[0] < 251 && (unsigned char)temp_pack_data.data[0] > 0)
|
|
|
+ {
|
|
|
+ action_setup = 1;
|
|
|
+ column_num = (unsigned char)temp_pack_data.data[0];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (action_setup == 1)
|
|
|
+ {
|
|
|
+ field_info_t temp_filed_col;
|
|
|
+ conn->read_col_info(temp_pack_data.data, temp_filed_col);
|
|
|
+
|
|
|
+ field_array.emplace_back(std::move(temp_filed_col));
|
|
|
+ column_num--;
|
|
|
+ if (column_num == 0)
|
|
|
+ {
|
|
|
+ action_setup = 2;
|
|
|
+ for (unsigned int ii = 0; ii < field_array.size(); ii++)
|
|
|
+ {
|
|
|
+ field_pos.push_back(B_BASE::findcolpos(field_array[ii].org_name));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (action_setup == 2)
|
|
|
+ {
|
|
|
+ unsigned int column_num = field_array.size();
|
|
|
+ unsigned int tempnum = 0;
|
|
|
+
|
|
|
+ typename B_BASE::meta data_temp;
|
|
|
+ for (unsigned int ij = 0; ij < column_num; ij++)
|
|
|
+ {
|
|
|
+ unsigned long long name_length = 0;
|
|
|
+ name_length = conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], tempnum);
|
|
|
+
|
|
|
+ assign_field_value(field_pos[ij], (unsigned char *)&temp_pack_data.data[tempnum], name_length, data_temp);
|
|
|
+ tempnum = tempnum + name_length;
|
|
|
+ }
|
|
|
+ B_BASE::record.emplace_back(std::move(data_temp));
|
|
|
+ effect_num++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (offset >= n)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ is_sql_item = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ conn_obj->back_select_conn(conn);
|
|
|
+
|
|
|
+ if (iscache)
|
|
|
+ {
|
|
|
+ if (exptime > 0)
|
|
|
+ {
|
|
|
+ save_cache(exptime);
|
|
|
+ exptime = 0;
|
|
|
+ iscache = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+ catch (const std::exception &e)
|
|
|
+ {
|
|
|
+ error_msg = std::string(e.what());
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+ catch (const std::string &e)
|
|
|
+ {
|
|
|
+ error_msg = e;
|
|
|
+ }
|
|
|
+ catch (...)
|
|
|
+ {
|
|
|
+ }
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+ asio::awaitable<unsigned int> async_fetch_append()
|
|
|
+ {
|
|
|
+ effect_num = 0;
|
|
|
+ if (selectsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring = "SELECT * FROM ";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sqlstring = "SELECT ";
|
|
|
+ sqlstring.append(selectsql);
|
|
|
+ sqlstring.append(" FROM ");
|
|
|
+ }
|
|
|
+
|
|
|
+ sqlstring.append(B_BASE::tablename);
|
|
|
+ sqlstring.append(" WHERE ");
|
|
|
+
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(" 1 ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sqlstring.append(wheresql);
|
|
|
+ }
|
|
|
+ if (!groupsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(groupsql);
|
|
|
+ }
|
|
|
+ if (!ordersql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(ordersql);
|
|
|
+ }
|
|
|
+ if (!limitsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(limitsql);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iscache)
|
|
|
+ {
|
|
|
+ std::size_t sqlhashid = std::hash<std::string>{}(sqlstring);
|
|
|
+ if (get_cacherecord(sqlhashid))
|
|
|
+ {
|
|
|
+ iscache = false;
|
|
|
+ co_return 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iserror)
|
|
|
+ {
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ effect_num = 0;
|
|
|
+
|
|
|
+ if (conn_empty())
|
|
|
+ {
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ auto conn = co_await conn_obj->async_get_select_conn();
|
|
|
+
|
|
|
+ unsigned int querysql_len = sqlstring.length() + 1;
|
|
|
+
|
|
|
+ conn->send_data.clear();
|
|
|
+
|
|
|
+ conn->send_data.push_back((querysql_len & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 8 & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 16 & 0xFF));
|
|
|
+ conn->send_data.push_back(0x00);
|
|
|
+ conn->send_data.push_back(0x03);
|
|
|
+ conn->send_data.append(sqlstring);
|
|
|
+
|
|
|
+ std::size_t n = co_await asio::async_write(*conn->socket, asio::buffer(conn->send_data), asio::use_awaitable);
|
|
|
+
|
|
|
+ // asio::error_code ec;
|
|
|
+
|
|
|
+
|
|
|
+ pack_info_t temp_pack_data;
|
|
|
+ temp_pack_data.seq_id = 1;
|
|
|
+ bool is_sql_item = false;
|
|
|
+ std::vector<field_info_t> field_array;
|
|
|
+ // std::vector<std::vector<std::string>> field_value;
|
|
|
+
|
|
|
+ unsigned char action_setup = 0;
|
|
|
+ unsigned int column_num = 0;
|
|
|
+
|
|
|
+ unsigned int offset = 0;
|
|
|
+
|
|
|
+ std::vector<unsigned char> field_pos;
|
|
|
+ // std::map<unsigned char, std::string> other_col;
|
|
|
+
|
|
|
+ for (; is_sql_item == false;)
|
|
|
+ {
|
|
|
+ // std::memset(result_data, 0x00, 4096);
|
|
|
+ // n = co_await conn->socket->async_read_some(asio::buffer(result_data), asio::use_awaitable);
|
|
|
+ n = co_await conn->async_read_loop();
|
|
|
+ offset = 0;
|
|
|
+ for (; offset < n;)
|
|
|
+ {
|
|
|
+ conn->read_field_pack(conn->_cache_data, n, offset, temp_pack_data);
|
|
|
+ if (temp_pack_data.length == temp_pack_data.current_length)
|
|
|
+ {
|
|
|
+ if (conn->pack_eof_check(temp_pack_data))
|
|
|
+ {
|
|
|
+ is_sql_item = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (action_setup == 0)
|
|
|
+ {
|
|
|
+ if (temp_pack_data.length == 2 && (unsigned char)temp_pack_data.data[0] < 251 && (unsigned char)temp_pack_data.data[0] > 0)
|
|
|
+ {
|
|
|
+ action_setup = 1;
|
|
|
+ column_num = (unsigned char)temp_pack_data.data[0];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (action_setup == 1)
|
|
|
+ {
|
|
|
+ field_info_t temp_filed_col;
|
|
|
+ conn->read_col_info(temp_pack_data.data, temp_filed_col);
|
|
|
+
|
|
|
+ field_array.emplace_back(std::move(temp_filed_col));
|
|
|
+ column_num--;
|
|
|
+ if (column_num == 0)
|
|
|
+ {
|
|
|
+ action_setup = 2;
|
|
|
+ for (unsigned int ii = 0; ii < field_array.size(); ii++)
|
|
|
+ {
|
|
|
+ field_pos.push_back(B_BASE::findcolpos(field_array[ii].org_name));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (action_setup == 2)
|
|
|
+ {
|
|
|
+ unsigned int column_num = field_array.size();
|
|
|
+ unsigned int tempnum = 0;
|
|
|
+
|
|
|
+ typename B_BASE::meta data_temp;
|
|
|
+ for (unsigned int ij = 0; ij < column_num; ij++)
|
|
|
+ {
|
|
|
+ unsigned long long name_length = 0;
|
|
|
+ name_length = conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], tempnum);
|
|
|
+
|
|
|
+ assign_field_value(field_pos[ij], (unsigned char *)&temp_pack_data.data[tempnum], name_length, data_temp);
|
|
|
+ tempnum = tempnum + name_length;
|
|
|
+ }
|
|
|
+ effect_num++;
|
|
|
+ B_BASE::record.emplace_back(std::move(data_temp));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (offset >= n)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ is_sql_item = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ conn_obj->back_select_conn(conn);
|
|
|
+
|
|
|
+ if (iscache)
|
|
|
+ {
|
|
|
+ if (exptime > 0)
|
|
|
+ {
|
|
|
+ save_cache(exptime);
|
|
|
+ exptime = 0;
|
|
|
+ iscache = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ co_return effect_num;
|
|
|
+ }
|
|
|
+ catch (const std::exception &e)
|
|
|
+ {
|
|
|
+ error_msg = std::string(e.what());
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ catch (const std::string &e)
|
|
|
+ {
|
|
|
+ error_msg = e;
|
|
|
+ }
|
|
|
+ catch (...)
|
|
|
+ {
|
|
|
+ }
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ unsigned int fetch_one(bool isappend = false)
|
|
|
+ {
|
|
|
+ effect_num = 0;
|
|
|
+ if (selectsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring = "SELECT * FROM ";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sqlstring = "SELECT ";
|
|
|
+ sqlstring.append(selectsql);
|
|
|
+ sqlstring.append(" FROM ");
|
|
|
+ }
|
|
|
+
|
|
|
+ sqlstring.append(B_BASE::tablename);
|
|
|
+ sqlstring.append(" WHERE ");
|
|
|
+
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(" 1 ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sqlstring.append(wheresql);
|
|
|
+ }
|
|
|
+ if (!groupsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(groupsql);
|
|
|
+ }
|
|
|
+ if (!ordersql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(ordersql);
|
|
|
+ }
|
|
|
+
|
|
|
+ sqlstring.append(" limit 1");
|
|
|
+
|
|
|
+ if (iscache)
|
|
|
+ {
|
|
|
+ std::size_t sqlhashid = std::hash<std::string>{}(sqlstring);
|
|
|
+ if (get_cacherecord(sqlhashid))
|
|
|
+ {
|
|
|
+ iscache = false;
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ B_BASE::data_reset();
|
|
|
+ if (iserror)
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ effect_num = 0;
|
|
|
+ if (conn_empty())
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ auto conn = conn_obj->get_select_conn();
|
|
|
+
|
|
|
+ unsigned int querysql_len = sqlstring.length() + 1;
|
|
|
+
|
|
|
+ conn->send_data.clear();
|
|
|
+ conn->send_data.push_back((querysql_len & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 8 & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 16 & 0xFF));
|
|
|
+ conn->send_data.push_back(0x00);
|
|
|
+ conn->send_data.push_back(0x03);
|
|
|
+ conn->send_data.append(sqlstring);
|
|
|
+
|
|
|
+ std::size_t n = asio::write(*conn->socket, asio::buffer(conn->send_data), conn->ec);
|
|
|
+
|
|
|
+ if(conn->ec)
|
|
|
+ {
|
|
|
+ error_msg = conn->ec.message();
|
|
|
+ iserror = true;
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ pack_info_t temp_pack_data;
|
|
|
+ temp_pack_data.seq_id = 1;
|
|
|
+ bool is_sql_item = false;
|
|
|
+ std::vector<field_info_t> field_array;
|
|
|
+ unsigned char action_setup = 0;
|
|
|
+ unsigned int column_num = 0;
|
|
|
+ unsigned int offset = 0;
|
|
|
+
|
|
|
+ std::vector<unsigned char> field_pos;
|
|
|
+
|
|
|
+ for (; is_sql_item == false;)
|
|
|
+ {
|
|
|
+ n = conn->read_loop();
|
|
|
+ offset = 0;
|
|
|
+ for (; offset < n;)
|
|
|
+ {
|
|
|
+ conn->read_field_pack(conn->_cache_data, n, offset, temp_pack_data);
|
|
|
+ if (temp_pack_data.length == temp_pack_data.current_length)
|
|
|
+ {
|
|
|
+ if (conn->pack_eof_check(temp_pack_data))
|
|
|
+ {
|
|
|
+ is_sql_item = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (action_setup == 0)
|
|
|
+ {
|
|
|
+ if (temp_pack_data.length == 2 && (unsigned char)temp_pack_data.data[0] < 251 && (unsigned char)temp_pack_data.data[0] > 0)
|
|
|
+ {
|
|
|
+ action_setup = 1;
|
|
|
+ column_num = (unsigned char)temp_pack_data.data[0];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (action_setup == 1)
|
|
|
+ {
|
|
|
+ field_info_t temp_filed_col;
|
|
|
+ conn->read_col_info(temp_pack_data.data, temp_filed_col);
|
|
|
+
|
|
|
+ field_array.emplace_back(std::move(temp_filed_col));
|
|
|
+ column_num--;
|
|
|
+ if (column_num == 0)
|
|
|
+ {
|
|
|
+ action_setup = 2;
|
|
|
+ for (unsigned int ii = 0; ii < field_array.size(); ii++)
|
|
|
+ {
|
|
|
+ field_pos.push_back(B_BASE::findcolpos(field_array[ii].org_name));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (action_setup == 2)
|
|
|
+ {
|
|
|
+ unsigned int column_num = field_array.size();
|
|
|
+ unsigned int tempnum = 0;
|
|
|
+
|
|
|
+ if (isappend)
|
|
|
+ {
|
|
|
+ typename B_BASE::meta data_temp;
|
|
|
+ for (unsigned int ij = 0; ij < column_num; ij++)
|
|
|
+ {
|
|
|
+ unsigned long long name_length = 0;
|
|
|
+ name_length = conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], tempnum);
|
|
|
+
|
|
|
+ assign_field_value(field_pos[ij], (unsigned char *)&temp_pack_data.data[tempnum], name_length, data_temp);
|
|
|
+ tempnum = tempnum + name_length;
|
|
|
+ }
|
|
|
+ B_BASE::record.emplace_back(std::move(data_temp));
|
|
|
+ effect_num++;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ for (unsigned int ij = 0; ij < column_num; ij++)
|
|
|
+ {
|
|
|
+ unsigned long long name_length = 0;
|
|
|
+ name_length = conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], tempnum);
|
|
|
+
|
|
|
+ assign_field_value(field_pos[ij], (unsigned char *)&temp_pack_data.data[tempnum], name_length, B_BASE::data);
|
|
|
+ tempnum = tempnum + name_length;
|
|
|
+ }
|
|
|
+ effect_num++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (offset >= n)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ is_sql_item = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ conn_obj->back_select_conn(conn);
|
|
|
+
|
|
|
+ if (iscache)
|
|
|
+ {
|
|
|
+ if (exptime > 0)
|
|
|
+ {
|
|
|
+ save_cache(exptime);
|
|
|
+ exptime = 0;
|
|
|
+ iscache = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return effect_num;
|
|
|
+ }
|
|
|
+ catch (const std::exception &e)
|
|
|
+ {
|
|
|
+ error_msg = std::string(e.what());
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ catch (const std::string &e)
|
|
|
+ {
|
|
|
+ error_msg = e;
|
|
|
+ }
|
|
|
+ catch (...)
|
|
|
+ {
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ asio::awaitable<unsigned int> async_fetch_one(bool isappend = false)
|
|
|
+ {
|
|
|
+ effect_num = 0;
|
|
|
+ if (selectsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring = "SELECT * FROM ";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sqlstring = "SELECT ";
|
|
|
+ sqlstring.append(selectsql);
|
|
|
+ sqlstring.append(" FROM ");
|
|
|
+ }
|
|
|
+
|
|
|
+ sqlstring.append(B_BASE::tablename);
|
|
|
+ sqlstring.append(" WHERE ");
|
|
|
+
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(" 1 ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sqlstring.append(wheresql);
|
|
|
+ }
|
|
|
+ if (!groupsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(groupsql);
|
|
|
+ }
|
|
|
+ if (!ordersql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(ordersql);
|
|
|
+ }
|
|
|
+
|
|
|
+ sqlstring.append(" limit 1");
|
|
|
+
|
|
|
+ if (iscache)
|
|
|
+ {
|
|
|
+ std::size_t sqlhashid = std::hash<std::string>{}(sqlstring);
|
|
|
+ if (get_cacherecord(sqlhashid))
|
|
|
+ {
|
|
|
+ iscache = false;
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ B_BASE::data_reset();
|
|
|
+ if (iserror)
|
|
|
+ {
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ effect_num = 0;
|
|
|
+
|
|
|
+ if (conn_empty())
|
|
|
+ {
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ auto conn = co_await conn_obj->async_get_select_conn();
|
|
|
+
|
|
|
+ unsigned int querysql_len = sqlstring.length() + 1;
|
|
|
+
|
|
|
+ conn->send_data.clear();
|
|
|
+ conn->send_data.push_back((querysql_len & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 8 & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 16 & 0xFF));
|
|
|
+ conn->send_data.push_back(0x00);
|
|
|
+ conn->send_data.push_back(0x03);
|
|
|
+ conn->send_data.append(sqlstring);
|
|
|
+
|
|
|
+ std::size_t n = co_await asio::async_write(*conn->socket, asio::buffer(conn->send_data), asio::use_awaitable);
|
|
|
+
|
|
|
+
|
|
|
+ pack_info_t temp_pack_data;
|
|
|
+ temp_pack_data.seq_id = 1;
|
|
|
+ bool is_sql_item = false;
|
|
|
+ std::vector<field_info_t> field_array;
|
|
|
+ // std::vector<std::vector<std::string>> field_value;
|
|
|
+
|
|
|
+ unsigned char action_setup = 0;
|
|
|
+ unsigned int column_num = 0;
|
|
|
+
|
|
|
+ unsigned int offset = 0;
|
|
|
+
|
|
|
+ std::vector<unsigned char> field_pos;
|
|
|
+ // std::map<unsigned char, std::string> other_col;
|
|
|
+
|
|
|
+ for (; is_sql_item == false;)
|
|
|
+ {
|
|
|
+ n = co_await conn->async_read_loop();
|
|
|
+ offset = 0;
|
|
|
+ for (; offset < n;)
|
|
|
+ {
|
|
|
+ conn->read_field_pack(conn->_cache_data, n, offset, temp_pack_data);
|
|
|
+ if (temp_pack_data.length == temp_pack_data.current_length)
|
|
|
+ {
|
|
|
+ if (conn->pack_eof_check(temp_pack_data))
|
|
|
+ {
|
|
|
+ is_sql_item = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (action_setup == 0)
|
|
|
+ {
|
|
|
+ if (temp_pack_data.length == 2 && (unsigned char)temp_pack_data.data[0] < 251 && (unsigned char)temp_pack_data.data[0] > 0)
|
|
|
+ {
|
|
|
+ action_setup = 1;
|
|
|
+ column_num = (unsigned char)temp_pack_data.data[0];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (action_setup == 1)
|
|
|
+ {
|
|
|
+ field_info_t temp_filed_col;
|
|
|
+ conn->read_col_info(temp_pack_data.data, temp_filed_col);
|
|
|
+
|
|
|
+ field_array.emplace_back(std::move(temp_filed_col));
|
|
|
+ column_num--;
|
|
|
+ if (column_num == 0)
|
|
|
+ {
|
|
|
+ action_setup = 2;
|
|
|
+ for (unsigned int ii = 0; ii < field_array.size(); ii++)
|
|
|
+ {
|
|
|
+ field_pos.push_back(B_BASE::findcolpos(field_array[ii].org_name));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (action_setup == 2)
|
|
|
+ {
|
|
|
+ unsigned int column_num = field_array.size();
|
|
|
+ unsigned int tempnum = 0;
|
|
|
+
|
|
|
+ if (isappend)
|
|
|
+ {
|
|
|
+ typename B_BASE::meta data_temp;
|
|
|
+ for (unsigned int ij = 0; ij < column_num; ij++)
|
|
|
+ {
|
|
|
+ unsigned long long name_length = 0;
|
|
|
+ name_length = conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], tempnum);
|
|
|
+
|
|
|
+ assign_field_value(field_pos[ij], (unsigned char *)&temp_pack_data.data[tempnum], name_length, data_temp);
|
|
|
+ tempnum = tempnum + name_length;
|
|
|
+ }
|
|
|
+ B_BASE::record.emplace_back(std::move(data_temp));
|
|
|
+ effect_num++;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ for (unsigned int ij = 0; ij < column_num; ij++)
|
|
|
+ {
|
|
|
+ unsigned long long name_length = 0;
|
|
|
+ name_length = conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], tempnum);
|
|
|
+
|
|
|
+ assign_field_value(field_pos[ij], (unsigned char *)&temp_pack_data.data[tempnum], name_length, B_BASE::data);
|
|
|
+ tempnum = tempnum + name_length;
|
|
|
+ }
|
|
|
+ effect_num++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (offset >= n)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ is_sql_item = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ conn_obj->back_select_conn(conn);
|
|
|
+
|
|
|
+ if (iscache)
|
|
|
+ {
|
|
|
+ if (exptime > 0)
|
|
|
+ {
|
|
|
+ save_cache(exptime);
|
|
|
+ exptime = 0;
|
|
|
+ iscache = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ co_return effect_num;
|
|
|
+ }
|
|
|
+ catch (const std::exception &e)
|
|
|
+ {
|
|
|
+ error_msg = std::string(e.what());
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ catch (const std::string &e)
|
|
|
+ {
|
|
|
+ error_msg = e;
|
|
|
+ }
|
|
|
+ catch (...)
|
|
|
+ {
|
|
|
+ }
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ M_MODEL &use_cache(int cache_time = 0)
|
|
|
+ {
|
|
|
+ iscache = true;
|
|
|
+ exptime = cache_time;
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+ bool isuse_cache(bool iscachedate = false)
|
|
|
+ {
|
|
|
+ if (iscachedate)
|
|
|
+ {
|
|
|
+ return exptime == 0 && iscache == false;
|
|
|
+ }
|
|
|
+ return iscache;
|
|
|
+ }
|
|
|
+ void set_cache_state(bool isrestatus = false) { iscache = isrestatus; }
|
|
|
+ void remove_exptime_cache()
|
|
|
+ {
|
|
|
+ model_meta_cache<typename B_BASE::meta> &temp_cache = model_meta_cache<typename B_BASE::meta>::getinstance();
|
|
|
+ temp_cache.remove_exptime();
|
|
|
+ }
|
|
|
+ void clear_cache()
|
|
|
+ {
|
|
|
+ model_meta_cache<typename B_BASE::meta> &temp_cache = model_meta_cache<typename B_BASE::meta>::getinstance();
|
|
|
+ temp_cache.clear();
|
|
|
+ }
|
|
|
+ bool remove_cache()
|
|
|
+ {
|
|
|
+ model_meta_cache<typename B_BASE::meta> &temp_cache = model_meta_cache<typename B_BASE::meta>::getinstance();
|
|
|
+ std::size_t sqlhashid = std::hash<std::string>{}(sqlstring);
|
|
|
+ return temp_cache.remove(sqlhashid);
|
|
|
+ }
|
|
|
+ bool remove_cache(std::size_t cache_key_name)
|
|
|
+ {
|
|
|
+ model_meta_cache<typename B_BASE::meta> &temp_cache = model_meta_cache<typename B_BASE::meta>::getinstance();
|
|
|
+ return temp_cache.remove(cache_key_name);
|
|
|
+ }
|
|
|
+ int check_cache(std::size_t cache_key_name)
|
|
|
+ {
|
|
|
+ model_meta_cache<typename B_BASE::meta> &temp_cache = model_meta_cache<typename B_BASE::meta>::getinstance();
|
|
|
+ return temp_cache.check(cache_key_name);
|
|
|
+ }
|
|
|
+ std::vector<typename B_BASE::meta> get_cache_data(std::size_t cache_key_name)
|
|
|
+ {
|
|
|
+ model_meta_cache<typename B_BASE::meta> &temp_cache = model_meta_cache<typename B_BASE::meta>::getinstance();
|
|
|
+ auto cache_data = temp_cache.get(cache_key_name);
|
|
|
+ return cache_data;
|
|
|
+ }
|
|
|
+ typename B_BASE::meta get_cache_obj(std::size_t cache_key_name)
|
|
|
+ {
|
|
|
+ model_meta_cache<typename B_BASE::meta> &temp_cache = model_meta_cache<typename B_BASE::meta>::getinstance();
|
|
|
+ auto cache_data = temp_cache.get_obj(cache_key_name);
|
|
|
+ return cache_data;
|
|
|
+ }
|
|
|
+ M_MODEL &get_cache(std::size_t cache_key_name)
|
|
|
+ {
|
|
|
+ model_meta_cache<typename B_BASE::meta> &temp_cache = model_meta_cache<typename B_BASE::meta>::getinstance();
|
|
|
+ B_BASE::record = temp_cache.get(cache_key_name);
|
|
|
+ if (B_BASE::record.size() == 0)
|
|
|
+ {
|
|
|
+ B_BASE::record_reset();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ B_BASE::data = B_BASE::record[0];
|
|
|
+ }
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+ int update_cache(int exp_time = 0)
|
|
|
+ {
|
|
|
+ model_meta_cache<typename B_BASE::meta> &temp_cache = model_meta_cache<typename B_BASE::meta>::getinstance();
|
|
|
+ std::size_t sqlhashid = std::hash<std::string>{}(sqlstring);
|
|
|
+ return temp_cache.update(sqlhashid, exp_time);
|
|
|
+ }
|
|
|
+ int update_cache(std::size_t cache_key_name, int exp_time)
|
|
|
+ {
|
|
|
+ model_meta_cache<typename B_BASE::meta> &temp_cache = model_meta_cache<typename B_BASE::meta>::getinstance();
|
|
|
+ return temp_cache.update(cache_key_name, exp_time);
|
|
|
+ }
|
|
|
+ bool save_cache(int exp_time = 0)
|
|
|
+ {
|
|
|
+ model_meta_cache<typename B_BASE::meta> &temp_cache = model_meta_cache<typename B_BASE::meta>::getinstance();
|
|
|
+ std::size_t sqlhashid = std::hash<std::string>{}(sqlstring);
|
|
|
+ temp_cache.save(sqlhashid, B_BASE::record, exp_time);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ bool save_cache(std::size_t cache_key_name, typename B_BASE::meta &cache_data, int exp_time = 0)
|
|
|
+ {
|
|
|
+ model_meta_cache<typename B_BASE::meta> &temp_cache = model_meta_cache<typename B_BASE::meta>::getinstance();
|
|
|
+ temp_cache.save(cache_key_name, cache_data, exp_time);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ bool save_cache(std::size_t cache_key_name, std::vector<typename B_BASE::meta> &cache_data, int exp_time = 0)
|
|
|
+ {
|
|
|
+ model_meta_cache<typename B_BASE::meta> &temp_cache = model_meta_cache<typename B_BASE::meta>::getinstance();
|
|
|
+ temp_cache.save(cache_key_name, cache_data, exp_time);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ bool get_cacherecord(std::size_t cache_key_name)
|
|
|
+ {
|
|
|
+ model_meta_cache<typename B_BASE::meta> &temp_cache = model_meta_cache<typename B_BASE::meta>::getinstance();
|
|
|
+ B_BASE::record = temp_cache.get(cache_key_name);
|
|
|
+ if (B_BASE::record.size() == 0)
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ B_BASE::data = B_BASE::record[0];
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ http::OBJ_VALUE fetch_json()
|
|
|
+ {
|
|
|
+ effect_num = 0;
|
|
|
+ if (selectsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring = "SELECT * FROM ";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sqlstring = "SELECT ";
|
|
|
+ sqlstring.append(selectsql);
|
|
|
+ sqlstring.append(" FROM ");
|
|
|
+ }
|
|
|
+
|
|
|
+ sqlstring.append(B_BASE::tablename);
|
|
|
+ sqlstring.append(" WHERE ");
|
|
|
+
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(" 1 ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sqlstring.append(wheresql);
|
|
|
+ }
|
|
|
+ if (!groupsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(groupsql);
|
|
|
+ }
|
|
|
+ if (!ordersql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(ordersql);
|
|
|
+ }
|
|
|
+ if (!limitsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(limitsql);
|
|
|
+ }
|
|
|
+
|
|
|
+ http::OBJ_VALUE valuetemp;
|
|
|
+ valuetemp.set_array();
|
|
|
+
|
|
|
+ if (iserror)
|
|
|
+ {
|
|
|
+ return valuetemp;
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (conn_empty())
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ auto conn = conn_obj->get_select_conn();
|
|
|
+
|
|
|
+ unsigned int querysql_len = sqlstring.length() + 1;
|
|
|
+
|
|
|
+ conn->send_data.clear();
|
|
|
+
|
|
|
+ conn->send_data.push_back((querysql_len & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 8 & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 16 & 0xFF));
|
|
|
+ conn->send_data.push_back(0x00);
|
|
|
+ conn->send_data.push_back(0x03);
|
|
|
+ conn->send_data.append(sqlstring);
|
|
|
+
|
|
|
+ std::size_t n = asio::write(*conn->socket, asio::buffer(conn->send_data), conn->ec);
|
|
|
+
|
|
|
+ if(conn->ec)
|
|
|
+ {
|
|
|
+ error_msg = conn->ec.message();
|
|
|
+ iserror = true;
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ pack_info_t temp_pack_data;
|
|
|
+ temp_pack_data.seq_id = 1;
|
|
|
+ bool is_sql_item = false;
|
|
|
+ std::vector<field_info_t> field_array;
|
|
|
+
|
|
|
+
|
|
|
+ unsigned char action_setup = 0;
|
|
|
+ unsigned int column_num = 0;
|
|
|
+
|
|
|
+ unsigned int offset = 0;
|
|
|
+
|
|
|
+ for (; is_sql_item == false;)
|
|
|
+ {
|
|
|
+ n = conn->read_loop();
|
|
|
+ offset = 0;
|
|
|
+ for (; offset < n;)
|
|
|
+ {
|
|
|
+ conn->read_field_pack(conn->_cache_data, n, offset, temp_pack_data);
|
|
|
+ if (temp_pack_data.length == temp_pack_data.current_length)
|
|
|
+ {
|
|
|
+ if (conn->pack_eof_check(temp_pack_data))
|
|
|
+ {
|
|
|
+ is_sql_item = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (action_setup == 0)
|
|
|
+ {
|
|
|
+ if (temp_pack_data.length == 2 && (unsigned char)temp_pack_data.data[0] < 251 && (unsigned char)temp_pack_data.data[0] > 0)
|
|
|
+ {
|
|
|
+ action_setup = 1;
|
|
|
+ column_num = (unsigned char)temp_pack_data.data[0];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (action_setup == 1)
|
|
|
+ {
|
|
|
+ field_info_t temp_filed_col;
|
|
|
+ conn->read_col_info(temp_pack_data.data, temp_filed_col);
|
|
|
+
|
|
|
+ field_array.emplace_back(std::move(temp_filed_col));
|
|
|
+ column_num--;
|
|
|
+ if (column_num == 0)
|
|
|
+ {
|
|
|
+ action_setup = 2;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (action_setup == 2)
|
|
|
+ {
|
|
|
+ unsigned int column_num = field_array.size();
|
|
|
+ unsigned int tempnum = 0;
|
|
|
+
|
|
|
+ http::OBJ_VALUE json_temp_v;
|
|
|
+ for (unsigned int ij = 0; ij < column_num; ij++)
|
|
|
+ {
|
|
|
+ unsigned long long name_length = 0;
|
|
|
+ name_length = conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], tempnum);
|
|
|
+
|
|
|
+ std::string temp_str;
|
|
|
+ temp_str.resize(name_length);
|
|
|
+ std::memcpy(temp_str.data(), (unsigned char *)&temp_pack_data.data[tempnum], name_length);
|
|
|
+ if(field_array[ij].name.size()>0)
|
|
|
+ {
|
|
|
+ //or alias name
|
|
|
+ json_temp_v[field_array[ij].name]=std::move(temp_str);
|
|
|
+ }
|
|
|
+ else if(field_array[ij].org_name.size()>0)
|
|
|
+ {
|
|
|
+ json_temp_v[field_array[ij].org_name]=std::move(temp_str);
|
|
|
+ }
|
|
|
+ tempnum = tempnum + name_length;
|
|
|
+ }
|
|
|
+ valuetemp.push(json_temp_v);
|
|
|
+ effect_num++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (offset >= n)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ is_sql_item = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ conn_obj->back_select_conn(conn);
|
|
|
+
|
|
|
+ }
|
|
|
+ catch (const std::exception &e)
|
|
|
+ {
|
|
|
+ error_msg = std::string(e.what());
|
|
|
+ }
|
|
|
+ catch (const std::string &e)
|
|
|
+ {
|
|
|
+ error_msg = e;
|
|
|
+ }
|
|
|
+ catch (...)
|
|
|
+ {
|
|
|
+ }
|
|
|
+ return valuetemp;
|
|
|
+ }
|
|
|
+
|
|
|
+ asio::awaitable<http::OBJ_VALUE> async_fetch_json()
|
|
|
+ {
|
|
|
+ effect_num = 0;
|
|
|
+ if (selectsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring = "SELECT * FROM ";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sqlstring = "SELECT ";
|
|
|
+ sqlstring.append(selectsql);
|
|
|
+ sqlstring.append(" FROM ");
|
|
|
+ }
|
|
|
+
|
|
|
+ sqlstring.append(B_BASE::tablename);
|
|
|
+ sqlstring.append(" WHERE ");
|
|
|
+
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(" 1 ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sqlstring.append(wheresql);
|
|
|
+ }
|
|
|
+ if (!groupsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(groupsql);
|
|
|
+ }
|
|
|
+ if (!ordersql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(ordersql);
|
|
|
+ }
|
|
|
+ if (!limitsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(limitsql);
|
|
|
+ }
|
|
|
+
|
|
|
+ http::OBJ_VALUE valuetemp;
|
|
|
+ valuetemp.set_array();
|
|
|
+
|
|
|
+ if (iserror)
|
|
|
+ {
|
|
|
+ co_return valuetemp;
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (conn_empty())
|
|
|
+ {
|
|
|
+ co_return valuetemp;
|
|
|
+ }
|
|
|
+ auto conn = co_await conn_obj->async_get_select_conn();
|
|
|
+
|
|
|
+ unsigned int querysql_len = sqlstring.length() + 1;
|
|
|
+ conn->send_data.clear();
|
|
|
+
|
|
|
+ conn->send_data.push_back((querysql_len & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 8 & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 16 & 0xFF));
|
|
|
+ conn->send_data.push_back(0x00);
|
|
|
+ conn->send_data.push_back(0x03);
|
|
|
+ conn->send_data.append(sqlstring);
|
|
|
+
|
|
|
+ std::size_t n = co_await asio::async_write(*conn->socket, asio::buffer(conn->send_data), asio::use_awaitable);
|
|
|
+
|
|
|
+
|
|
|
+ pack_info_t temp_pack_data;
|
|
|
+ temp_pack_data.seq_id = 1;
|
|
|
+ bool is_sql_item = false;
|
|
|
+ std::vector<field_info_t> field_array;
|
|
|
+
|
|
|
+
|
|
|
+ unsigned char action_setup = 0;
|
|
|
+ unsigned int column_num = 0;
|
|
|
+
|
|
|
+ unsigned int offset = 0;
|
|
|
+
|
|
|
+ for (; is_sql_item == false;)
|
|
|
+ {
|
|
|
+ n = co_await conn->async_read_loop();
|
|
|
+ offset = 0;
|
|
|
+ for (; offset < n;)
|
|
|
+ {
|
|
|
+ conn->read_field_pack(conn->_cache_data, n, offset, temp_pack_data);
|
|
|
+ if (temp_pack_data.length == temp_pack_data.current_length)
|
|
|
+ {
|
|
|
+ if (conn->pack_eof_check(temp_pack_data))
|
|
|
+ {
|
|
|
+ is_sql_item = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (action_setup == 0)
|
|
|
+ {
|
|
|
+ if (temp_pack_data.length == 2 && (unsigned char)temp_pack_data.data[0] < 251 && (unsigned char)temp_pack_data.data[0] > 0)
|
|
|
+ {
|
|
|
+ action_setup = 1;
|
|
|
+ column_num = (unsigned char)temp_pack_data.data[0];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (action_setup == 1)
|
|
|
+ {
|
|
|
+ field_info_t temp_filed_col;
|
|
|
+ conn->read_col_info(temp_pack_data.data, temp_filed_col);
|
|
|
+
|
|
|
+ field_array.emplace_back(std::move(temp_filed_col));
|
|
|
+ column_num--;
|
|
|
+ if (column_num == 0)
|
|
|
+ {
|
|
|
+ action_setup = 2;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (action_setup == 2)
|
|
|
+ {
|
|
|
+ unsigned int column_num = field_array.size();
|
|
|
+ unsigned int tempnum = 0;
|
|
|
+
|
|
|
+ http::OBJ_VALUE json_temp_v;
|
|
|
+ for (unsigned int ij = 0; ij < column_num; ij++)
|
|
|
+ {
|
|
|
+ unsigned long long name_length = 0;
|
|
|
+ name_length = conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], tempnum);
|
|
|
+
|
|
|
+ std::string temp_str;
|
|
|
+ temp_str.resize(name_length);
|
|
|
+ std::memcpy(temp_str.data(), (unsigned char *)&temp_pack_data.data[tempnum], name_length);
|
|
|
+ if(field_array[ij].name.size()>0)
|
|
|
+ {
|
|
|
+ //or alias name
|
|
|
+ json_temp_v[field_array[ij].name]=std::move(temp_str);
|
|
|
+ }
|
|
|
+ else if(field_array[ij].org_name.size()>0)
|
|
|
+ {
|
|
|
+ json_temp_v[field_array[ij].org_name]=std::move(temp_str);
|
|
|
+ }
|
|
|
+ tempnum = tempnum + name_length;
|
|
|
+ }
|
|
|
+ valuetemp.push(json_temp_v);
|
|
|
+ effect_num++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (offset >= n)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ is_sql_item = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ conn_obj->back_select_conn(conn);
|
|
|
+
|
|
|
+ }
|
|
|
+ catch (const std::exception &e)
|
|
|
+ {
|
|
|
+ error_msg = std::string(e.what());
|
|
|
+ }
|
|
|
+ catch (const std::string &e)
|
|
|
+ {
|
|
|
+ error_msg = e;
|
|
|
+ }
|
|
|
+ catch (...)
|
|
|
+ {
|
|
|
+ }
|
|
|
+ co_return valuetemp;
|
|
|
+ }
|
|
|
+
|
|
|
+ long long get_one(long long id)
|
|
|
+ {
|
|
|
+ effect_num = 0;
|
|
|
+ if (selectsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring = "SELECT * FROM ";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sqlstring = "SELECT ";
|
|
|
+ sqlstring.append(selectsql);
|
|
|
+ sqlstring.append(" FROM ");
|
|
|
+ }
|
|
|
+
|
|
|
+ sqlstring.append(B_BASE::tablename);
|
|
|
+ sqlstring.append(" WHERE ");
|
|
|
+
|
|
|
+ sqlstring.append(B_BASE::getPKname());
|
|
|
+ sqlstring.append("=");
|
|
|
+ sqlstring.append(std::to_string(id));
|
|
|
+ sqlstring.append(" limit 1");
|
|
|
+ if (iscache)
|
|
|
+ {
|
|
|
+ std::size_t sqlhashid = std::hash<std::string>{}(sqlstring);
|
|
|
+ if (get_cacherecord(sqlhashid))
|
|
|
+ {
|
|
|
+ iscache = false;
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ B_BASE::data_reset();
|
|
|
+
|
|
|
+ if (iserror)
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (conn_empty())
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ auto conn = conn_obj->get_select_conn();
|
|
|
+
|
|
|
+ unsigned int querysql_len = sqlstring.length() + 1;
|
|
|
+
|
|
|
+ conn->send_data.clear();
|
|
|
+
|
|
|
+ conn->send_data.push_back((querysql_len & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 8 & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 16 & 0xFF));
|
|
|
+ conn->send_data.push_back(0x00);
|
|
|
+ conn->send_data.push_back(0x03);
|
|
|
+ conn->send_data.append(sqlstring);
|
|
|
+
|
|
|
+ std::size_t n = asio::write(*conn->socket, asio::buffer(conn->send_data), conn->ec);
|
|
|
+
|
|
|
+ if(conn->ec)
|
|
|
+ {
|
|
|
+ error_msg = conn->ec.message();
|
|
|
+ iserror = true;
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ pack_info_t temp_pack_data;
|
|
|
+ temp_pack_data.seq_id = 1;
|
|
|
+ bool is_sql_item = false;
|
|
|
+ std::vector<field_info_t> field_array;
|
|
|
+
|
|
|
+ unsigned char action_setup = 0;
|
|
|
+ unsigned int column_num = 0;
|
|
|
+
|
|
|
+ unsigned int offset = 0;
|
|
|
+
|
|
|
+ std::vector<unsigned char> field_pos;
|
|
|
+
|
|
|
+ for (; is_sql_item == false;)
|
|
|
+ {
|
|
|
+ n = conn->read_loop();
|
|
|
+ offset = 0;
|
|
|
+ for (; offset < n;)
|
|
|
+ {
|
|
|
+ conn->read_field_pack(conn->_cache_data, n, offset, temp_pack_data);
|
|
|
+ if (temp_pack_data.length == temp_pack_data.current_length)
|
|
|
+ {
|
|
|
+ if (conn->pack_eof_check(temp_pack_data))
|
|
|
+ {
|
|
|
+ is_sql_item = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (action_setup == 0)
|
|
|
+ {
|
|
|
+ if (temp_pack_data.length == 2 && (unsigned char)temp_pack_data.data[0] < 251 && (unsigned char)temp_pack_data.data[0] > 0)
|
|
|
+ {
|
|
|
+ action_setup = 1;
|
|
|
+ column_num = (unsigned char)temp_pack_data.data[0];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (action_setup == 1)
|
|
|
+ {
|
|
|
+ field_info_t temp_filed_col;
|
|
|
+ conn->read_col_info(temp_pack_data.data, temp_filed_col);
|
|
|
+
|
|
|
+ field_array.emplace_back(std::move(temp_filed_col));
|
|
|
+ column_num--;
|
|
|
+ if (column_num == 0)
|
|
|
+ {
|
|
|
+ action_setup = 2;
|
|
|
+ for (unsigned int ii = 0; ii < field_array.size(); ii++)
|
|
|
+ {
|
|
|
+ field_pos.push_back(B_BASE::findcolpos(field_array[ii].org_name));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (action_setup == 2)
|
|
|
+ {
|
|
|
+ unsigned int column_num = field_array.size();
|
|
|
+ unsigned int tempnum = 0;
|
|
|
+
|
|
|
+ for (unsigned int ij = 0; ij < column_num; ij++)
|
|
|
+ {
|
|
|
+ unsigned long long name_length = 0;
|
|
|
+ name_length = conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], tempnum);
|
|
|
+
|
|
|
+ assign_field_value(field_pos[ij], (unsigned char *)&temp_pack_data.data[tempnum], name_length, B_BASE::data);
|
|
|
+ tempnum = tempnum + name_length;
|
|
|
+ }
|
|
|
+
|
|
|
+ effect_num++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (offset >= n)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ is_sql_item = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ conn_obj->back_select_conn(conn);
|
|
|
+
|
|
|
+ if (iscache)
|
|
|
+ {
|
|
|
+ if (exptime > 0)
|
|
|
+ {
|
|
|
+ save_cache(exptime);
|
|
|
+ exptime = 0;
|
|
|
+ iscache = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ catch (const std::exception &e)
|
|
|
+ {
|
|
|
+ error_msg = std::string(e.what());
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ catch (const std::string &e)
|
|
|
+ {
|
|
|
+ error_msg = e;
|
|
|
+ }
|
|
|
+ catch (...)
|
|
|
+ {
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ asio::awaitable<long long> async_get_one(long long id)
|
|
|
+ {
|
|
|
+ effect_num = 0;
|
|
|
+ if (selectsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring = "SELECT * FROM ";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sqlstring = "SELECT ";
|
|
|
+ sqlstring.append(selectsql);
|
|
|
+ sqlstring.append(" FROM ");
|
|
|
+ }
|
|
|
+
|
|
|
+ sqlstring.append(B_BASE::tablename);
|
|
|
+ sqlstring.append(" WHERE ");
|
|
|
+
|
|
|
+ sqlstring.append(B_BASE::getPKname());
|
|
|
+ sqlstring.append("=");
|
|
|
+ sqlstring.append(std::to_string(id));
|
|
|
+ sqlstring.append(" limit 1");
|
|
|
+ if (iscache)
|
|
|
+ {
|
|
|
+ std::size_t sqlhashid = std::hash<std::string>{}(sqlstring);
|
|
|
+ if (get_cacherecord(sqlhashid))
|
|
|
+ {
|
|
|
+ iscache = false;
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ B_BASE::data_reset();
|
|
|
+
|
|
|
+ if (iserror)
|
|
|
+ {
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (conn_empty())
|
|
|
+ {
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ auto conn = co_await conn_obj->async_get_select_conn();
|
|
|
+
|
|
|
+ unsigned int querysql_len = sqlstring.length() + 1;
|
|
|
+
|
|
|
+ conn->send_data.clear();
|
|
|
+
|
|
|
+ conn->send_data.push_back((querysql_len & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 8 & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 16 & 0xFF));
|
|
|
+ conn->send_data.push_back(0x00);
|
|
|
+ conn->send_data.push_back(0x03);
|
|
|
+ conn->send_data.append(sqlstring);
|
|
|
+
|
|
|
+ std::size_t n = co_await asio::async_write(*conn->socket, asio::buffer(conn->send_data), asio::use_awaitable);
|
|
|
+
|
|
|
+
|
|
|
+ pack_info_t temp_pack_data;
|
|
|
+ temp_pack_data.seq_id = 1;
|
|
|
+ bool is_sql_item = false;
|
|
|
+ std::vector<field_info_t> field_array;
|
|
|
+
|
|
|
+ unsigned char action_setup = 0;
|
|
|
+ unsigned int column_num = 0;
|
|
|
+
|
|
|
+ unsigned int offset = 0;
|
|
|
+
|
|
|
+ std::vector<unsigned char> field_pos;
|
|
|
+
|
|
|
+ for (; is_sql_item == false;)
|
|
|
+ {
|
|
|
+ n = co_await conn->async_read_loop();
|
|
|
+ offset = 0;
|
|
|
+ for (; offset < n;)
|
|
|
+ {
|
|
|
+ conn->read_field_pack(conn->_cache_data, n, offset, temp_pack_data);
|
|
|
+ if (temp_pack_data.length == temp_pack_data.current_length)
|
|
|
+ {
|
|
|
+ if (conn->pack_eof_check(temp_pack_data))
|
|
|
+ {
|
|
|
+ is_sql_item = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (action_setup == 0)
|
|
|
+ {
|
|
|
+ if (temp_pack_data.length == 2 && (unsigned char)temp_pack_data.data[0] < 251 && (unsigned char)temp_pack_data.data[0] > 0)
|
|
|
+ {
|
|
|
+ action_setup = 1;
|
|
|
+ column_num = (unsigned char)temp_pack_data.data[0];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (action_setup == 1)
|
|
|
+ {
|
|
|
+ field_info_t temp_filed_col;
|
|
|
+ conn->read_col_info(temp_pack_data.data, temp_filed_col);
|
|
|
+
|
|
|
+ field_array.emplace_back(std::move(temp_filed_col));
|
|
|
+ column_num--;
|
|
|
+ if (column_num == 0)
|
|
|
+ {
|
|
|
+ action_setup = 2;
|
|
|
+ for (unsigned int ii = 0; ii < field_array.size(); ii++)
|
|
|
+ {
|
|
|
+ field_pos.push_back(B_BASE::findcolpos(field_array[ii].org_name));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (action_setup == 2)
|
|
|
+ {
|
|
|
+ unsigned int column_num = field_array.size();
|
|
|
+ unsigned int tempnum = 0;
|
|
|
+
|
|
|
+ for (unsigned int ij = 0; ij < column_num; ij++)
|
|
|
+ {
|
|
|
+ unsigned long long name_length = 0;
|
|
|
+ name_length = conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], tempnum);
|
|
|
+
|
|
|
+ assign_field_value(field_pos[ij], (unsigned char *)&temp_pack_data.data[tempnum], name_length, B_BASE::data);
|
|
|
+ tempnum = tempnum + name_length;
|
|
|
+ }
|
|
|
+
|
|
|
+ effect_num++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (offset >= n)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ is_sql_item = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ conn_obj->back_select_conn(conn);
|
|
|
+
|
|
|
+ if (iscache)
|
|
|
+ {
|
|
|
+ if (exptime > 0)
|
|
|
+ {
|
|
|
+ save_cache(exptime);
|
|
|
+ exptime = 0;
|
|
|
+ iscache = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ co_return effect_num;
|
|
|
+ }
|
|
|
+ catch (const std::exception &e)
|
|
|
+ {
|
|
|
+ error_msg = std::string(e.what());
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ catch (const std::string &e)
|
|
|
+ {
|
|
|
+ error_msg = e;
|
|
|
+ }
|
|
|
+ catch (...)
|
|
|
+ {
|
|
|
+ }
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ int update()
|
|
|
+ {
|
|
|
+ effect_num = 0;
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ if (B_BASE::getPK() > 0)
|
|
|
+ {
|
|
|
+ std::ostringstream tempsql;
|
|
|
+ tempsql << " ";
|
|
|
+ tempsql << B_BASE::getPKname();
|
|
|
+ tempsql << " = '";
|
|
|
+ tempsql << B_BASE::getPK();
|
|
|
+ tempsql << "' ";
|
|
|
+ wheresql = tempsql.str();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sqlstring = B_BASE::_makeupdatesql("");
|
|
|
+ sqlstring.append(" where ");
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sqlstring.append(wheresql);
|
|
|
+ }
|
|
|
+ if (!groupsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(groupsql);
|
|
|
+ }
|
|
|
+ if (!ordersql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(ordersql);
|
|
|
+ }
|
|
|
+ if (!limitsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(limitsql);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iscommit)
|
|
|
+ {
|
|
|
+ iscommit = false;
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iserror)
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (conn_empty())
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ auto conn = conn_obj->get_edit_conn();
|
|
|
+
|
|
|
+ unsigned int querysql_len = sqlstring.length() + 1;
|
|
|
+
|
|
|
+ conn->send_data.clear();
|
|
|
+ conn->send_data.push_back((querysql_len & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 8 & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 16 & 0xFF));
|
|
|
+ conn->send_data.push_back(0x00);
|
|
|
+ conn->send_data.push_back(0x03);
|
|
|
+ conn->send_data.append(sqlstring);
|
|
|
+
|
|
|
+ std::size_t n = asio::write(*conn->socket, asio::buffer(conn->send_data), conn->ec);
|
|
|
+
|
|
|
+ if(conn->ec)
|
|
|
+ {
|
|
|
+ error_msg = conn->ec.message();
|
|
|
+ iserror = true;
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ unsigned int offset = 0;
|
|
|
+ n = conn->read_loop();
|
|
|
+
|
|
|
+ pack_info_t temp_pack_data;
|
|
|
+ temp_pack_data.seq_id = 1;
|
|
|
+ conn->read_field_pack(conn->_cache_data, n, offset, temp_pack_data);
|
|
|
+
|
|
|
+ conn_obj->back_edit_conn(conn);
|
|
|
+
|
|
|
+ if ((unsigned char)temp_pack_data.data[0] == 0xFF)
|
|
|
+ {
|
|
|
+ error_msg = temp_pack_data.data.substr(3);
|
|
|
+ }
|
|
|
+ else if ((unsigned char)temp_pack_data.data[0] == 0x00)
|
|
|
+ {
|
|
|
+
|
|
|
+ unsigned int d_offset = 1;
|
|
|
+ effect_num = conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], d_offset);
|
|
|
+ return effect_num;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ catch (const std::exception &e)
|
|
|
+ {
|
|
|
+ error_msg = std::string(e.what());
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ catch (const std::string &e)
|
|
|
+ {
|
|
|
+ error_msg = e;
|
|
|
+ }
|
|
|
+ catch (...)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ int update(const std::string &fieldname)
|
|
|
+ {
|
|
|
+ effect_num = 0;
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ if (B_BASE::getPK() > 0)
|
|
|
+ {
|
|
|
+ std::ostringstream tempsql;
|
|
|
+ tempsql << " ";
|
|
|
+ tempsql << B_BASE::getPKname();
|
|
|
+ tempsql << " = '";
|
|
|
+ tempsql << B_BASE::getPK();
|
|
|
+ tempsql << "' ";
|
|
|
+ wheresql = tempsql.str();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ error_msg = "warning empty where sql!";
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ sqlstring = B_BASE::_makeupdatesql(fieldname);
|
|
|
+ sqlstring.append(" where ");
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sqlstring.append(wheresql);
|
|
|
+ }
|
|
|
+ if (!groupsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(groupsql);
|
|
|
+ }
|
|
|
+ if (!ordersql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(ordersql);
|
|
|
+ }
|
|
|
+ if (!limitsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(limitsql);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iscommit)
|
|
|
+ {
|
|
|
+ iscommit = false;
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iserror)
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (conn_empty())
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ auto conn = conn_obj->get_edit_conn();
|
|
|
+
|
|
|
+ unsigned int querysql_len = sqlstring.length() + 1;
|
|
|
+
|
|
|
+ conn->send_data.clear();
|
|
|
+ conn->send_data.push_back((querysql_len & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 8 & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 16 & 0xFF));
|
|
|
+ conn->send_data.push_back(0x00);
|
|
|
+ conn->send_data.push_back(0x03);
|
|
|
+ conn->send_data.append(sqlstring);
|
|
|
+
|
|
|
+ std::size_t n = asio::write(*conn->socket, asio::buffer(conn->send_data), conn->ec);
|
|
|
+
|
|
|
+ if(conn->ec)
|
|
|
+ {
|
|
|
+ error_msg = conn->ec.message();
|
|
|
+ iserror = true;
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ unsigned int offset = 0;
|
|
|
+ n = conn->read_loop();
|
|
|
+
|
|
|
+ pack_info_t temp_pack_data;
|
|
|
+ temp_pack_data.seq_id = 1;
|
|
|
+ conn->read_field_pack(conn->_cache_data, n, offset, temp_pack_data);
|
|
|
+
|
|
|
+ conn_obj->back_edit_conn(conn);
|
|
|
+
|
|
|
+ if ((unsigned char)temp_pack_data.data[0] == 0xFF)
|
|
|
+ {
|
|
|
+ error_msg = temp_pack_data.data.substr(3);
|
|
|
+ }
|
|
|
+ else if ((unsigned char)temp_pack_data.data[0] == 0x00)
|
|
|
+ {
|
|
|
+
|
|
|
+ unsigned int d_offset = 1;
|
|
|
+ effect_num = conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], d_offset);
|
|
|
+ return effect_num;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ catch (const std::exception &e)
|
|
|
+ {
|
|
|
+ error_msg = std::string(e.what());
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ catch (const std::string &e)
|
|
|
+ {
|
|
|
+ error_msg = e;
|
|
|
+ }
|
|
|
+ catch (...)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ asio::awaitable<int> async_update(const std::string &fieldname)
|
|
|
+ {
|
|
|
+ effect_num = 0;
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ if (B_BASE::getPK() > 0)
|
|
|
+ {
|
|
|
+ std::ostringstream tempsql;
|
|
|
+ tempsql << " ";
|
|
|
+ tempsql << B_BASE::getPKname();
|
|
|
+ tempsql << " = '";
|
|
|
+ tempsql << B_BASE::getPK();
|
|
|
+ tempsql << "' ";
|
|
|
+ wheresql = tempsql.str();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ error_msg = "warning empty where sql!";
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ sqlstring = B_BASE::_makeupdatesql(fieldname);
|
|
|
+ sqlstring.append(" where ");
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sqlstring.append(wheresql);
|
|
|
+ }
|
|
|
+ if (!groupsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(groupsql);
|
|
|
+ }
|
|
|
+ if (!ordersql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(ordersql);
|
|
|
+ }
|
|
|
+ if (!limitsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(limitsql);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iscommit)
|
|
|
+ {
|
|
|
+ iscommit = false;
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iserror)
|
|
|
+ {
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ try
|
|
|
+ {
|
|
|
+
|
|
|
+ if (conn_empty())
|
|
|
+ {
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ auto conn = co_await conn_obj->async_get_edit_conn();
|
|
|
+
|
|
|
+ unsigned int querysql_len = sqlstring.length() + 1;
|
|
|
+
|
|
|
+ conn->send_data.clear();
|
|
|
+ conn->send_data.push_back((querysql_len & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 8 & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 16 & 0xFF));
|
|
|
+ conn->send_data.push_back(0x00);
|
|
|
+ conn->send_data.push_back(0x03);
|
|
|
+ conn->send_data.append(sqlstring);
|
|
|
+
|
|
|
+ std::size_t n = co_await asio::async_write(*conn->socket, asio::buffer(conn->send_data), asio::use_awaitable);
|
|
|
+
|
|
|
+ unsigned int offset = 0;
|
|
|
+ n = co_await conn->async_read_loop();
|
|
|
+
|
|
|
+ pack_info_t temp_pack_data;
|
|
|
+ temp_pack_data.seq_id = 1;
|
|
|
+ conn->read_field_pack(conn->_cache_data, n, offset, temp_pack_data);
|
|
|
+
|
|
|
+ conn_obj->back_edit_conn(conn);
|
|
|
+
|
|
|
+ if ((unsigned char)temp_pack_data.data[0] == 0xFF)
|
|
|
+ {
|
|
|
+ error_msg = temp_pack_data.data.substr(3);
|
|
|
+ iserror = true;
|
|
|
+ }
|
|
|
+ else if ((unsigned char)temp_pack_data.data[0] == 0x00)
|
|
|
+ {
|
|
|
+
|
|
|
+ unsigned int d_offset = 1;
|
|
|
+ effect_num = conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], d_offset);
|
|
|
+
|
|
|
+ co_return effect_num;
|
|
|
+ }
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ catch (const std::exception &e)
|
|
|
+ {
|
|
|
+ error_msg = std::string(e.what());
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ catch (const std::string &e)
|
|
|
+ {
|
|
|
+ error_msg = e;
|
|
|
+ }
|
|
|
+ catch (...)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ asio::awaitable<int> async_update()
|
|
|
+ {
|
|
|
+ effect_num = 0;
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ if (B_BASE::getPK() > 0)
|
|
|
+ {
|
|
|
+ std::ostringstream tempsql;
|
|
|
+ tempsql << " ";
|
|
|
+ tempsql << B_BASE::getPKname();
|
|
|
+ tempsql << " = '";
|
|
|
+ tempsql << B_BASE::getPK();
|
|
|
+ tempsql << "' ";
|
|
|
+ wheresql = tempsql.str();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ error_msg = "warning empty where sql!";
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ sqlstring = B_BASE::_makeupdatesql("");
|
|
|
+ sqlstring.append(" where ");
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sqlstring.append(wheresql);
|
|
|
+ }
|
|
|
+ if (!groupsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(groupsql);
|
|
|
+ }
|
|
|
+ if (!ordersql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(ordersql);
|
|
|
+ }
|
|
|
+ if (!limitsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(limitsql);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iscommit)
|
|
|
+ {
|
|
|
+ iscommit = false;
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iserror)
|
|
|
+ {
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ try
|
|
|
+ {
|
|
|
+
|
|
|
+ if (conn_empty())
|
|
|
+ {
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ auto conn = co_await conn_obj->async_get_edit_conn();
|
|
|
+
|
|
|
+ unsigned int querysql_len = sqlstring.length() + 1;
|
|
|
+
|
|
|
+ conn->send_data.clear();
|
|
|
+ conn->send_data.push_back((querysql_len & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 8 & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 16 & 0xFF));
|
|
|
+ conn->send_data.push_back(0x00);
|
|
|
+ conn->send_data.push_back(0x03);
|
|
|
+ conn->send_data.append(sqlstring);
|
|
|
+
|
|
|
+ std::size_t n = co_await asio::async_write(*conn->socket, asio::buffer(conn->send_data), asio::use_awaitable);
|
|
|
+
|
|
|
+ unsigned int offset = 0;
|
|
|
+ n = co_await conn->async_read_loop();
|
|
|
+
|
|
|
+ pack_info_t temp_pack_data;
|
|
|
+ temp_pack_data.seq_id = 1;
|
|
|
+ conn->read_field_pack(conn->_cache_data, n, offset, temp_pack_data);
|
|
|
+
|
|
|
+ conn_obj->back_edit_conn(conn);
|
|
|
+
|
|
|
+ if ((unsigned char)temp_pack_data.data[0] == 0xFF)
|
|
|
+ {
|
|
|
+ error_msg = temp_pack_data.data.substr(3);
|
|
|
+ iserror = true;
|
|
|
+ }
|
|
|
+ else if ((unsigned char)temp_pack_data.data[0] == 0x00)
|
|
|
+ {
|
|
|
+
|
|
|
+ unsigned int d_offset = 1;
|
|
|
+ effect_num = conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], d_offset);
|
|
|
+
|
|
|
+ co_return effect_num;
|
|
|
+ }
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ catch (const std::exception &e)
|
|
|
+ {
|
|
|
+ error_msg = std::string(e.what());
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ catch (const std::string &e)
|
|
|
+ {
|
|
|
+ error_msg = e;
|
|
|
+ }
|
|
|
+ catch (...)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ int update_batch(const std::string &fieldname)
|
|
|
+ {
|
|
|
+ effect_num = 0;
|
|
|
+ if (B_BASE::record.size() == 0)
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ if (fieldname.size() > 0)
|
|
|
+ {
|
|
|
+ sqlstring = B_BASE::_make_insert_into_sql(fieldname);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sqlstring = B_BASE::_make_replace_into_sql();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iserror)
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (conn_empty())
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ auto conn = conn_obj->get_edit_conn();
|
|
|
+
|
|
|
+ unsigned int querysql_len = sqlstring.length() + 1;
|
|
|
+
|
|
|
+ conn->send_data.clear();
|
|
|
+ conn->send_data.push_back((querysql_len & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 8 & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 16 & 0xFF));
|
|
|
+ conn->send_data.push_back(0x00);
|
|
|
+ conn->send_data.push_back(0x03);
|
|
|
+ conn->send_data.append(sqlstring);
|
|
|
+
|
|
|
+ std::size_t n = asio::write(*conn->socket, asio::buffer(conn->send_data), conn->ec);
|
|
|
+
|
|
|
+ if(conn->ec)
|
|
|
+ {
|
|
|
+ error_msg = conn->ec.message();
|
|
|
+ iserror = true;
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ unsigned int offset = 0;
|
|
|
+ n = conn->read_loop();
|
|
|
+
|
|
|
+ pack_info_t temp_pack_data;
|
|
|
+ temp_pack_data.seq_id = 1;
|
|
|
+ conn->read_field_pack(conn->_cache_data, n, offset, temp_pack_data);
|
|
|
+
|
|
|
+ conn_obj->back_edit_conn(conn);
|
|
|
+
|
|
|
+ if ((unsigned char)temp_pack_data.data[0] == 0xFF)
|
|
|
+ {
|
|
|
+ error_msg = temp_pack_data.data.substr(3);
|
|
|
+ }
|
|
|
+ else if ((unsigned char)temp_pack_data.data[0] == 0x00)
|
|
|
+ {
|
|
|
+
|
|
|
+ unsigned int d_offset = 1;
|
|
|
+ effect_num = conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], d_offset);
|
|
|
+ return effect_num;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ catch (const std::exception &e)
|
|
|
+ {
|
|
|
+ error_msg = std::string(e.what());
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ catch (const std::string &e)
|
|
|
+ {
|
|
|
+ error_msg = e;
|
|
|
+ }
|
|
|
+ catch (...)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ int remove()
|
|
|
+ {
|
|
|
+ effect_num = 0;
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ if (B_BASE::getPK() > 0)
|
|
|
+ {
|
|
|
+ std::ostringstream tempsql;
|
|
|
+ tempsql << " ";
|
|
|
+ tempsql << B_BASE::getPKname();
|
|
|
+ tempsql << " = '";
|
|
|
+ tempsql << B_BASE::getPK();
|
|
|
+ tempsql << "' ";
|
|
|
+ wheresql = tempsql.str();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ sqlstring = "DELETE FROM ";
|
|
|
+ sqlstring.append(B_BASE::tablename);
|
|
|
+ sqlstring.append(" WHERE ");
|
|
|
+
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sqlstring.append(wheresql);
|
|
|
+ }
|
|
|
+ if (!groupsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(groupsql);
|
|
|
+ }
|
|
|
+ if (!ordersql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(ordersql);
|
|
|
+ }
|
|
|
+ if (!limitsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(limitsql);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iscommit)
|
|
|
+ {
|
|
|
+ iscommit = false;
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iserror)
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (conn_empty())
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ auto conn = conn_obj->get_edit_conn();
|
|
|
+
|
|
|
+ unsigned int querysql_len = sqlstring.length() + 1;
|
|
|
+
|
|
|
+ conn->send_data.clear();
|
|
|
+ conn->send_data.push_back((querysql_len & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 8 & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 16 & 0xFF));
|
|
|
+ conn->send_data.push_back(0x00);
|
|
|
+ conn->send_data.push_back(0x03);
|
|
|
+ conn->send_data.append(sqlstring);
|
|
|
+
|
|
|
+ std::size_t n = asio::write(*conn->socket, asio::buffer(conn->send_data), conn->ec);
|
|
|
+
|
|
|
+ if(conn->ec)
|
|
|
+ {
|
|
|
+ error_msg = conn->ec.message();
|
|
|
+ iserror = true;
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ unsigned int offset = 0;
|
|
|
+ n = conn->read_loop();
|
|
|
+
|
|
|
+ pack_info_t temp_pack_data;
|
|
|
+ temp_pack_data.seq_id = 1;
|
|
|
+ conn->read_field_pack(conn->_cache_data, n, offset, temp_pack_data);
|
|
|
+
|
|
|
+ conn_obj->back_edit_conn(conn);
|
|
|
+
|
|
|
+ if ((unsigned char)temp_pack_data.data[0] == 0xFF)
|
|
|
+ {
|
|
|
+ error_msg = temp_pack_data.data.substr(3);
|
|
|
+ }
|
|
|
+ else if ((unsigned char)temp_pack_data.data[0] == 0x00)
|
|
|
+ {
|
|
|
+
|
|
|
+ unsigned int d_offset = 1;
|
|
|
+ effect_num = conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], d_offset);
|
|
|
+ return effect_num;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ catch (const std::exception &e)
|
|
|
+ {
|
|
|
+ error_msg = std::string(e.what());
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ catch (const std::string &e)
|
|
|
+ {
|
|
|
+ error_msg = e;
|
|
|
+ }
|
|
|
+ catch (...)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ asio::awaitable<unsigned int> async_remove()
|
|
|
+ {
|
|
|
+ effect_num = 0;
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ if (B_BASE::getPK() > 0)
|
|
|
+ {
|
|
|
+ std::ostringstream tempsql;
|
|
|
+ tempsql << " ";
|
|
|
+ tempsql << B_BASE::getPKname();
|
|
|
+ tempsql << " = '";
|
|
|
+ tempsql << B_BASE::getPK();
|
|
|
+ tempsql << "' ";
|
|
|
+ wheresql = tempsql.str();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ sqlstring = "DELETE FROM ";
|
|
|
+ sqlstring.append(B_BASE::tablename);
|
|
|
+ sqlstring.append(" WHERE ");
|
|
|
+
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sqlstring.append(wheresql);
|
|
|
+ }
|
|
|
+ if (!groupsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(groupsql);
|
|
|
+ }
|
|
|
+ if (!ordersql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(ordersql);
|
|
|
+ }
|
|
|
+ if (!limitsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(limitsql);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iscommit)
|
|
|
+ {
|
|
|
+ iscommit = false;
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iserror)
|
|
|
+ {
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (conn_empty())
|
|
|
+ {
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ auto conn = co_await conn_obj->async_get_edit_conn();
|
|
|
+
|
|
|
+ unsigned int querysql_len = sqlstring.length() + 1;
|
|
|
+
|
|
|
+ conn->send_data.clear();
|
|
|
+ conn->send_data.push_back((querysql_len & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 8 & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 16 & 0xFF));
|
|
|
+ conn->send_data.push_back(0x00);
|
|
|
+ conn->send_data.push_back(0x03);
|
|
|
+ conn->send_data.append(sqlstring);
|
|
|
+
|
|
|
+ std::size_t n = co_await asio::async_write(*conn->socket, asio::buffer(conn->send_data), asio::use_awaitable);
|
|
|
+
|
|
|
+ unsigned int offset = 0;
|
|
|
+ n = co_await conn->async_read_loop();
|
|
|
+
|
|
|
+ pack_info_t temp_pack_data;
|
|
|
+ temp_pack_data.seq_id = 1;
|
|
|
+ conn->read_field_pack(conn->_cache_data, n, offset, temp_pack_data);
|
|
|
+
|
|
|
+ conn_obj->back_edit_conn(conn);
|
|
|
+
|
|
|
+ if ((unsigned char)temp_pack_data.data[0] == 0xFF)
|
|
|
+ {
|
|
|
+ error_msg = temp_pack_data.data.substr(3);
|
|
|
+ }
|
|
|
+ else if ((unsigned char)temp_pack_data.data[0] == 0x00)
|
|
|
+ {
|
|
|
+
|
|
|
+ unsigned int d_offset = 1;
|
|
|
+ effect_num = conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], d_offset);
|
|
|
+ co_return effect_num;
|
|
|
+ }
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ catch (const std::exception &e)
|
|
|
+ {
|
|
|
+ error_msg = std::string(e.what());
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ catch (const std::string &e)
|
|
|
+ {
|
|
|
+ error_msg = e;
|
|
|
+ }
|
|
|
+ catch (...)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ int remove(long long id)
|
|
|
+ {
|
|
|
+ effect_num = 0;
|
|
|
+ sqlstring = "DELETE FROM ";
|
|
|
+ sqlstring.append(B_BASE::tablename);
|
|
|
+ sqlstring.append(" WHERE ");
|
|
|
+
|
|
|
+ sqlstring.append(B_BASE::getPKname());
|
|
|
+ sqlstring.append("=");
|
|
|
+ sqlstring.append(std::to_string(id));
|
|
|
+
|
|
|
+ if (iscommit)
|
|
|
+ {
|
|
|
+ iscommit = false;
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iserror)
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (conn_empty())
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ auto conn = conn_obj->get_edit_conn();
|
|
|
+
|
|
|
+ unsigned int querysql_len = sqlstring.length() + 1;
|
|
|
+
|
|
|
+ conn->send_data.clear();
|
|
|
+ conn->send_data.push_back((querysql_len & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 8 & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 16 & 0xFF));
|
|
|
+ conn->send_data.push_back(0x00);
|
|
|
+ conn->send_data.push_back(0x03);
|
|
|
+ conn->send_data.append(sqlstring);
|
|
|
+
|
|
|
+ std::size_t n = asio::write(*conn->socket, asio::buffer(conn->send_data), conn->ec);
|
|
|
+
|
|
|
+ if(conn->ec)
|
|
|
+ {
|
|
|
+ error_msg = conn->ec.message();
|
|
|
+ iserror = true;
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ unsigned int offset = 0;
|
|
|
+ n = conn->read_loop();
|
|
|
+
|
|
|
+ pack_info_t temp_pack_data;
|
|
|
+ temp_pack_data.seq_id = 1;
|
|
|
+ conn->read_field_pack(conn->_cache_data, n, offset, temp_pack_data);
|
|
|
+
|
|
|
+ conn_obj->back_edit_conn(conn);
|
|
|
+
|
|
|
+ if ((unsigned char)temp_pack_data.data[0] == 0xFF)
|
|
|
+ {
|
|
|
+ error_msg = temp_pack_data.data.substr(3);
|
|
|
+ }
|
|
|
+ else if ((unsigned char)temp_pack_data.data[0] == 0x00)
|
|
|
+ {
|
|
|
+
|
|
|
+ unsigned int d_offset = 1;
|
|
|
+ effect_num = conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], d_offset);
|
|
|
+ return effect_num;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ catch (const std::exception &e)
|
|
|
+ {
|
|
|
+ error_msg = std::string(e.what());
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ catch (const std::string &e)
|
|
|
+ {
|
|
|
+ error_msg = e;
|
|
|
+ }
|
|
|
+ catch (...)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ asio::awaitable<unsigned int> async_remove(long long id)
|
|
|
+ {
|
|
|
+ effect_num = 0;
|
|
|
+ sqlstring = "DELETE FROM ";
|
|
|
+ sqlstring.append(B_BASE::tablename);
|
|
|
+ sqlstring.append(" WHERE ");
|
|
|
+
|
|
|
+ sqlstring.append(B_BASE::getPKname());
|
|
|
+ sqlstring.append("=");
|
|
|
+ sqlstring.append(std::to_string(id));
|
|
|
+
|
|
|
+ if (iscommit)
|
|
|
+ {
|
|
|
+ iscommit = false;
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iserror)
|
|
|
+ {
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (conn_empty())
|
|
|
+ {
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ auto conn = co_await conn_obj->async_get_edit_conn();
|
|
|
+
|
|
|
+ unsigned int querysql_len = sqlstring.length() + 1;
|
|
|
+
|
|
|
+ conn->send_data.clear();
|
|
|
+ conn->send_data.push_back((querysql_len & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 8 & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 16 & 0xFF));
|
|
|
+ conn->send_data.push_back(0x00);
|
|
|
+ conn->send_data.push_back(0x03);
|
|
|
+ conn->send_data.append(sqlstring);
|
|
|
+
|
|
|
+ std::size_t n = co_await asio::async_write(*conn->socket, asio::buffer(conn->send_data), asio::use_awaitable);
|
|
|
+
|
|
|
+ unsigned int offset = 0;
|
|
|
+ n = co_await conn->async_read_loop();
|
|
|
+
|
|
|
+ pack_info_t temp_pack_data;
|
|
|
+ temp_pack_data.seq_id = 1;
|
|
|
+ conn->read_field_pack(conn->_cache_data, n, offset, temp_pack_data);
|
|
|
+
|
|
|
+ conn_obj->back_edit_conn(conn);
|
|
|
+
|
|
|
+ if ((unsigned char)temp_pack_data.data[0] == 0xFF)
|
|
|
+ {
|
|
|
+ error_msg = temp_pack_data.data.substr(3);
|
|
|
+ }
|
|
|
+ else if ((unsigned char)temp_pack_data.data[0] == 0x00)
|
|
|
+ {
|
|
|
+
|
|
|
+ unsigned int d_offset = 1;
|
|
|
+ effect_num = conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], d_offset);
|
|
|
+ co_return effect_num;
|
|
|
+ }
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ catch (const std::exception &e)
|
|
|
+ {
|
|
|
+ error_msg = std::string(e.what());
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ catch (const std::string &e)
|
|
|
+ {
|
|
|
+ error_msg = e;
|
|
|
+ }
|
|
|
+ catch (...)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ int soft_remove(const std::string &fieldsql)
|
|
|
+ {
|
|
|
+ effect_num = 0;
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ if (B_BASE::getPK() > 0)
|
|
|
+ {
|
|
|
+ std::ostringstream tempsql;
|
|
|
+ tempsql << " ";
|
|
|
+ tempsql << B_BASE::getPKname();
|
|
|
+ tempsql << " = '";
|
|
|
+ tempsql << B_BASE::getPK();
|
|
|
+ tempsql << "' ";
|
|
|
+ wheresql = tempsql.str();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ sqlstring = B_BASE::soft_remove_sql(fieldsql);
|
|
|
+ if (sqlstring.empty())
|
|
|
+ {
|
|
|
+ error_msg = "soft delete field empty.";
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ sqlstring.append(" where ");
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sqlstring.append(wheresql);
|
|
|
+ }
|
|
|
+ if (!groupsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(groupsql);
|
|
|
+ }
|
|
|
+ if (!ordersql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(ordersql);
|
|
|
+ }
|
|
|
+ if (!limitsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(limitsql);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iscommit)
|
|
|
+ {
|
|
|
+ iscommit = false;
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iserror)
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (conn_empty())
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ auto conn = conn_obj->get_edit_conn();
|
|
|
+
|
|
|
+ unsigned int querysql_len = sqlstring.length() + 1;
|
|
|
+
|
|
|
+ conn->send_data.clear();
|
|
|
+ conn->send_data.push_back((querysql_len & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 8 & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 16 & 0xFF));
|
|
|
+ conn->send_data.push_back(0x00);
|
|
|
+ conn->send_data.push_back(0x03);
|
|
|
+ conn->send_data.append(sqlstring);
|
|
|
+
|
|
|
+ std::size_t n = asio::write(*conn->socket, asio::buffer(conn->send_data), conn->ec);
|
|
|
+
|
|
|
+ if(conn->ec)
|
|
|
+ {
|
|
|
+ error_msg = conn->ec.message();
|
|
|
+ iserror = true;
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ unsigned int offset = 0;
|
|
|
+ n = conn->read_loop();
|
|
|
+
|
|
|
+ pack_info_t temp_pack_data;
|
|
|
+ temp_pack_data.seq_id = 1;
|
|
|
+ conn->read_field_pack(conn->_cache_data, n, offset, temp_pack_data);
|
|
|
+
|
|
|
+ conn_obj->back_edit_conn(conn);
|
|
|
+
|
|
|
+ if ((unsigned char)temp_pack_data.data[0] == 0xFF)
|
|
|
+ {
|
|
|
+ error_msg = temp_pack_data.data.substr(3);
|
|
|
+ }
|
|
|
+ else if ((unsigned char)temp_pack_data.data[0] == 0x00)
|
|
|
+ {
|
|
|
+
|
|
|
+ unsigned int d_offset = 1;
|
|
|
+ effect_num = conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], d_offset);
|
|
|
+ return effect_num;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ catch (const std::exception &e)
|
|
|
+ {
|
|
|
+ error_msg = std::string(e.what());
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ catch (const std::string &e)
|
|
|
+ {
|
|
|
+ error_msg = e;
|
|
|
+ }
|
|
|
+ catch (...)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ int soft_remove()
|
|
|
+ {
|
|
|
+ effect_num = 0;
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ if (B_BASE::getPK() > 0)
|
|
|
+ {
|
|
|
+ std::ostringstream tempsql;
|
|
|
+ effect_num = 1;
|
|
|
+ tempsql << " ";
|
|
|
+ tempsql << B_BASE::getPKname();
|
|
|
+ tempsql << " = '";
|
|
|
+ tempsql << B_BASE::getPK();
|
|
|
+ tempsql << "' ";
|
|
|
+ wheresql = tempsql.str();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (effect_num == 1)
|
|
|
+ {
|
|
|
+ sqlstring = B_BASE::soft_remove_sql(" ");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sqlstring = B_BASE::soft_remove_sql("");
|
|
|
+ }
|
|
|
+ effect_num = 0;
|
|
|
+ if (sqlstring.empty())
|
|
|
+ {
|
|
|
+ error_msg = "soft delete field empty.";
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ sqlstring.append(" where ");
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sqlstring.append(wheresql);
|
|
|
+ }
|
|
|
+ if (!groupsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(groupsql);
|
|
|
+ }
|
|
|
+ if (!ordersql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(ordersql);
|
|
|
+ }
|
|
|
+ if (!limitsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(limitsql);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iscommit)
|
|
|
+ {
|
|
|
+ iscommit = false;
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iserror)
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (conn_empty())
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ auto conn = conn_obj->get_edit_conn();
|
|
|
+
|
|
|
+ unsigned int querysql_len = sqlstring.length() + 1;
|
|
|
+
|
|
|
+ conn->send_data.clear();
|
|
|
+ conn->send_data.push_back((querysql_len & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 8 & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 16 & 0xFF));
|
|
|
+ conn->send_data.push_back(0x00);
|
|
|
+ conn->send_data.push_back(0x03);
|
|
|
+ conn->send_data.append(sqlstring);
|
|
|
+
|
|
|
+ std::size_t n = asio::write(*conn->socket, asio::buffer(conn->send_data), conn->ec);
|
|
|
+
|
|
|
+ if(conn->ec)
|
|
|
+ {
|
|
|
+ error_msg = conn->ec.message();
|
|
|
+ iserror = true;
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ unsigned int offset = 0;
|
|
|
+ n = conn->read_loop();
|
|
|
+
|
|
|
+ pack_info_t temp_pack_data;
|
|
|
+ temp_pack_data.seq_id = 1;
|
|
|
+ conn->read_field_pack(conn->_cache_data, n, offset, temp_pack_data);
|
|
|
+
|
|
|
+ conn_obj->back_edit_conn(conn);
|
|
|
+
|
|
|
+ if ((unsigned char)temp_pack_data.data[0] == 0xFF)
|
|
|
+ {
|
|
|
+ error_msg = temp_pack_data.data.substr(3);
|
|
|
+ }
|
|
|
+ else if ((unsigned char)temp_pack_data.data[0] == 0x00)
|
|
|
+ {
|
|
|
+
|
|
|
+ unsigned int d_offset = 1;
|
|
|
+ effect_num = conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], d_offset);
|
|
|
+ return effect_num;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ catch (const std::exception &e)
|
|
|
+ {
|
|
|
+ error_msg = std::string(e.what());
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ catch (const std::string &e)
|
|
|
+ {
|
|
|
+ error_msg = e;
|
|
|
+ }
|
|
|
+ catch (...)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ long long insert(typename B_BASE::meta &insert_data)
|
|
|
+ {
|
|
|
+ effect_num = 0;
|
|
|
+ sqlstring = B_BASE::_makerecordinsertsql(insert_data);
|
|
|
+ if (iscommit)
|
|
|
+ {
|
|
|
+ iscommit = false;
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iserror)
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (conn_empty())
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ auto conn = conn_obj->get_edit_conn();
|
|
|
+
|
|
|
+ unsigned int querysql_len = sqlstring.length() + 1;
|
|
|
+
|
|
|
+ conn->send_data.clear();
|
|
|
+ conn->send_data.push_back((querysql_len & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 8 & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 16 & 0xFF));
|
|
|
+ conn->send_data.push_back(0x00);
|
|
|
+ conn->send_data.push_back(0x03);
|
|
|
+ conn->send_data.append(sqlstring);
|
|
|
+
|
|
|
+ std::size_t n = asio::write(*conn->socket, asio::buffer(conn->send_data), conn->ec);
|
|
|
+
|
|
|
+ if(conn->ec)
|
|
|
+ {
|
|
|
+ error_msg = conn->ec.message();
|
|
|
+ iserror = true;
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ unsigned int offset = 0;
|
|
|
+ n = conn->read_loop();
|
|
|
+
|
|
|
+ pack_info_t temp_pack_data;
|
|
|
+ temp_pack_data.seq_id = 1;
|
|
|
+ conn->read_field_pack(conn->_cache_data, n, offset, temp_pack_data);
|
|
|
+
|
|
|
+ conn_obj->back_edit_conn(conn);
|
|
|
+
|
|
|
+ if ((unsigned char)temp_pack_data.data[0] == 0xFF)
|
|
|
+ {
|
|
|
+ error_msg = temp_pack_data.data.substr(3);
|
|
|
+ }
|
|
|
+ else if ((unsigned char)temp_pack_data.data[0] == 0x00)
|
|
|
+ {
|
|
|
+
|
|
|
+ unsigned int d_offset = 1;
|
|
|
+ effect_num = conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], d_offset);
|
|
|
+ long long insert_last_id= conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], d_offset);
|
|
|
+
|
|
|
+ return insert_last_id;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ catch (const std::exception &e)
|
|
|
+ {
|
|
|
+ error_msg = std::string(e.what());
|
|
|
+ }
|
|
|
+ catch (const std::string &e)
|
|
|
+ {
|
|
|
+ error_msg = e;
|
|
|
+ }
|
|
|
+ catch (...)
|
|
|
+ {
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ asio::awaitable<long long> async_insert(typename B_BASE::meta &insert_data)
|
|
|
+ {
|
|
|
+ effect_num = 0;
|
|
|
+ sqlstring = B_BASE::_makerecordinsertsql(insert_data);
|
|
|
+ if (iscommit)
|
|
|
+ {
|
|
|
+ iscommit = false;
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iserror)
|
|
|
+ {
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (conn_empty())
|
|
|
+ {
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ auto conn = co_await conn_obj->async_get_edit_conn();
|
|
|
+
|
|
|
+ unsigned int querysql_len = sqlstring.length() + 1;
|
|
|
+
|
|
|
+ conn->send_data.clear();
|
|
|
+ conn->send_data.push_back((querysql_len & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 8 & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 16 & 0xFF));
|
|
|
+ conn->send_data.push_back(0x00);
|
|
|
+ conn->send_data.push_back(0x03);
|
|
|
+ conn->send_data.append(sqlstring);
|
|
|
+
|
|
|
+ std::size_t n = co_await asio::async_write(*conn->socket, asio::buffer(conn->send_data), asio::use_awaitable);
|
|
|
+
|
|
|
+ unsigned int offset = 0;
|
|
|
+ n = co_await conn->async_read_loop();
|
|
|
+
|
|
|
+ pack_info_t temp_pack_data;
|
|
|
+ temp_pack_data.seq_id = 1;
|
|
|
+ conn->read_field_pack(conn->_cache_data, n, offset, temp_pack_data);
|
|
|
+
|
|
|
+ conn_obj->back_edit_conn(conn);
|
|
|
+
|
|
|
+ if ((unsigned char)temp_pack_data.data[0] == 0xFF)
|
|
|
+ {
|
|
|
+ error_msg = temp_pack_data.data.substr(3);
|
|
|
+ }
|
|
|
+ else if ((unsigned char)temp_pack_data.data[0] == 0x00)
|
|
|
+ {
|
|
|
+
|
|
|
+ unsigned int d_offset = 1;
|
|
|
+ effect_num = conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], d_offset);
|
|
|
+ long long insert_last_id= conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], d_offset);
|
|
|
+
|
|
|
+ co_return insert_last_id;
|
|
|
+ }
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ catch (const std::exception &e)
|
|
|
+ {
|
|
|
+ error_msg = std::string(e.what());
|
|
|
+ }
|
|
|
+ catch (const std::string &e)
|
|
|
+ {
|
|
|
+ error_msg = e;
|
|
|
+ }
|
|
|
+ catch (...)
|
|
|
+ {
|
|
|
+ }
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ long long insert(std::vector<typename B_BASE::meta> &insert_data)
|
|
|
+ {
|
|
|
+ effect_num = 0;
|
|
|
+ sqlstring = B_BASE::_makerecordinsertsql(insert_data);
|
|
|
+ if (iscommit)
|
|
|
+ {
|
|
|
+ iscommit = false;
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iserror)
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (conn_empty())
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ auto conn = conn_obj->get_edit_conn();
|
|
|
+
|
|
|
+ unsigned int querysql_len = sqlstring.length() + 1;
|
|
|
+
|
|
|
+ conn->send_data.clear();
|
|
|
+ conn->send_data.push_back((querysql_len & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 8 & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 16 & 0xFF));
|
|
|
+ conn->send_data.push_back(0x00);
|
|
|
+ conn->send_data.push_back(0x03);
|
|
|
+ conn->send_data.append(sqlstring);
|
|
|
+
|
|
|
+ std::size_t n = asio::write(*conn->socket, asio::buffer(conn->send_data), conn->ec);
|
|
|
+
|
|
|
+ if(conn->ec)
|
|
|
+ {
|
|
|
+ error_msg = conn->ec.message();
|
|
|
+ iserror = true;
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ unsigned int offset = 0;
|
|
|
+ n = conn->read_loop();
|
|
|
+
|
|
|
+ pack_info_t temp_pack_data;
|
|
|
+ temp_pack_data.seq_id = 1;
|
|
|
+ conn->read_field_pack(conn->_cache_data, n, offset, temp_pack_data);
|
|
|
+
|
|
|
+ conn_obj->back_edit_conn(conn);
|
|
|
+
|
|
|
+ if ((unsigned char)temp_pack_data.data[0] == 0xFF)
|
|
|
+ {
|
|
|
+ error_msg = temp_pack_data.data.substr(3);
|
|
|
+ }
|
|
|
+ else if ((unsigned char)temp_pack_data.data[0] == 0x00)
|
|
|
+ {
|
|
|
+
|
|
|
+ unsigned int d_offset = 1;
|
|
|
+ effect_num = conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], d_offset);
|
|
|
+ long long insert_last_id= conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], d_offset);
|
|
|
+
|
|
|
+ return insert_last_id;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ catch (const std::exception &e)
|
|
|
+ {
|
|
|
+ error_msg = std::string(e.what());
|
|
|
+ }
|
|
|
+ catch (const std::string &e)
|
|
|
+ {
|
|
|
+ error_msg = e;
|
|
|
+ }
|
|
|
+ catch (...)
|
|
|
+ {
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ asio::awaitable<long long> async_insert(std::vector<typename B_BASE::meta> &insert_data)
|
|
|
+ {
|
|
|
+ effect_num = 0;
|
|
|
+ sqlstring = B_BASE::_makerecordinsertsql(insert_data);
|
|
|
+ if (iscommit)
|
|
|
+ {
|
|
|
+ iscommit = false;
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iserror)
|
|
|
+ {
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (conn_empty())
|
|
|
+ {
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ auto conn = co_await conn_obj->async_get_edit_conn();
|
|
|
+
|
|
|
+ unsigned int querysql_len = sqlstring.length() + 1;
|
|
|
+
|
|
|
+ conn->send_data.clear();
|
|
|
+ conn->send_data.push_back((querysql_len & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 8 & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 16 & 0xFF));
|
|
|
+ conn->send_data.push_back(0x00);
|
|
|
+ conn->send_data.push_back(0x03);
|
|
|
+ conn->send_data.append(sqlstring);
|
|
|
+
|
|
|
+ std::size_t n = co_await asio::async_write(*conn->socket, asio::buffer(conn->send_data), asio::use_awaitable);
|
|
|
+
|
|
|
+ unsigned int offset = 0;
|
|
|
+ n = co_await conn->async_read_loop();
|
|
|
+
|
|
|
+ pack_info_t temp_pack_data;
|
|
|
+ temp_pack_data.seq_id = 1;
|
|
|
+ conn->read_field_pack(conn->_cache_data, n, offset, temp_pack_data);
|
|
|
+
|
|
|
+ conn_obj->back_edit_conn(conn);
|
|
|
+
|
|
|
+ if ((unsigned char)temp_pack_data.data[0] == 0xFF)
|
|
|
+ {
|
|
|
+ error_msg = temp_pack_data.data.substr(3);
|
|
|
+ }
|
|
|
+ else if ((unsigned char)temp_pack_data.data[0] == 0x00)
|
|
|
+ {
|
|
|
+
|
|
|
+ unsigned int d_offset = 1;
|
|
|
+ effect_num = conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], d_offset);
|
|
|
+ long long insert_last_id= conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], d_offset);
|
|
|
+
|
|
|
+ co_return insert_last_id;
|
|
|
+ }
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ catch (const std::exception &e)
|
|
|
+ {
|
|
|
+ error_msg = std::string(e.what());
|
|
|
+ }
|
|
|
+ catch (const std::string &e)
|
|
|
+ {
|
|
|
+ error_msg = e;
|
|
|
+ }
|
|
|
+ catch (...)
|
|
|
+ {
|
|
|
+ }
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ long long insert()
|
|
|
+ {
|
|
|
+ effect_num = 0;
|
|
|
+ sqlstring = B_BASE::_makeinsertsql();
|
|
|
+ if (iscommit)
|
|
|
+ {
|
|
|
+ iscommit = false;
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iserror)
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (conn_empty())
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ auto conn = conn_obj->get_edit_conn();
|
|
|
+
|
|
|
+ unsigned int querysql_len = sqlstring.length() + 1;
|
|
|
+
|
|
|
+ conn->send_data.clear();
|
|
|
+ conn->send_data.push_back((querysql_len & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 8 & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 16 & 0xFF));
|
|
|
+ conn->send_data.push_back(0x00);
|
|
|
+ conn->send_data.push_back(0x03);
|
|
|
+ conn->send_data.append(sqlstring);
|
|
|
+
|
|
|
+ std::size_t n = asio::write(*conn->socket, asio::buffer(conn->send_data), conn->ec);
|
|
|
+
|
|
|
+ if(conn->ec)
|
|
|
+ {
|
|
|
+ error_msg = conn->ec.message();
|
|
|
+ iserror = true;
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ unsigned int offset = 0;
|
|
|
+ n = conn->read_loop();
|
|
|
+
|
|
|
+ pack_info_t temp_pack_data;
|
|
|
+ temp_pack_data.seq_id = 1;
|
|
|
+ conn->read_field_pack(conn->_cache_data, n, offset, temp_pack_data);
|
|
|
+
|
|
|
+ conn_obj->back_edit_conn(conn);
|
|
|
+
|
|
|
+ if ((unsigned char)temp_pack_data.data[0] == 0xFF)
|
|
|
+ {
|
|
|
+ error_msg = temp_pack_data.data.substr(3);
|
|
|
+ }
|
|
|
+ else if ((unsigned char)temp_pack_data.data[0] == 0x00)
|
|
|
+ {
|
|
|
+ unsigned int d_offset = 1;
|
|
|
+ effect_num = conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], d_offset);
|
|
|
+ long long insert_last_id= conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], d_offset);
|
|
|
+
|
|
|
+ return insert_last_id;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ catch (const std::exception &e)
|
|
|
+ {
|
|
|
+ error_msg = std::string(e.what());
|
|
|
+ }
|
|
|
+ catch (const std::string &e)
|
|
|
+ {
|
|
|
+ error_msg = e;
|
|
|
+ }
|
|
|
+ catch (...)
|
|
|
+ {
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ asio::awaitable<long long> async_insert()
|
|
|
+ {
|
|
|
+ effect_num = 0;
|
|
|
+ sqlstring = B_BASE::_makeinsertsql();
|
|
|
+ if (iscommit)
|
|
|
+ {
|
|
|
+ iscommit = false;
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iserror)
|
|
|
+ {
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (conn_empty())
|
|
|
+ {
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ auto conn = co_await conn_obj->async_get_edit_conn();
|
|
|
+
|
|
|
+ unsigned int querysql_len = sqlstring.length() + 1;
|
|
|
+
|
|
|
+ conn->send_data.clear();
|
|
|
+ conn->send_data.push_back((querysql_len & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 8 & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 16 & 0xFF));
|
|
|
+ conn->send_data.push_back(0x00);
|
|
|
+ conn->send_data.push_back(0x03);
|
|
|
+ conn->send_data.append(sqlstring);
|
|
|
+
|
|
|
+ std::size_t n = co_await asio::async_write(*conn->socket, asio::buffer(conn->send_data), asio::use_awaitable);
|
|
|
+
|
|
|
+ unsigned int offset = 0;
|
|
|
+ n = co_await conn->async_read_loop();
|
|
|
+
|
|
|
+ pack_info_t temp_pack_data;
|
|
|
+ temp_pack_data.seq_id = 1;
|
|
|
+ conn->read_field_pack(conn->_cache_data, n, offset, temp_pack_data);
|
|
|
+
|
|
|
+ conn_obj->back_edit_conn(conn);
|
|
|
+
|
|
|
+ if ((unsigned char)temp_pack_data.data[0] == 0xFF)
|
|
|
+ {
|
|
|
+ error_msg = temp_pack_data.data.substr(3);
|
|
|
+ }
|
|
|
+ else if ((unsigned char)temp_pack_data.data[0] == 0x00)
|
|
|
+ {
|
|
|
+
|
|
|
+ unsigned int d_offset = 1;
|
|
|
+ effect_num = conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], d_offset);
|
|
|
+ long long insert_last_id= conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], d_offset);
|
|
|
+
|
|
|
+ co_return insert_last_id;
|
|
|
+ }
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ catch (const std::exception &e)
|
|
|
+ {
|
|
|
+ error_msg = std::string(e.what());
|
|
|
+ }
|
|
|
+ catch (const std::string &e)
|
|
|
+ {
|
|
|
+ error_msg = e;
|
|
|
+ }
|
|
|
+ catch (...)
|
|
|
+ {
|
|
|
+ }
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ long long save(bool isrealnew = false)
|
|
|
+ {
|
|
|
+ effect_num = 0;
|
|
|
+ if (B_BASE::getPK() > 0 && isrealnew == false)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ std::ostringstream tempsql;
|
|
|
+ tempsql << " ";
|
|
|
+ tempsql << B_BASE::getPKname();
|
|
|
+ tempsql << " = '";
|
|
|
+ tempsql << B_BASE::getPK();
|
|
|
+ tempsql << "' ";
|
|
|
+ wheresql = tempsql.str();
|
|
|
+ }
|
|
|
+ sqlstring = B_BASE::_makeupdatesql("");
|
|
|
+ sqlstring.append(" where ");
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sqlstring.append(wheresql);
|
|
|
+ }
|
|
|
+ if (!groupsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(groupsql);
|
|
|
+ }
|
|
|
+ if (!ordersql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(ordersql);
|
|
|
+ }
|
|
|
+ if (!limitsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(limitsql);
|
|
|
+ }
|
|
|
+ if (iscommit)
|
|
|
+ {
|
|
|
+ iscommit = false;
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iserror)
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ if (conn_empty())
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ auto conn = conn_obj->get_edit_conn();
|
|
|
+
|
|
|
+ unsigned int querysql_len = sqlstring.length() + 1;
|
|
|
+
|
|
|
+ conn->send_data.clear();
|
|
|
+ conn->send_data.push_back((querysql_len & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 8 & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 16 & 0xFF));
|
|
|
+ conn->send_data.push_back(0x00);
|
|
|
+ conn->send_data.push_back(0x03);
|
|
|
+ conn->send_data.append(sqlstring);
|
|
|
+
|
|
|
+ std::size_t n = asio::write(*conn->socket, asio::buffer(conn->send_data), conn->ec);
|
|
|
+
|
|
|
+ if(conn->ec)
|
|
|
+ {
|
|
|
+ error_msg = conn->ec.message();
|
|
|
+ iserror = true;
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ unsigned int offset = 0;
|
|
|
+ n = conn->read_loop();
|
|
|
+
|
|
|
+ pack_info_t temp_pack_data;
|
|
|
+ temp_pack_data.seq_id = 1;
|
|
|
+ conn->read_field_pack(conn->_cache_data, n, offset, temp_pack_data);
|
|
|
+
|
|
|
+ conn_obj->back_edit_conn(conn);
|
|
|
+
|
|
|
+ if ((unsigned char)temp_pack_data.data[0] == 0xFF)
|
|
|
+ {
|
|
|
+ error_msg = temp_pack_data.data.substr(3);
|
|
|
+ }
|
|
|
+ else if ((unsigned char)temp_pack_data.data[0] == 0x00)
|
|
|
+ {
|
|
|
+
|
|
|
+ unsigned int d_offset = 1;
|
|
|
+ effect_num = conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], d_offset);
|
|
|
+ return effect_num;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sqlstring = B_BASE::_makeinsertsql();
|
|
|
+ if (conn_empty())
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ auto conn = conn_obj->get_edit_conn();
|
|
|
+
|
|
|
+ unsigned int querysql_len = sqlstring.length() + 1;
|
|
|
+
|
|
|
+ conn->send_data.clear();
|
|
|
+ conn->send_data.push_back((querysql_len & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 8 & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 16 & 0xFF));
|
|
|
+ conn->send_data.push_back(0x00);
|
|
|
+ conn->send_data.push_back(0x03);
|
|
|
+ conn->send_data.append(sqlstring);
|
|
|
+
|
|
|
+ std::size_t n = asio::write(*conn->socket, asio::buffer(conn->send_data), conn->ec);
|
|
|
+
|
|
|
+ if(conn->ec)
|
|
|
+ {
|
|
|
+ error_msg = conn->ec.message();
|
|
|
+ iserror = true;
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ unsigned int offset = 0;
|
|
|
+ n = conn->read_loop();
|
|
|
+
|
|
|
+ pack_info_t temp_pack_data;
|
|
|
+ temp_pack_data.seq_id = 1;
|
|
|
+ conn->read_field_pack(conn->_cache_data, n, offset, temp_pack_data);
|
|
|
+
|
|
|
+ conn_obj->back_edit_conn(conn);
|
|
|
+
|
|
|
+ if ((unsigned char)temp_pack_data.data[0] == 0xFF)
|
|
|
+ {
|
|
|
+ error_msg = temp_pack_data.data.substr(3);
|
|
|
+ }
|
|
|
+ else if ((unsigned char)temp_pack_data.data[0] == 0x00)
|
|
|
+ {
|
|
|
+
|
|
|
+ unsigned int d_offset = 1;
|
|
|
+ effect_num = conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], d_offset);
|
|
|
+ long long insert_last_id= conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], d_offset);
|
|
|
+
|
|
|
+ return insert_last_id;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ asio::awaitable<long long> async_save(bool isrealnew = false)
|
|
|
+ {
|
|
|
+ effect_num = 0;
|
|
|
+ if (B_BASE::getPK() > 0 && isrealnew == false)
|
|
|
+ {
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ std::ostringstream tempsql;
|
|
|
+ tempsql << " ";
|
|
|
+ tempsql << B_BASE::getPKname();
|
|
|
+ tempsql << " = '";
|
|
|
+ tempsql << B_BASE::getPK();
|
|
|
+ tempsql << "' ";
|
|
|
+ wheresql = tempsql.str();
|
|
|
+ }
|
|
|
+ sqlstring = B_BASE::_makeupdatesql("");
|
|
|
+ sqlstring.append(" where ");
|
|
|
+ if (wheresql.empty())
|
|
|
+ {
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sqlstring.append(wheresql);
|
|
|
+ }
|
|
|
+ if (!groupsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(groupsql);
|
|
|
+ }
|
|
|
+ if (!ordersql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(ordersql);
|
|
|
+ }
|
|
|
+ if (!limitsql.empty())
|
|
|
+ {
|
|
|
+ sqlstring.append(limitsql);
|
|
|
+ }
|
|
|
+ if (iscommit)
|
|
|
+ {
|
|
|
+ iscommit = false;
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iserror)
|
|
|
+ {
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (conn_empty())
|
|
|
+ {
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ auto conn = co_await conn_obj->async_get_edit_conn();
|
|
|
+
|
|
|
+ unsigned int querysql_len = sqlstring.length() + 1;
|
|
|
+
|
|
|
+ conn->send_data.clear();
|
|
|
+ conn->send_data.push_back((querysql_len & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 8 & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 16 & 0xFF));
|
|
|
+ conn->send_data.push_back(0x00);
|
|
|
+ conn->send_data.push_back(0x03);
|
|
|
+ conn->send_data.append(sqlstring);
|
|
|
+
|
|
|
+ std::size_t n = co_await asio::async_write(*conn->socket, asio::buffer(conn->send_data), asio::use_awaitable);
|
|
|
+
|
|
|
+ unsigned int offset = 0;
|
|
|
+ n = co_await conn->async_read_loop();
|
|
|
+
|
|
|
+ pack_info_t temp_pack_data;
|
|
|
+ temp_pack_data.seq_id = 1;
|
|
|
+ conn->read_field_pack(conn->_cache_data, n, offset, temp_pack_data);
|
|
|
+
|
|
|
+ conn_obj->back_edit_conn(conn);
|
|
|
+
|
|
|
+ if ((unsigned char)temp_pack_data.data[0] == 0xFF)
|
|
|
+ {
|
|
|
+ error_msg = temp_pack_data.data.substr(3);
|
|
|
+ iserror = true;
|
|
|
+ }
|
|
|
+ else if ((unsigned char)temp_pack_data.data[0] == 0x00)
|
|
|
+ {
|
|
|
+
|
|
|
+ unsigned int d_offset = 1;
|
|
|
+ effect_num = conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], d_offset);
|
|
|
+
|
|
|
+ co_return effect_num;
|
|
|
+ }
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ catch (const std::exception &e)
|
|
|
+ {
|
|
|
+ error_msg = std::string(e.what());
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ catch (const std::string &e)
|
|
|
+ {
|
|
|
+ error_msg = e;
|
|
|
+ }
|
|
|
+ catch (...)
|
|
|
+ {
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sqlstring = B_BASE::_makeinsertsql();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (conn_empty())
|
|
|
+ {
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ auto conn = co_await conn_obj->async_get_edit_conn();
|
|
|
+
|
|
|
+ unsigned int querysql_len = sqlstring.length() + 1;
|
|
|
+
|
|
|
+ conn->send_data.clear();
|
|
|
+ conn->send_data.push_back((querysql_len & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 8 & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 16 & 0xFF));
|
|
|
+ conn->send_data.push_back(0x00);
|
|
|
+ conn->send_data.push_back(0x03);
|
|
|
+ conn->send_data.append(sqlstring);
|
|
|
+
|
|
|
+ std::size_t n = co_await asio::async_write(*conn->socket, asio::buffer(conn->send_data), asio::use_awaitable);
|
|
|
+
|
|
|
+ unsigned int offset = 0;
|
|
|
+ n = co_await conn->async_read_loop();
|
|
|
+
|
|
|
+ pack_info_t temp_pack_data;
|
|
|
+ temp_pack_data.seq_id = 1;
|
|
|
+ conn->read_field_pack(conn->_cache_data, n, offset, temp_pack_data);
|
|
|
+
|
|
|
+ conn_obj->back_edit_conn(conn);
|
|
|
+
|
|
|
+ if ((unsigned char)temp_pack_data.data[0] == 0xFF)
|
|
|
+ {
|
|
|
+ error_msg = temp_pack_data.data.substr(3);
|
|
|
+ }
|
|
|
+ else if ((unsigned char)temp_pack_data.data[0] == 0x00)
|
|
|
+ {
|
|
|
+
|
|
|
+ unsigned int d_offset = 1;
|
|
|
+ effect_num = conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], d_offset);
|
|
|
+ long long insert_last_id= conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], d_offset);
|
|
|
+
|
|
|
+ co_return insert_last_id;
|
|
|
+ }
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ catch (const std::exception &e)
|
|
|
+ {
|
|
|
+ error_msg = std::string(e.what());
|
|
|
+ }
|
|
|
+ catch (const std::string &e)
|
|
|
+ {
|
|
|
+ error_msg = e;
|
|
|
+ }
|
|
|
+ catch (...)
|
|
|
+ {
|
|
|
+ }
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+ co_return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ std::tuple<std::vector<std::string>, std::map<std::string, unsigned int>, std::vector<std::vector<std::string>>>
|
|
|
+ query(const std::string &rawsql)
|
|
|
+ {
|
|
|
+
|
|
|
+ std::vector<std::vector<std::string>> temprecord;
|
|
|
+ std::vector<std::string> table_fieldname;
|
|
|
+ std::map<std::string, unsigned int> table_fieldmap;
|
|
|
+
|
|
|
+ if(rawsql.size()>10)
|
|
|
+ {
|
|
|
+ unsigned int i=0;
|
|
|
+ for(;i<rawsql.size();i++)
|
|
|
+ {
|
|
|
+ if(rawsql[i]!=0x20)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(i<5)
|
|
|
+ {
|
|
|
+ //must be select
|
|
|
+ if(rawsql[i]!='s' && rawsql[i]!='S')
|
|
|
+ {
|
|
|
+ iserror = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ iserror = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ iserror = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iserror)
|
|
|
+ {
|
|
|
+ return std::make_tuple(table_fieldname, table_fieldmap, temprecord);
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (conn_empty())
|
|
|
+ {
|
|
|
+ return std::make_tuple(table_fieldname, table_fieldmap, temprecord);
|
|
|
+ }
|
|
|
+ auto conn = conn_obj->get_select_conn();
|
|
|
+
|
|
|
+ unsigned int querysql_len = rawsql.length() + 1;
|
|
|
+
|
|
|
+ conn->send_data.clear();
|
|
|
+
|
|
|
+ conn->send_data.push_back((querysql_len & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 8 & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 16 & 0xFF));
|
|
|
+ conn->send_data.push_back(0x00);
|
|
|
+ conn->send_data.push_back(0x03);
|
|
|
+ conn->send_data.append(rawsql);
|
|
|
+
|
|
|
+ std::size_t n = asio::write(*conn->socket, asio::buffer(conn->send_data), conn->ec);
|
|
|
+
|
|
|
+ if(conn->ec)
|
|
|
+ {
|
|
|
+ error_msg = conn->ec.message();
|
|
|
+ iserror = true;
|
|
|
+ return std::make_tuple(table_fieldname, table_fieldmap, temprecord);
|
|
|
+ }
|
|
|
+
|
|
|
+ pack_info_t temp_pack_data;
|
|
|
+ temp_pack_data.seq_id = 1;
|
|
|
+ bool is_sql_item = false;
|
|
|
+ std::vector<field_info_t> field_array;
|
|
|
+
|
|
|
+ unsigned char action_setup = 0;
|
|
|
+ unsigned int column_num = 0;
|
|
|
+
|
|
|
+ unsigned int offset = 0;
|
|
|
+
|
|
|
+ std::vector<unsigned char> field_pos;
|
|
|
+
|
|
|
+ for (; is_sql_item == false;)
|
|
|
+ {
|
|
|
+ n = conn->read_loop();
|
|
|
+ offset = 0;
|
|
|
+ for (; offset < n;)
|
|
|
+ {
|
|
|
+ conn->read_field_pack(conn->_cache_data, n, offset, temp_pack_data);
|
|
|
+ if (temp_pack_data.length == temp_pack_data.current_length)
|
|
|
+ {
|
|
|
+ if (conn->pack_eof_check(temp_pack_data))
|
|
|
+ {
|
|
|
+ is_sql_item = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (action_setup == 0)
|
|
|
+ {
|
|
|
+ if (temp_pack_data.length == 2 && (unsigned char)temp_pack_data.data[0] < 251 && (unsigned char)temp_pack_data.data[0] > 0)
|
|
|
+ {
|
|
|
+ action_setup = 1;
|
|
|
+ column_num = (unsigned char)temp_pack_data.data[0];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (action_setup == 1)
|
|
|
+ {
|
|
|
+ field_info_t temp_filed_col;
|
|
|
+ conn->read_col_info(temp_pack_data.data, temp_filed_col);
|
|
|
+
|
|
|
+ field_array.emplace_back(std::move(temp_filed_col));
|
|
|
+ column_num--;
|
|
|
+ if (column_num == 0)
|
|
|
+ {
|
|
|
+ action_setup = 2;
|
|
|
+ for (unsigned int ii = 0; ii < field_array.size(); ii++)
|
|
|
+ {
|
|
|
+ field_pos.push_back(B_BASE::findcolpos(field_array[ii].org_name));
|
|
|
+ table_fieldmap.insert({field_array[ii].org_name,table_fieldname.size()});
|
|
|
+ table_fieldname.push_back(field_array[ii].org_name);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (action_setup == 2)
|
|
|
+ {
|
|
|
+ unsigned int column_num = field_array.size();
|
|
|
+ unsigned int tempnum = 0;
|
|
|
+
|
|
|
+ std::vector<std::string> temp_v_record;
|
|
|
+ for (unsigned int ij = 0; ij < column_num; ij++)
|
|
|
+ {
|
|
|
+ unsigned long long name_length = 0;
|
|
|
+ name_length = conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], tempnum);
|
|
|
+ std::string tempstr;
|
|
|
+ tempstr.resize(name_length);
|
|
|
+ std::memcpy(tempstr.data(), (unsigned char *)&temp_pack_data.data[tempnum], name_length);
|
|
|
+ temp_v_record.push_back(std::move(tempstr));
|
|
|
+ tempnum = tempnum + name_length;
|
|
|
+ }
|
|
|
+ temprecord.push_back(temp_v_record);
|
|
|
+ effect_num++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (offset >= n)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ is_sql_item = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ conn_obj->back_select_conn(conn);
|
|
|
+
|
|
|
+ return std::make_tuple(std::move(table_fieldname), std::move(table_fieldmap), std::move(temprecord));
|
|
|
+ }
|
|
|
+ catch (const std::exception &e)
|
|
|
+ {
|
|
|
+ error_msg = std::string(e.what());
|
|
|
+ }
|
|
|
+ catch (const std::string &e)
|
|
|
+ {
|
|
|
+ error_msg = e;
|
|
|
+ }
|
|
|
+ catch (...)
|
|
|
+ {
|
|
|
+ }
|
|
|
+ return std::make_tuple(table_fieldname, table_fieldmap, temprecord);
|
|
|
+ }
|
|
|
+
|
|
|
+ asio::awaitable<std::tuple<std::vector<std::string>, std::map<std::string, unsigned int>, std::vector<std::vector<std::string>>>>
|
|
|
+ async_query(const std::string &rawsql)
|
|
|
+ {
|
|
|
+
|
|
|
+ std::vector<std::vector<std::string>> temprecord;
|
|
|
+ std::vector<std::string> table_fieldname;
|
|
|
+ std::map<std::string, unsigned int> table_fieldmap;
|
|
|
+
|
|
|
+ if(rawsql.size()>10)
|
|
|
+ {
|
|
|
+ unsigned int i=0;
|
|
|
+ for(;i<rawsql.size();i++)
|
|
|
+ {
|
|
|
+ if(rawsql[i]!=0x20)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(i<5)
|
|
|
+ {
|
|
|
+ //must be select
|
|
|
+ if(rawsql[i]!='s' && rawsql[i]!='S')
|
|
|
+ {
|
|
|
+ iserror = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ iserror = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ iserror = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iserror)
|
|
|
+ {
|
|
|
+ co_return std::make_tuple(table_fieldname, table_fieldmap, temprecord);
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (conn_empty())
|
|
|
+ {
|
|
|
+ co_return std::make_tuple(table_fieldname, table_fieldmap, temprecord);
|
|
|
+ }
|
|
|
+ auto conn = co_await conn_obj->async_get_select_conn();
|
|
|
+
|
|
|
+ unsigned int querysql_len = rawsql.length() + 1;
|
|
|
+
|
|
|
+ conn->send_data.clear();
|
|
|
+
|
|
|
+ conn->send_data.push_back((querysql_len & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 8 & 0xFF));
|
|
|
+ conn->send_data.push_back((querysql_len >> 16 & 0xFF));
|
|
|
+ conn->send_data.push_back(0x00);
|
|
|
+ conn->send_data.push_back(0x03);
|
|
|
+ conn->send_data.append(rawsql);
|
|
|
+
|
|
|
+ std::size_t n = co_await asio::async_write(*conn->socket, asio::buffer(conn->send_data), asio::use_awaitable);
|
|
|
+
|
|
|
+
|
|
|
+ pack_info_t temp_pack_data;
|
|
|
+ temp_pack_data.seq_id = 1;
|
|
|
+ bool is_sql_item = false;
|
|
|
+ std::vector<field_info_t> field_array;
|
|
|
+
|
|
|
+ unsigned char action_setup = 0;
|
|
|
+ unsigned int column_num = 0;
|
|
|
+
|
|
|
+ unsigned int offset = 0;
|
|
|
+
|
|
|
+ std::vector<unsigned char> field_pos;
|
|
|
+
|
|
|
+ for (; is_sql_item == false;)
|
|
|
+ {
|
|
|
+ n = co_await conn->async_read_loop();
|
|
|
+ offset = 0;
|
|
|
+ for (; offset < n;)
|
|
|
+ {
|
|
|
+ conn->read_field_pack(conn->_cache_data, n, offset, temp_pack_data);
|
|
|
+ if (temp_pack_data.length == temp_pack_data.current_length)
|
|
|
+ {
|
|
|
+ if (conn->pack_eof_check(temp_pack_data))
|
|
|
+ {
|
|
|
+ is_sql_item = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (action_setup == 0)
|
|
|
+ {
|
|
|
+ if (temp_pack_data.length == 2 && (unsigned char)temp_pack_data.data[0] < 251 && (unsigned char)temp_pack_data.data[0] > 0)
|
|
|
+ {
|
|
|
+ action_setup = 1;
|
|
|
+ column_num = (unsigned char)temp_pack_data.data[0];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (action_setup == 1)
|
|
|
+ {
|
|
|
+ field_info_t temp_filed_col;
|
|
|
+ conn->read_col_info(temp_pack_data.data, temp_filed_col);
|
|
|
+
|
|
|
+ field_array.emplace_back(std::move(temp_filed_col));
|
|
|
+ column_num--;
|
|
|
+ if (column_num == 0)
|
|
|
+ {
|
|
|
+ action_setup = 2;
|
|
|
+ for (unsigned int ii = 0; ii < field_array.size(); ii++)
|
|
|
+ {
|
|
|
+ field_pos.push_back(B_BASE::findcolpos(field_array[ii].org_name));
|
|
|
+ table_fieldmap.insert({field_array[ii].org_name,table_fieldname.size()});
|
|
|
+ table_fieldname.push_back(field_array[ii].org_name);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (action_setup == 2)
|
|
|
+ {
|
|
|
+ unsigned int column_num = field_array.size();
|
|
|
+ unsigned int tempnum = 0;
|
|
|
+
|
|
|
+ std::vector<std::string> temp_v_record;
|
|
|
+ for (unsigned int ij = 0; ij < column_num; ij++)
|
|
|
+ {
|
|
|
+ unsigned long long name_length = 0;
|
|
|
+ name_length = conn->pack_real_num((unsigned char *)&temp_pack_data.data[0], tempnum);
|
|
|
+ std::string tempstr;
|
|
|
+ tempstr.resize(name_length);
|
|
|
+ std::memcpy(tempstr.data(), (unsigned char *)&temp_pack_data.data[tempnum], name_length);
|
|
|
+ temp_v_record.push_back(std::move(tempstr));
|
|
|
+ tempnum = tempnum + name_length;
|
|
|
+ }
|
|
|
+ temprecord.push_back(temp_v_record);
|
|
|
+ effect_num++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (offset >= n)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ is_sql_item = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ conn_obj->back_select_conn(conn);
|
|
|
+
|
|
|
+ co_return std::make_tuple(std::move(table_fieldname), std::move(table_fieldmap), std::move(temprecord));
|
|
|
+ }
|
|
|
+ catch (const std::exception &e)
|
|
|
+ {
|
|
|
+ error_msg = std::string(e.what());
|
|
|
+ }
|
|
|
+ catch (const std::string &e)
|
|
|
+ {
|
|
|
+ error_msg = e;
|
|
|
+ }
|
|
|
+ catch (...)
|
|
|
+ {
|
|
|
+ }
|
|
|
+ co_return std::make_tuple(table_fieldname, table_fieldmap, temprecord);
|
|
|
+ }
|
|
|
+
|
|
|
+ // long long edit_query(const std::string &rawsql, bool isinsert = false)
|
|
|
+ // {
|
|
|
+ // if (iserror)
|
|
|
+ // {
|
|
|
+ // return 0;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // return 0;
|
|
|
+ // }
|
|
|
+ M_MODEL &clear(bool both = true)
|
|
|
+ {
|
|
|
+ selectsql.clear();
|
|
|
+ wheresql.clear();
|
|
|
+ ordersql.clear();
|
|
|
+ groupsql.clear();
|
|
|
+ limitsql.clear();
|
|
|
+ sqlstring.clear();
|
|
|
+ error_msg.clear();
|
|
|
+ iskuohao = false;
|
|
|
+ ishascontent = false;
|
|
|
+ iscommit = false;
|
|
|
+ iscache = false;
|
|
|
+ effect_num = 0;
|
|
|
+ if (both)
|
|
|
+ {
|
|
|
+ B_BASE::record_reset();
|
|
|
+ B_BASE::data_reset();
|
|
|
+ }
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+ M_MODEL &clearWhere()
|
|
|
+ {
|
|
|
+ selectsql.clear();
|
|
|
+ wheresql.clear();
|
|
|
+ ordersql.clear();
|
|
|
+ groupsql.clear();
|
|
|
+ limitsql.clear();
|
|
|
+ sqlstring.clear();
|
|
|
+ error_msg.clear();
|
|
|
+ iskuohao = false;
|
|
|
+ ishascontent = false;
|
|
|
+ iscommit = false;
|
|
|
+ iscache = false;
|
|
|
+ effect_num = 0;
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+ M_MODEL &set_data(typename B_BASE::meta indata)
|
|
|
+ {
|
|
|
+ B_BASE::data = indata;
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+ M_MODEL &get() { return *mod; }
|
|
|
+ std::string get_query() { return sqlstring; }
|
|
|
+ M_MODEL &start_commit()
|
|
|
+ {
|
|
|
+ iscommit = true;
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+ M_MODEL &end_commit()
|
|
|
+ {
|
|
|
+ iscommit = false;
|
|
|
+ return *mod;
|
|
|
+ }
|
|
|
+
|
|
|
+ unsigned int effect()
|
|
|
+ {
|
|
|
+ return effect_num;
|
|
|
+ }
|
|
|
+ bool conn_empty()
|
|
|
+ {
|
|
|
+ if (conn_obj)
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ error_msg = "conn_obj is null";
|
|
|
+ iserror = true;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ public:
|
|
|
+ std::string selectsql;
|
|
|
+ std::string wheresql;
|
|
|
+ std::string ordersql;
|
|
|
+ std::string groupsql;
|
|
|
+ std::string limitsql;
|
|
|
+ std::string sqlstring;
|
|
|
+ std::string dbtag;
|
|
|
+ std::string error_msg;
|
|
|
+ std::string original_tablename;
|
|
|
+
|
|
|
+ // std::list<std::string> commit_sqllist;
|
|
|
+ bool iskuohao = false;
|
|
|
+ bool iscommit = false;
|
|
|
+ bool ishascontent = false;
|
|
|
+ bool iscache = false;
|
|
|
+ bool iserror = false;
|
|
|
+ int exptime = 0;
|
|
|
+ unsigned int effect_num = 0;
|
|
|
+
|
|
|
+ M_MODEL *mod;
|
|
|
+
|
|
|
+ std::shared_ptr<orm_conn_pool> conn_obj;
|
|
|
+ };
|
|
|
+//} /*tagnamespace_replace*/
|
|
|
+}// namespace orm
|
|
|
+#endif
|