diff --git a/frameworks/C++/paozhu/paozhu.dockerfile b/frameworks/C++/paozhu/paozhu.dockerfile index 7381d0e9ac9..212773c8bea 100644 --- a/frameworks/C++/paozhu/paozhu.dockerfile +++ b/frameworks/C++/paozhu/paozhu.dockerfile @@ -4,8 +4,8 @@ RUN apt-get install -yqq gcc g++ openssl libssl-dev zlib1g-dev build-essential l RUN apt-get -y install brotli libbrotli-dev RUN apt-get -y install libreadline-dev -RUN apt-get -y install mysql-client -RUN apt-get -y install libmysqlclient-dev +# RUN apt-get -y install mysql-client +# RUN apt-get -y install libmysqlclient-dev RUN locale-gen en_US.UTF-8 ENV LANG en_US.UTF-8 @@ -18,13 +18,13 @@ WORKDIR / # RUN wget https://github.com/hggq/paozhu/releases/download/v1.5.8/benchmark.zip RUN git clone https://github.com/hggq/paozhu # RUN unzip benchmark.zip -# RUN rm -Rf ./paozhu/controller -# RUN rm -Rf ./paozhu/libs +RUN rm -Rf ./paozhu/controller +RUN rm -Rf ./paozhu/libs # RUN rm -Rf ./paozhu/view -# RUN rm -Rf ./paozhu/viewsrc -# RUN rm -Rf ./paozhu/orm -# RUN rm -Rf ./paozhu/models -# RUN rm -Rf ./paozhu/common +RUN rm -Rf ./paozhu/viewsrc +RUN rm -Rf ./paozhu/orm +RUN rm -Rf ./paozhu/models +RUN rm -Rf ./paozhu/common @@ -39,29 +39,29 @@ RUN git clone https://github.com/hggq/paozhu # RUN ls -l ./paozhu # RUN pwd -# RUN mkdir ./paozhu/common -# RUN mkdir ./paozhu/libs -# RUN mkdir ./paozhu/libs/types -# COPY ./paozhu_benchmark/libs/types/techempower_json.h ./paozhu/libs/types/ -# COPY ./paozhu_benchmark/libs/types/techempower_json_jsonreflect.cpp ./paozhu/libs/types/ +RUN mkdir ./paozhu/common +RUN mkdir ./paozhu/libs +RUN mkdir ./paozhu/libs/types +COPY ./paozhu_benchmark/libs/types/techempower_json.h ./paozhu/libs/types/ +COPY ./paozhu_benchmark/libs/types/techempower_json_jsonreflect.cpp ./paozhu/libs/types/ -# RUN mkdir ./paozhu/controller -# RUN mkdir ./paozhu/controller/include -# RUN mkdir ./paozhu/controller/src +RUN mkdir ./paozhu/controller +RUN mkdir ./paozhu/controller/include +RUN mkdir ./paozhu/controller/src -# COPY ./paozhu_benchmark/controller/include/techempower.h ./paozhu/controller/include/ -# COPY ./paozhu_benchmark/controller/src/techempower.cpp ./paozhu/controller/src/ +COPY ./paozhu_benchmark/controller/include/techempower.h ./paozhu/controller/include/ +COPY ./paozhu_benchmark/controller/src/techempower.cpp ./paozhu/controller/src/ -# COPY ./paozhu_benchmark/common/autocontrolmethod.hpp ./paozhu/common/ -# COPY ./paozhu_benchmark/common/reghttpmethod_pre.hpp ./paozhu/common/ -# COPY ./paozhu_benchmark/common/reghttpmethod.hpp ./paozhu/common/ -# COPY ./paozhu_benchmark/common/json_reflect_headers.h ./paozhu/common/ +COPY ./paozhu_benchmark/common/autocontrolmethod.hpp ./paozhu/common/ +COPY ./paozhu_benchmark/common/reghttpmethod_pre.hpp ./paozhu/common/ +COPY ./paozhu_benchmark/common/reghttpmethod.hpp ./paozhu/common/ +COPY ./paozhu_benchmark/common/json_reflect_headers.h ./paozhu/common/ -# COPY ./paozhu_benchmark/common/cost_define.h ./paozhu/common/ -# COPY ./paozhu_benchmark/common/autorestfulpaths.hpp ./paozhu/common/ -# COPY ./paozhu_benchmark/common/websockets_method_reg.hpp ./paozhu/common/ -# COPY ./paozhu_benchmark/common/httphook.cpp ./paozhu/common/ +COPY ./paozhu_benchmark/common/cost_define.h ./paozhu/common/ +COPY ./paozhu_benchmark/common/autorestfulpaths.hpp ./paozhu/common/ +COPY ./paozhu_benchmark/common/websockets_method_reg.hpp ./paozhu/common/ +COPY ./paozhu_benchmark/common/httphook.cpp ./paozhu/common/ COPY ./paozhu_benchmark/conf/server.conf ./paozhu/conf/server.conf COPY ./paozhu_benchmark/conf/orm.conf ./paozhu/conf/orm.conf @@ -74,32 +74,34 @@ COPY ./paozhu_benchmark/CMakeLists.txt ./paozhu/CMakeLists.txt # COPY ./paozhu_benchmark/view/techempower/fortunes.html ./paozhu/view/techempower/ -# RUN mkdir ./paozhu/viewsrc -# RUN mkdir ./paozhu/viewsrc/include -# RUN mkdir ./paozhu/viewsrc/view -# RUN mkdir ./paozhu/viewsrc/view/techempower +RUN mkdir ./paozhu/viewsrc +RUN mkdir ./paozhu/viewsrc/include +RUN mkdir ./paozhu/viewsrc/view +RUN mkdir ./paozhu/viewsrc/view/techempower -# COPY ./paozhu_benchmark/viewsrc/view/techempower/fortunes.cpp ./paozhu/viewsrc/view/techempower/ -# COPY ./paozhu_benchmark/viewsrc/include/viewsrc.h ./paozhu/viewsrc/include/ -# COPY ./paozhu_benchmark/viewsrc/include/regviewmethod.hpp ./paozhu/viewsrc/include/ +COPY ./paozhu_benchmark/viewsrc/view/techempower/fortunes.cpp ./paozhu/viewsrc/view/techempower/ +COPY ./paozhu_benchmark/viewsrc/include/viewsrc.h ./paozhu/viewsrc/include/ +COPY ./paozhu_benchmark/viewsrc/include/regviewmethod.hpp ./paozhu/viewsrc/include/ -# RUN mkdir ./paozhu/orm -# RUN mkdir ./paozhu/orm/include +RUN mkdir ./paozhu/orm +RUN mkdir ./paozhu/orm/include -# COPY ./paozhu_benchmark/orm/orm.h ./paozhu/orm/ -# COPY ./paozhu_benchmark/orm/include/fortunebase.h ./paozhu/orm/include/ -# COPY ./paozhu_benchmark/orm/include/worldbase.h ./paozhu/orm/include/ +COPY ./paozhu_benchmark/orm/orm.h ./paozhu/orm/ +COPY ./paozhu_benchmark/orm/include/fortunebase.h ./paozhu/orm/include/ +COPY ./paozhu_benchmark/orm/include/worldbase.h ./paozhu/orm/include/ +COPY ./paozhu_benchmark/orm/include/fortune_mysql.h ./paozhu/orm/include/ +COPY ./paozhu_benchmark/orm/include/world_mysql.h ./paozhu/orm/include/ -# RUN mkdir ./paozhu/models -# RUN mkdir ./paozhu/models/include +RUN mkdir ./paozhu/models +RUN mkdir ./paozhu/models/include -# COPY ./paozhu_benchmark/models/include/Fortune.h ./paozhu/models/include/ -# COPY ./paozhu_benchmark/models/include/World.h ./paozhu/models/include/ -# COPY ./paozhu_benchmark/models/World.cpp ./paozhu/models/ -# COPY ./paozhu_benchmark/models/Fortune.cpp ./paozhu/models/ +COPY ./paozhu_benchmark/models/include/Fortune.h ./paozhu/models/include/ +COPY ./paozhu_benchmark/models/include/World.h ./paozhu/models/include/ +COPY ./paozhu_benchmark/models/World.cpp ./paozhu/models/ +COPY ./paozhu_benchmark/models/Fortune.cpp ./paozhu/models/ WORKDIR /paozhu RUN unzip asio.zip diff --git a/frameworks/C++/paozhu/paozhu_benchmark/CMakeLists.txt b/frameworks/C++/paozhu/paozhu_benchmark/CMakeLists.txt index 611a71394bb..a25af789299 100755 --- a/frameworks/C++/paozhu/paozhu_benchmark/CMakeLists.txt +++ b/frameworks/C++/paozhu/paozhu_benchmark/CMakeLists.txt @@ -73,7 +73,7 @@ if(${mode} AND (CMAKE_BUILD_TYPE STREQUAL "Debug")) endif () else() set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wextra") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pthread -g -fsanitize=address -DASIO_STANDALONE -DBENCHMARK -DDEBUG ${BOOST_OPEN} ${GD_OPEN} -I/usr/local/include -I/usr/local/mysql/include -I/usr/include -I/usr/include/mysql " ) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pthread -g -fsanitize=address -DASIO_STANDALONE -DBENCHMARK -DDEBUG ${BOOST_OPEN} ${GD_OPEN} -I/usr/local/include -I/usr/include " ) endif () message("Debug mode:${CMAKE_CXX_FLAGS_DEBUG}") @@ -86,7 +86,7 @@ elseif(${mode} AND (CMAKE_BUILD_TYPE STREQUAL "Release")) endif () else () set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wall -Wextra -O3") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -DASIO_STANDALONE ${BOOST_OPEN} ${GD_OPEN} -DBENCHMARK -I/usr/local/include -I/usr/local/mysql/include -I/usr/include -I/usr/include/mysql " ) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -DASIO_STANDALONE ${BOOST_OPEN} ${GD_OPEN} -DBENCHMARK -I/usr/local/include -I/usr/include " ) file(MAKE_DIRECTORY /usr/local/etc/paozhu) file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/conf/ DESTINATION /usr/local/etc/paozhu/) endif () @@ -95,7 +95,7 @@ elseif(${mode} AND (CMAKE_BUILD_TYPE STREQUAL "Release")) else() set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wextra") message("Debug mode:${CMAKE_CXX_FLAGS_DEBUG}") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pthread -g -fsanitize=address -DASIO_STANDALONE -DBENCHMARK -DDEBUG ${BOOST_OPEN} ${GD_OPEN} -I/usr/local/include -I/usr/local/mysql/include -I/usr/include -I/usr/include/mysql " ) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pthread -g -fsanitize=address -DASIO_STANDALONE -DBENCHMARK -DDEBUG ${BOOST_OPEN} ${GD_OPEN} -I/usr/local/include -I/usr/include " ) if(NOT CMAKE_SYSTEM_NAME MATCHES "Windows") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address") @@ -122,6 +122,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/vendor/httpcli) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/viewsrc/include) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/websockets/include) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/orm) if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/bin/paozhu_pre) file(REMOVE_RECURSE ${CMAKE_CURRENT_SOURCE_DIR}/bin/paozhu_pre) @@ -191,7 +192,7 @@ include_sub_directories_recursively(${CMAKE_CURRENT_SOURCE_DIR}/libs) include_sub_directories_recursively(${CMAKE_CURRENT_SOURCE_DIR}/include) include_sub_directories_recursively(${CMAKE_CURRENT_SOURCE_DIR}/common) -add_executable(paozhu_cli ${CMAKE_CURRENT_SOURCE_DIR}/vendor/httpcli/http_cli.cpp) +add_executable(paozhu_cli ${CMAKE_CURRENT_SOURCE_DIR}/vendor/httpcli/http_cli.cpp ${CMAKE_CURRENT_SOURCE_DIR}/vendor/httpserver/src/mysql_conn.cpp ${CMAKE_CURRENT_SOURCE_DIR}/vendor/httpserver/src/mysql_conn_pool.cpp ${CMAKE_CURRENT_SOURCE_DIR}/vendor/httpserver/src/clientdatacache.cpp) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin) @@ -230,14 +231,17 @@ if (ENABLE_VCPKG) target_link_libraries(paozhu ZLIB::ZLIB) # find_package(libmysql REQUIRED) - find_package(unofficial-libmariadb CONFIG REQUIRED) - find_path(MYSQL_ROOT_DIR mysql) + # find_package(unofficial-libmariadb CONFIG REQUIRED) + # find_path(MYSQL_ROOT_DIR mysql) # target_link_libraries(paozhu ${MYSQL_LIBRARIES}) # target_link_libraries(paozhu_cli ${MYSQL_LIBRARIES}) - target_link_libraries(paozhu unofficial::libmariadb) - target_link_libraries(paozhu_cli unofficial::libmariadb) - target_include_directories(paozhu PUBLIC ${MYSQL_ROOT_DIR}/mysql) - target_include_directories(paozhu_cli PUBLIC ${MYSQL_ROOT_DIR}/mysql) + # target_link_libraries(paozhu unofficial::libmariadb) + # target_link_libraries(paozhu_cli unofficial::libmariadb) + # target_include_directories(paozhu PUBLIC ${MYSQL_ROOT_DIR}/mysql) + # target_include_directories(paozhu_cli PUBLIC ${MYSQL_ROOT_DIR}/mysql) + + target_link_libraries(paozhu_cli asio::asio) + target_link_libraries(paozhu_cli OpenSSL::Crypto OpenSSL::SSL) if (ENABLE_GD STREQUAL "ON") find_package(PkgConfig) @@ -331,6 +335,9 @@ if(OPENSSL_FOUND) INCLUDE_DIRECTORIES("${OPENSSL_INCLUDE_DIR}") target_link_libraries (paozhu ${OPENSSL_SSL_LIBRARY}) target_link_libraries (paozhu ${OPENSSL_CRYPTO_LIBRARY}) + + target_link_libraries (paozhu_cli ${OPENSSL_SSL_LIBRARY}) + target_link_libraries (paozhu_cli ${OPENSSL_CRYPTO_LIBRARY}) endif() @@ -343,80 +350,80 @@ if(ZLIB_FOUND) endif() -if(CMAKE_SYSTEM_NAME MATCHES "Darwin") - if (IS_DIRECTORY "/usr/local/mysql/include") - MESSAGE( STATUS "/usr/local/mysql") - set(MYSQL_INCLUDE_DIR "/usr/local/mysql/include") - include_sub_directories_recursively(/usr/local/mysql/include) - endif() - - if (IS_DIRECTORY "/usr/local/opt/mysql-client") - MESSAGE( STATUS "/usr/local/opt/mysql-client") - set(MYSQL_INCLUDE_DIR "/usr/local/opt/mysql-client/include") - include_sub_directories_recursively(/usr/local/opt/mysql-client/include) - endif() - - if (IS_DIRECTORY "/opt/homebrew/opt/mysql") - MESSAGE( STATUS "/opt/homebrew/opt/mysql") - set(MYSQL_INCLUDE_DIR "/opt/homebrew/opt/mysql/include") - include_sub_directories_recursively(/opt/homebrew/opt/mysql/include) - endif() - - - if (IS_DIRECTORY "/opt/homebrew/opt/mysql-client") - MESSAGE( STATUS "/opt/homebrew/opt/mysql-client") - set(MYSQL_INCLUDE_DIR "/opt/homebrew/opt/mysql-client/include") - include_sub_directories_recursively(/opt/homebrew/opt/mysql-client/include) - endif() - MESSAGE( STATUS "MYSQL_ROOT_DIR = ${MYSQL_ROOT_DIR} ") -else() - find_path(MYSQL_ROOT_DIR mysql) -endif() - - -FIND_PATH(MYSQL_INCLUDE_DIR NAMES mysql.h - PATHS /usr/local/include/mysql /usr/include/mysql /opt/homebrew/opt/mysql/include /usr/local/opt/mysql-client/include /opt/homebrew/opt/mysql-client/include -) - -MESSAGE( STATUS "MYSQL_ROOT_DIR = ${MYSQL_ROOT_DIR} ") -find_package_handle_standard_args(mysql REQUIRED_VARS MYSQL_ROOT_DIR) - - -if(NOT MYSQL_INCLUDE_DIR) - message(STATUS "Could not find \"mysql.h\" from searching ") -endif() - -SET(MYSQL_NAMES mysqlclient) -FIND_LIBRARY(MYSQL_LIBRARY - NAMES ${MYSQL_NAMES} - PATHS /usr/lib /usr/local/lib /usr/local/mysql/lib /usr/local/opt/mysql/lib /opt/homebrew/opt/mysql/lib /opt/homebrew/opt/mysql-client/lib - PATH_SUFFIXES mysql -) - -IF (MYSQL_INCLUDE_DIR AND MYSQL_LIBRARY) - SET(MYSQL_FOUND TRUE) - SET( MYSQL_LIBRARIES ${MYSQL_LIBRARY} ) -ELSE (MYSQL_INCLUDE_DIR AND MYSQL_LIBRARY) - SET(MYSQL_FOUND FALSE) - SET( MYSQL_LIBRARIES ) -ENDIF (MYSQL_INCLUDE_DIR AND MYSQL_LIBRARY) - -IF (MYSQL_FOUND) - IF (NOT MYSQL_FIND_QUIETLY) - MESSAGE(STATUS "Found MySQL: ${MYSQL_LIBRARY}") - ENDIF (NOT MYSQL_FIND_QUIETLY) -ELSE (MYSQL_FOUND) - IF (MYSQL_FIND_REQUIRED) - MESSAGE(STATUS "Looked for MySQL libraries named ${MYSQL_NAMES}.") - MESSAGE(FATAL_ERROR "Could NOT find MySQL library") - ENDIF (MYSQL_FIND_REQUIRED) -ENDIF (MYSQL_FOUND) - -target_include_directories(paozhu PUBLIC ${MYSQL_INCLUDE_DIR}) -target_link_libraries(paozhu ${MYSQL_LIBRARY}) - -target_include_directories(paozhu_cli PUBLIC ${MYSQL_INCLUDE_DIR}) -target_link_libraries(paozhu_cli ${MYSQL_LIBRARY}) +#if(CMAKE_SYSTEM_NAME MATCHES "Darwin") +# if (IS_DIRECTORY "/usr/local/mysql/include") +# MESSAGE( STATUS "/usr/local/mysql") +# set(MYSQL_INCLUDE_DIR "/usr/local/mysql/include") +# include_sub_directories_recursively(/usr/local/mysql/include) +# endif() +# +# if (IS_DIRECTORY "/usr/local/opt/mysql-client") +# MESSAGE( STATUS "/usr/local/opt/mysql-client") +# set(MYSQL_INCLUDE_DIR "/usr/local/opt/mysql-client/include") +# include_sub_directories_recursively(/usr/local/opt/mysql-client/include) +# endif() +# +# if (IS_DIRECTORY "/opt/homebrew/opt/mysql") +# MESSAGE( STATUS "/opt/homebrew/opt/mysql") +# set(MYSQL_INCLUDE_DIR "/opt/homebrew/opt/mysql/include") +# include_sub_directories_recursively(/opt/homebrew/opt/mysql/include) +# endif() +# +# +# if (IS_DIRECTORY "/opt/homebrew/opt/mysql-client") +# MESSAGE( STATUS "/opt/homebrew/opt/mysql-client") +# set(MYSQL_INCLUDE_DIR "/opt/homebrew/opt/mysql-client/include") +# include_sub_directories_recursively(/opt/homebrew/opt/mysql-client/include) +# endif() +# MESSAGE( STATUS "MYSQL_ROOT_DIR = ${MYSQL_ROOT_DIR} ") +#else() +# find_path(MYSQL_ROOT_DIR mysql) +#endif() +# +# +# FIND_PATH(MYSQL_INCLUDE_DIR NAMES mysql.h +# PATHS /usr/local/include/mysql /usr/include/mysql /opt/homebrew/opt/mysql/include /usr/local/opt/mysql-client/include /opt/homebrew/opt/mysql-client/include +# ) +# +# MESSAGE( STATUS "MYSQL_ROOT_DIR = ${MYSQL_ROOT_DIR} ") +# find_package_handle_standard_args(mysql REQUIRED_VARS MYSQL_ROOT_DIR) +# +# +# if(NOT MYSQL_INCLUDE_DIR) +# message(STATUS "Could not find \"mysql.h\" from searching ") +# endif() +# +# SET(MYSQL_NAMES mysqlclient) +# FIND_LIBRARY(MYSQL_LIBRARY +# NAMES ${MYSQL_NAMES} +# PATHS /usr/lib /usr/local/lib /usr/local/mysql/lib /usr/local/opt/mysql/lib /opt/homebrew/opt/mysql/lib /opt/homebrew/opt/mysql-client/lib +# PATH_SUFFIXES mysql +# ) +# +# IF (MYSQL_INCLUDE_DIR AND MYSQL_LIBRARY) +# SET(MYSQL_FOUND TRUE) +# SET( MYSQL_LIBRARIES ${MYSQL_LIBRARY} ) +# ELSE (MYSQL_INCLUDE_DIR AND MYSQL_LIBRARY) +# SET(MYSQL_FOUND FALSE) +# SET( MYSQL_LIBRARIES ) +# ENDIF (MYSQL_INCLUDE_DIR AND MYSQL_LIBRARY) +# +# IF (MYSQL_FOUND) +# IF (NOT MYSQL_FIND_QUIETLY) +# MESSAGE(STATUS "Found MySQL: ${MYSQL_LIBRARY}") +# ENDIF (NOT MYSQL_FIND_QUIETLY) +# ELSE (MYSQL_FOUND) +# IF (MYSQL_FIND_REQUIRED) +# MESSAGE(STATUS "Looked for MySQL libraries named ${MYSQL_NAMES}.") +# MESSAGE(FATAL_ERROR "Could NOT find MySQL library") +# ENDIF (MYSQL_FIND_REQUIRED) +# ENDIF (MYSQL_FOUND) +# +# target_include_directories(paozhu PUBLIC ${MYSQL_INCLUDE_DIR}) +# target_link_libraries(paozhu ${MYSQL_LIBRARY}) +# +# target_include_directories(paozhu_cli PUBLIC ${MYSQL_INCLUDE_DIR}) +# target_link_libraries(paozhu_cli ${MYSQL_LIBRARY}) diff --git a/frameworks/C++/paozhu/paozhu_benchmark/common/autocontrolmethod.hpp b/frameworks/C++/paozhu/paozhu_benchmark/common/autocontrolmethod.hpp index 46d8979692a..b793d7f8d5e 100755 --- a/frameworks/C++/paozhu/paozhu_benchmark/common/autocontrolmethod.hpp +++ b/frameworks/C++/paozhu/paozhu_benchmark/common/autocontrolmethod.hpp @@ -9,14 +9,21 @@ #include "httppeer.h" #include "techempower.h" + +namespace http +{ + + void _initauto_control_httpmethodregto(std::map &methodcallback) + { + struct regmethold_t temp; -namespace http -{ - void _initauto_control_httpmethodregto(std::map &methodcallback) - { - struct regmethold_t temp; + } + + void _initauto_co_control_httpmethodregto(std::map &methodcallback) + { + struct regmethold_co_t temp; temp.pre = nullptr; temp.regfun = techempowerplaintext; methodcallback.emplace("plaintext",temp); @@ -54,8 +61,16 @@ namespace http } -} + void _initauto_co_domain_httpmethodregto(std::map> &domain_methodcallback) + { + struct regmethold_co_t temp; + std::map methodcallback; + std::map>::iterator domain_iterator; + + } + +} #endif \ No newline at end of file diff --git a/frameworks/C++/paozhu/paozhu_benchmark/common/cost_define.h b/frameworks/C++/paozhu/paozhu_benchmark/common/cost_define.h index 47fb182f0e0..ef54468d7be 100755 --- a/frameworks/C++/paozhu/paozhu_benchmark/common/cost_define.h +++ b/frameworks/C++/paozhu/paozhu_benchmark/common/cost_define.h @@ -6,4 +6,7 @@ #define CONST_HTTP_HEADER_BODY_SIZE 16384 #define CONST_PHP_BODY_POST_SIZE 16777216 +#define CONST_HTTP_BODY_POST_SIZE 33554432 +#define CONST_HTTP_JSON_POST_SIZE 2097152 + #endif \ No newline at end of file diff --git a/frameworks/C++/paozhu/paozhu_benchmark/common/httphook.cpp b/frameworks/C++/paozhu/paozhu_benchmark/common/httphook.cpp index 3440c23f84b..327ecab4b71 100755 --- a/frameworks/C++/paozhu/paozhu_benchmark/common/httphook.cpp +++ b/frameworks/C++/paozhu/paozhu_benchmark/common/httphook.cpp @@ -8,13 +8,24 @@ #include #include #include "httppeer.h" +#include "client_session.h" namespace http { std::map _block_ip_tables; std::map _block_host_tables; -bool check_blockip(const std::string &client_ip) +std::map _passport_ip_tables; +std::map _passport_host_tables; +bool check_blockip(std::shared_ptr peer_session) { - if (client_ip.size() > 0) + if (peer_session->isssl) + { + return false; + } + return false; +} +bool check_pressl_blockip(std::shared_ptr peer_session) +{ + if (peer_session->isssl) { return false; } diff --git a/frameworks/C++/paozhu/paozhu_benchmark/conf/orm.conf b/frameworks/C++/paozhu/paozhu_benchmark/conf/orm.conf index 1700d25a66e..b8eae8460ab 100644 --- a/frameworks/C++/paozhu/paozhu_benchmark/conf/orm.conf +++ b/frameworks/C++/paozhu/paozhu_benchmark/conf/orm.conf @@ -6,7 +6,8 @@ dbname=hello_world user=benchmarkdbuser password=benchmarkdbpass pretable= -maxpool=5 +maxpool=120 +minpool=30 dbtype=mysql type=second @@ -16,5 +17,6 @@ dbname=hello_world user=benchmarkdbuser password=benchmarkdbpass pretable= -maxpool=20 +maxpool=120 +minpool=30 dbtype=mysql diff --git a/frameworks/C++/paozhu/paozhu_benchmark/conf/server.conf b/frameworks/C++/paozhu/paozhu_benchmark/conf/server.conf index 9013265e678..265e2193570 100755 --- a/frameworks/C++/paozhu/paozhu_benchmark/conf/server.conf +++ b/frameworks/C++/paozhu/paozhu_benchmark/conf/server.conf @@ -18,19 +18,19 @@ clean_cron =m5t600 ;5-minute interval clean 600 seconds ago inactive connection links_restart_process =n9998877ts1te5 ;More than 15000 connections, restart the process from 1:00 am to 5:00 am session_type=1 ;session save type 0.file 1.memory 2.redis 3.memcache 4.reserve static_file_compress_cache=1 ;1 enable, Cache static file compress(gzip,br) content to cache directory -modelspath=/root/benchmark/models -serverpath=/root/benchmark -viewpath=/root/benchmark/view -viewsopath=/root/benchmark/module/view +modelspath=/paozhu/models +serverpath=/paozhu +viewpath=/paozhu/view +viewsopath=/paozhu/module/view -controlpath=/root/benchmark/controller -controlsopath=/root/benchmark/module/controller +controlpath=/paozhu/controller +controlsopath=/paozhu/module/controller -temppath=/root/benchmark/temp -logpath=/root/benchmark/log -wwwpath=/root/benchmark/www/default -pluginspath=/root/benchmark/plugins -libspath=/root/benchmark/libs +temppath=/paozhu/temp +logpath=/paozhu/log +wwwpath=/paozhu/www/default +pluginspath=/paozhu/plugins +libspath=/paozhu/libs directorylist=0 index=index.html ;usehtmlcache=1 diff --git a/frameworks/C++/paozhu/paozhu_benchmark/controller/include/techempower.h b/frameworks/C++/paozhu/paozhu_benchmark/controller/include/techempower.h old mode 100755 new mode 100644 index f1697f616b9..ce43babe19f --- a/frameworks/C++/paozhu/paozhu_benchmark/controller/include/techempower.h +++ b/frameworks/C++/paozhu/paozhu_benchmark/controller/include/techempower.h @@ -5,15 +5,13 @@ #include "httppeer.h" namespace http -{ - - - std::string techempowerplaintext(std::shared_ptr peer); - std::string techempowerjson(std::shared_ptr peer); - std::string techempowerdb(std::shared_ptr peer); - std::string techempowerqueries(std::shared_ptr peer); - std::string techempowerfortunes(std::shared_ptr peer); - std::string techempowerupdates(std::shared_ptr peer); - std::string techempowercached_queries(std::shared_ptr peer); - std::string techempowercached_db(std::shared_ptr peer); +{ + asio::awaitable techempowerplaintext(std::shared_ptr peer); + asio::awaitable techempowerjson(std::shared_ptr peer); + asio::awaitable techempowerdb(std::shared_ptr peer); + asio::awaitable techempowerqueries(std::shared_ptr peer); + asio::awaitable techempowerfortunes(std::shared_ptr peer); + asio::awaitable techempowerupdates(std::shared_ptr peer); + asio::awaitable techempowercached_queries(std::shared_ptr peer); + asio::awaitable techempowercached_db(std::shared_ptr peer); } diff --git a/frameworks/C++/paozhu/paozhu_benchmark/controller/src/techempower.cpp b/frameworks/C++/paozhu/paozhu_benchmark/controller/src/techempower.cpp index f8dfe230acd..f3111732864 100755 --- a/frameworks/C++/paozhu/paozhu_benchmark/controller/src/techempower.cpp +++ b/frameworks/C++/paozhu/paozhu_benchmark/controller/src/techempower.cpp @@ -6,236 +6,245 @@ #include #include "httppeer.h" #include "techempower.h" +#include "techempower_json.h" #include "datetime.h" #include "func.h" #include "pzcache.h" #include "json_reflect_headers.h" -#include "techempower_json.h" namespace http { - //@urlpath(null,plaintext) - std::string techempowerplaintext(std::shared_ptr peer) +//@urlpath(null,plaintext) +asio::awaitable techempowerplaintext(std::shared_ptr peer) +{ + peer->type("text/plain; charset=UTF-8"); + peer->set_header("Date", get_gmttime()); + peer->output = "Hello, World!"; + co_return ""; +} + +//@urlpath(null,json) +asio::awaitable techempowerjson(std::shared_ptr peer) +{ + peer->type("application/json; charset=UTF-8"); + peer->set_header("Date", get_gmttime()); + struct techempower_outjson_t a; + a.message = "Hello, World!"; + peer->output = json_encode(a); + co_return ""; +} + +//@urlpath(null,db) +asio::awaitable techempowerdb(std::shared_ptr peer) +{ + peer->type("application/json; charset=UTF-8"); + peer->set_header("Date", get_gmttime()); + auto myworld = orm::World(); + unsigned int rd_num = rand_range(1, 10000); + myworld.where("id", rd_num); + myworld.limit(1); + co_await myworld.async_fetch_one(); + peer->output = myworld.data_tojson(); + co_return ""; +} + +//@urlpath(null,queries) +asio::awaitable techempowerqueries(std::shared_ptr peer) +{ + peer->type("application/json; charset=UTF-8"); + peer->set_header("Date", get_gmttime()); + + unsigned int get_num = peer->get["queries"].to_int(); + if (get_num == 0) { - peer->type("text/plain; charset=UTF-8"); - peer->set_header("Date", get_gmttime()); - peer->output = "Hello, World!"; - return ""; + get_num = 1; } - - //@urlpath(null,json) - std::string techempowerjson(std::shared_ptr peer) + else if (get_num > 500) { - peer->type("application/json; charset=UTF-8"); - peer->set_header("Date", get_gmttime()); - struct techempower_outjson_t a; - a.message = "Hello, World!"; - peer->output = json_encode(a); - return ""; + get_num = 500; } - - //@urlpath(null,db) - std::string techempowerdb(std::shared_ptr peer) + auto myworld = orm::World(); + myworld.record.reserve(get_num); + for (unsigned int i = 0; i < get_num; i++) { - peer->type("application/json; charset=UTF-8"); - peer->set_header("Date", get_gmttime()); - auto myworld = orm::World(); + myworld.wheresql.clear(); unsigned int rd_num = rand_range(1, 10000); - myworld.get_one(rd_num); - - peer->output = myworld.data_tojson(); - return ""; + myworld.where("id", rd_num); + co_await myworld.async_fetch_append(); } - //@urlpath(null,queries) - std::string techempowerqueries(std::shared_ptr peer) - { - peer->type("application/json; charset=UTF-8"); - peer->set_header("Date", get_gmttime()); + peer->output = myworld.to_json(); + co_return ""; +} - unsigned int get_num = peer->get["queries"].to_int(); - if (get_num == 0) - { - get_num = 1; - } - else if (get_num > 500) - { - get_num = 500; - } - auto myworld = orm::World(); - myworld.record.reserve(get_num); - for (unsigned int i = 0; i < get_num; i++) - { - myworld.wheresql.clear(); - unsigned int rd_num = rand_range(1, 10000); - myworld.where("id", rd_num).fetch_append(); - } - - peer->output = myworld.to_json(); - return ""; +//@urlpath(null,fortunes) +asio::awaitable techempowerfortunes(std::shared_ptr peer) +{ + peer->type("text/html; charset=UTF-8"); + peer->set_header("Date", get_gmttime()); + + auto myfortune = orm::Fortune(); + co_await myfortune.async_fetch(); + myfortune.data.id = 0; + myfortune.data.message = "Additional fortune added at request time."; + myfortune.record.push_back(myfortune.data); + + std::sort(myfortune.record.begin(), myfortune.record.end(), [](const auto &lhs, const auto &rhs) + { return lhs.message < rhs.message; }); + peer->val["list"].set_array(); + OBJ_ARRAY item; + for (unsigned int i = 0; i < myfortune.record.size(); i++) + { + item["id"] = myfortune.record[i].id; + item["message"] = html_encode(myfortune.record[i].message); + peer->val["list"].push(item); } + peer->view("techempower/fortunes"); + // peer->output = "Fortunes"; + // for (unsigned int i = 0; i < myfortune.record.size(); i++) + // { + // peer->output += ""; + // } + // peer->output += "
idmessage
" + std::to_string(myfortune.record[i].id) + "" + html_encode(myfortune.record[i].message) + "
"; + co_return ""; +} + +//@urlpath(null,updates) +asio::awaitable techempowerupdates(std::shared_ptr peer) +{ + peer->type("application/json; charset=UTF-8"); + peer->set_header("Date", get_gmttime()); + unsigned int get_num = peer->get["queries"].to_int(); - //@urlpath(null,fortunes) - std::string techempowerfortunes(std::shared_ptr peer) + if (get_num == 0) { - peer->type("text/html; charset=UTF-8"); - peer->set_header("Date", get_gmttime()); - - auto myfortune = orm::Fortune(); - myfortune.fetch(); - myfortune.data.id = 0; - myfortune.data.message = "Additional fortune added at request time."; - myfortune.record.push_back(myfortune.data); - - std::sort(myfortune.record.begin(), myfortune.record.end(), [](const auto &lhs, const auto &rhs) - { return lhs.message < rhs.message; }); - peer->val["list"].set_array(); - OBJ_ARRAY item; - for (unsigned int i = 0; i < myfortune.record.size(); i++) - { - item["id"] = myfortune.record[i].id; - item["message"] = html_encode(myfortune.record[i].message); - peer->val["list"].push(item); - } - - peer->view("techempower/fortunes"); - return ""; + get_num = 1; } - - //@urlpath(null,updates) - std::string techempowerupdates(std::shared_ptr peer) + else if (get_num > 500) { - peer->type("application/json; charset=UTF-8"); - peer->set_header("Date", get_gmttime()); - unsigned int get_num = peer->get["queries"].to_int(); - - if (get_num == 0) - { - get_num = 1; - } - else if (get_num > 500) - { - get_num = 500; - } - auto myworld = orm::World(); - myworld.record.clear(); - myworld.record.reserve(get_num); - for (unsigned int i = 0; i < get_num; i++) + get_num = 500; + } + auto myworld = orm::World(); + myworld.record.clear(); + myworld.record.reserve(get_num); + for (unsigned int i = 0; i < get_num; i++) + { + myworld.wheresql.clear(); + myworld.where("id", rand_range(1, 10000)); + co_await myworld.async_fetch_append(); + if (myworld.effect() > 0) { - myworld.wheresql.clear(); - myworld.where("id", rand_range(1, 10000)).fetch_append(); - if (myworld.effect() > 0) - { - unsigned int j = myworld.record.size() - 1; - myworld.data.randomnumber = rand_range(1, 10000); - myworld.record[j].randomnumber = myworld.data.randomnumber; - myworld.update("randomnumber"); - } + unsigned int j = myworld.record.size() - 1; + myworld.data.randomnumber = rand_range(1, 10000); + myworld.record[j].randomnumber = myworld.data.randomnumber; + co_await myworld.async_update("randomnumber"); } - peer->output = myworld.to_json(); - return ""; } + peer->output = myworld.to_json(); + co_return ""; +} - //@urlpath(null,cached-queries) - std::string techempowercached_queries(std::shared_ptr peer) - { - peer->type("application/json; charset=UTF-8"); - peer->set_header("Date", get_gmttime()); +//@urlpath(null,cached-queries) +asio::awaitable techempowercached_queries(std::shared_ptr peer) +{ + peer->type("application/json; charset=UTF-8"); + peer->set_header("Date", get_gmttime()); - unsigned int get_num = peer->get["count"].to_int(); - if (get_num == 0) - { - get_num = 1; - } - else if (get_num > 500) - { - get_num = 500; - } - auto myworld = orm::World(); - std::string mycacheid = "alldatacache"; + unsigned int get_num = peer->get["count"].to_int(); + if (get_num == 0) + { + get_num = 1; + } + else if (get_num > 500) + { + get_num = 500; + } + auto myworld = orm::World(); + std::string mycacheid = "alldatacache"; - pzcache> &temp_cache = pzcache>::conn(); + pzcache> &temp_cache = pzcache>::conn(); - std::vector allcachedata_array; - allcachedata_array.reserve(10000); - // create rand data to cache - if (temp_cache.check(mycacheid) > -1) - { - allcachedata_array = temp_cache.get(mycacheid); - } - else - { - allcachedata_array.resize(10000); - for (unsigned int i = 0; i < 10000; i++) - { - allcachedata_array[i].id = i + 1; - allcachedata_array[i].randomnumber = rand_range(1, 10000); - } - temp_cache.save(mycacheid, allcachedata_array, 120); - } - // get rand data from cache - mycacheid = "my" + std::to_string(get_num); - myworld.record.reserve(get_num); - if (temp_cache.check(mycacheid) > -1) + std::vector allcachedata_array; + allcachedata_array.reserve(10000); + //create rand data to cache + if (temp_cache.check(mycacheid) > -1) + { + allcachedata_array = temp_cache.get(mycacheid); + } + else + { + allcachedata_array.resize(10000); + for (unsigned int i = 0; i < 10000; i++) { - myworld.record = temp_cache.get(mycacheid); + allcachedata_array[i].id = i + 1; + allcachedata_array[i].randomnumber = rand_range(1, 10000); } - else + temp_cache.save(mycacheid, allcachedata_array, 360); + } + //get rand data from cache + mycacheid = "my" + std::to_string(get_num); + myworld.record.reserve(get_num); + if (temp_cache.check(mycacheid) > -1) + { + myworld.record = temp_cache.get(mycacheid); + } + else + { + if (allcachedata_array.size() == 10000) { - if (allcachedata_array.size() == 10000) + for (unsigned int i = 0; i < get_num; i++) { - for (unsigned int i = 0; i < get_num; i++) - { - unsigned int temp_rid = rand_range(0, 9999); - myworld.record.push_back(allcachedata_array[temp_rid]); - } + unsigned int temp_rid = rand_range(0, 9999); + myworld.record.push_back(allcachedata_array[temp_rid]); } - temp_cache.save(mycacheid, myworld.record, 120); } - - peer->output = myworld.to_json(); - return ""; + temp_cache.save(mycacheid, myworld.record, 360); } - //@urlpath(null,cached-db) - std::string techempowercached_db(std::shared_ptr peer) + peer->output = myworld.to_json(); + co_return ""; +} + +//@urlpath(null,cached-db) +asio::awaitable techempowercached_db(std::shared_ptr peer) +{ + peer->type("application/json; charset=UTF-8"); + peer->set_header("Date", get_gmttime()); + //this test from database to cache + unsigned int get_num = peer->get["count"].to_int(); + if (get_num == 0) { - peer->type("application/json; charset=UTF-8"); - peer->set_header("Date", get_gmttime()); - // this test from database to cache - unsigned int get_num = peer->get["count"].to_int(); - if (get_num == 0) - { - get_num = 1; - } - else if (get_num > 500) - { - get_num = 500; - } - auto myworld = orm::World(); - std::string mycacheid = "my" + std::to_string(get_num); + get_num = 1; + } + else if (get_num > 500) + { + get_num = 500; + } + auto myworld = orm::World(); + std::string mycacheid = "my" + std::to_string(get_num); - pzcache> &temp_cache = pzcache>::conn(); + pzcache> &temp_cache = pzcache>::conn(); - myworld.record.reserve(get_num); - if (temp_cache.check(mycacheid) > -1) - { - myworld.record = temp_cache.get(mycacheid); - } - else + myworld.record.reserve(get_num); + if (temp_cache.check(mycacheid) > -1) + { + myworld.record = temp_cache.get(mycacheid); + } + else + { + std::vector cacheid; + for (unsigned int i = 0; i < get_num; i++) { - std::vector cacheid; - for (unsigned int i = 0; i < get_num; i++) - { - cacheid.push_back(rand_range(1, 10000)); - } - - std::string sqlstr = array_to_sql(cacheid); - myworld.whereIn("id", sqlstr).fetch(); - temp_cache.save(mycacheid, myworld.record, 120); + cacheid.push_back(rand_range(1, 10000)); } - peer->output = myworld.to_json(); - return ""; + std::string sqlstr = array_to_sql(cacheid); + myworld.whereIn("id", sqlstr); + co_await myworld.async_fetch(); + temp_cache.save(mycacheid, myworld.record, 360); } -} // namespace http \ No newline at end of file + peer->output = myworld.to_json(); + co_return ""; +} + +}// namespace http \ No newline at end of file diff --git a/frameworks/C++/paozhu/paozhu_benchmark/models/Fortune.cpp b/frameworks/C++/paozhu/paozhu_benchmark/models/Fortune.cpp old mode 100755 new mode 100644 index 160924992af..4bb6dd1bc5c --- a/frameworks/C++/paozhu/paozhu_benchmark/models/Fortune.cpp +++ b/frameworks/C++/paozhu/paozhu_benchmark/models/Fortune.cpp @@ -1,4 +1,5 @@ -#include "mysqlmodel.hpp" + +#include "fortune_mysql.h" #include "fortunebase.h" #include "Fortune.h" @@ -7,10 +8,9 @@ namespace orm{ - - - Fortune::Fortune(std::string dbtag):mysqlclientDB(dbtag){} - Fortune::Fortune():mysqlclientDB(){} - - + + Fortune::Fortune(std::string dbtag):fortune_mysql(dbtag){ mod=this; } + Fortune::Fortune():fortune_mysql(){ mod=this; } + + } diff --git a/frameworks/C++/paozhu/paozhu_benchmark/models/World.cpp b/frameworks/C++/paozhu/paozhu_benchmark/models/World.cpp old mode 100755 new mode 100644 index aa18f46cab6..970e3427398 --- a/frameworks/C++/paozhu/paozhu_benchmark/models/World.cpp +++ b/frameworks/C++/paozhu/paozhu_benchmark/models/World.cpp @@ -1,4 +1,5 @@ -#include "mysqlmodel.hpp" + +#include "world_mysql.h" #include "worldbase.h" #include "World.h" @@ -7,10 +8,9 @@ namespace orm{ - - - World::World(std::string dbtag):mysqlclientDB(dbtag){} - World::World():mysqlclientDB(){} - - + + World::World(std::string dbtag):world_mysql(dbtag){ mod=this; } + World::World():world_mysql(){ mod=this; } + + } diff --git a/frameworks/C++/paozhu/paozhu_benchmark/models/include/Fortune.h b/frameworks/C++/paozhu/paozhu_benchmark/models/include/Fortune.h old mode 100755 new mode 100644 index 27865161b32..1f53aa1e51d --- a/frameworks/C++/paozhu/paozhu_benchmark/models/include/Fortune.h +++ b/frameworks/C++/paozhu/paozhu_benchmark/models/include/Fortune.h @@ -1,16 +1,16 @@ #ifndef ORM_DEFAULT_FORTUNE_H #define ORM_DEFAULT_FORTUNE_H -#include "mysqlmodel.hpp" +#include "fortune_mysql.h" #include "fortunebase.h" /* 如果此文件存在不会自动覆盖,没有则会自动生成。 *If this file exists, it will not be overwritten automatically. If not, it will be generated automatically. */ namespace orm { - class Fortune : public mysqlclientDB{ + class Fortune : public fortune_mysql{ public: Fortune(std::string dbtag); Fortune(); }; -}; +} #endif diff --git a/frameworks/C++/paozhu/paozhu_benchmark/models/include/World.h b/frameworks/C++/paozhu/paozhu_benchmark/models/include/World.h old mode 100755 new mode 100644 index ba44dee7888..0967117ebb0 --- a/frameworks/C++/paozhu/paozhu_benchmark/models/include/World.h +++ b/frameworks/C++/paozhu/paozhu_benchmark/models/include/World.h @@ -1,16 +1,16 @@ #ifndef ORM_DEFAULT_WORLD_H #define ORM_DEFAULT_WORLD_H -#include "mysqlmodel.hpp" +#include "world_mysql.h" #include "worldbase.h" /* 如果此文件存在不会自动覆盖,没有则会自动生成。 *If this file exists, it will not be overwritten automatically. If not, it will be generated automatically. */ namespace orm { - class World : public mysqlclientDB{ + class World : public world_mysql{ public: World(std::string dbtag); World(); }; -}; +} #endif diff --git a/frameworks/C++/paozhu/paozhu_benchmark/orm/include/fortune_mysql.h b/frameworks/C++/paozhu/paozhu_benchmark/orm/include/fortune_mysql.h new file mode 100644 index 00000000000..18cba5958fc --- /dev/null +++ b/frameworks/C++/paozhu/paozhu_benchmark/orm/include/fortune_mysql.h @@ -0,0 +1,9788 @@ +#ifndef _ORM_DEFAULT_FORTUNE_OPERATE_H +#define _ORM_DEFAULT_FORTUNE_OPERATE_H + +#include +#include +#include +#include +#include +#include +#include +#include "request.h" +#include "unicode.h" +#include "datetime.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "mysql_conn.h" +#include "mysql_conn_pool.h" +#include "orm_cache.hpp" +/*baseincludefile*/ +namespace orm +{ +// mysql Operational SQL middleware +/*tagnamespace*/ +//{ /*tagnamespace_replace*/ + template + class fortune_mysql : public B_BASE + { + public: + fortune_mysql(const std::string &tag) : dbtag(tag) + { + std::map> &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> &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> &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_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 + 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 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_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> + 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 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 + requires std::is_integral_v +M_MODEL& inId(const std::vector& 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 0) + { + wheresql.push_back(','); + } + wheresql.append(std::to_string(val[i])); + } + wheresql.push_back(')'); + + return *mod; + } + + +M_MODEL& inId(const std::vector& 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 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 + requires std::is_integral_v +M_MODEL& ninId(const std::vector& 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 0) + { + wheresql.push_back(','); + } + wheresql.append(std::to_string(val[i])); + } + wheresql.push_back(')'); + + return *mod; + } + + +M_MODEL& ninId(const std::vector& 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 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 + requires std::is_integral_v +M_MODEL& or_inId(const std::vector& 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 0) + { + wheresql.push_back(','); + } + wheresql.append(std::to_string(val[i])); + } + wheresql.push_back(')'); + + return *mod; + } + + +M_MODEL& or_inId(const std::vector& 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 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 + requires std::is_integral_v +M_MODEL& or_ninId(const std::vector& 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 0) + { + wheresql.push_back(','); + } + wheresql.append(std::to_string(val[i])); + } + wheresql.push_back(')'); + + return *mod; + } + + +M_MODEL& or_ninId(const std::vector& 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 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 + requires std::is_integral_v +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 + requires std::is_integral_v +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 + requires std::is_integral_v +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 + requires std::is_integral_v +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 + requires std::is_integral_v +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 + requires std::is_integral_v +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 + requires std::is_integral_v +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 + requires std::is_integral_v +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 + requires std::is_integral_v +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 + requires std::is_integral_v +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 + requires std::is_integral_v +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 + requires std::is_integral_v +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 &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;i0) + { + wheresql.push_back(','); + } + wheresql.push_back('\''); + wheresql.append(B_BASE::stringaddslash(val[i])); + wheresql.push_back('\''); + } + + + + return *mod; + } + + +template + requires std::is_integral_v +M_MODEL& inMessage(const std::vector &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;i0) + { + 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 &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;i0) + { + wheresql.push_back(','); + } + wheresql.push_back('\''); + wheresql.append(B_BASE::stringaddslash(val[i])); + wheresql.push_back('\''); + } + + + + return *mod; + } + + +template + requires std::is_integral_v +M_MODEL& ninMessage(const std::vector &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;i0) + { + 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 &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;i0) + { + wheresql.push_back(','); + } + wheresql.push_back('\''); + wheresql.append(B_BASE::stringaddslash(val[i])); + wheresql.push_back('\''); + } + + + + return *mod; + } + + +template + requires std::is_integral_v +M_MODEL& or_inMessage(const std::vector &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;i0) + { + 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 &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;i0) + { + wheresql.push_back(','); + } + wheresql.push_back('\''); + wheresql.append(B_BASE::stringaddslash(val[i])); + wheresql.push_back('\''); + } + + + + return *mod; + } + + +template + requires std::is_integral_v +M_MODEL& or_ninMessage(const std::vector &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;i0) + { + 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 + requires std::is_floating_point_v||std::is_integral_v +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 + requires std::is_floating_point_v||std::is_integral_v +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 + requires std::is_floating_point_v||std::is_integral_v +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 + requires std::is_floating_point_v||std::is_integral_v +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 + requires std::is_floating_point_v||std::is_integral_v +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 + requires std::is_floating_point_v||std::is_integral_v +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 + requires std::is_floating_point_v||std::is_integral_v +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 + requires std::is_floating_point_v||std::is_integral_v +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 + requires std::is_floating_point_v||std::is_integral_v +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 + requires std::is_floating_point_v||std::is_integral_v +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 + requires std::is_floating_point_v||std::is_integral_v +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 + requires std::is_floating_point_v||std::is_integral_v +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 + 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 + 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 + 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 + 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 + 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 + 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 &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 &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 + 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 + 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 + 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> 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> 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_array; + unsigned char action_setup = 0; + unsigned int column_num = 0; + unsigned int offset = 0; + + std::vector 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 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::map, std::vector>> + 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> temprecord; + std::vector table_fieldname; + std::map table_fieldmap; + + if (iscache) + { + std::size_t sqlhashid = std::hash{}(sqlstring); + + model_meta_cache> &temp_cache = + model_meta_cache>::getinstance(); + temprecord = temp_cache.get(sqlhashid); + if (temprecord.size() > 0) + { + iscache = false; + model_meta_cache &table_cache = model_meta_cache::getinstance(); + table_fieldname = table_cache.get(sqlhashid); + + model_meta_cache> &tablemap_cache = + model_meta_cache>::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_array; + // std::vector> field_value; + + unsigned char action_setup = 0; + unsigned int column_num = 0; + + unsigned int offset = 0; + + std::vector 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 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{}(sqlstring); + + model_meta_cache> &temp_cache = + model_meta_cache>::getinstance(); + temp_cache.save(sqlhashid, temprecord, exptime); + + exptime += 1; + model_meta_cache &table_cache = model_meta_cache::getinstance(); + table_cache.save(sqlhashid, table_fieldname, exptime); + + model_meta_cache> &tablemap_cache = + model_meta_cache>::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{}(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_array; + + unsigned char action_setup = 0; + unsigned int column_num = 0; + + unsigned int offset = 0; + + std::vector 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 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{}(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_array; + + unsigned char action_setup = 0; + unsigned int column_num = 0; + + unsigned int offset = 0; + + std::vector 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{}(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_array; + + unsigned char action_setup = 0; + unsigned int column_num = 0; + + unsigned int offset = 0; + + std::vector 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 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{}(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_array; + // std::vector> field_value; + + unsigned char action_setup = 0; + unsigned int column_num = 0; + + unsigned int offset = 0; + + std::vector field_pos; + // std::map 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{}(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_array; + unsigned char action_setup = 0; + unsigned int column_num = 0; + unsigned int offset = 0; + + std::vector 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 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{}(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_array; + // std::vector> field_value; + + unsigned char action_setup = 0; + unsigned int column_num = 0; + + unsigned int offset = 0; + + std::vector field_pos; + // std::map 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 &temp_cache = model_meta_cache::getinstance(); + temp_cache.remove_exptime(); + } + void clear_cache() + { + model_meta_cache &temp_cache = model_meta_cache::getinstance(); + temp_cache.clear(); + } + bool remove_cache() + { + model_meta_cache &temp_cache = model_meta_cache::getinstance(); + std::size_t sqlhashid = std::hash{}(sqlstring); + return temp_cache.remove(sqlhashid); + } + bool remove_cache(std::size_t cache_key_name) + { + model_meta_cache &temp_cache = model_meta_cache::getinstance(); + return temp_cache.remove(cache_key_name); + } + int check_cache(std::size_t cache_key_name) + { + model_meta_cache &temp_cache = model_meta_cache::getinstance(); + return temp_cache.check(cache_key_name); + } + std::vector get_cache_data(std::size_t cache_key_name) + { + model_meta_cache &temp_cache = model_meta_cache::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 &temp_cache = model_meta_cache::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 &temp_cache = model_meta_cache::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 &temp_cache = model_meta_cache::getinstance(); + std::size_t sqlhashid = std::hash{}(sqlstring); + return temp_cache.update(sqlhashid, exp_time); + } + int update_cache(std::size_t cache_key_name, int exp_time) + { + model_meta_cache &temp_cache = model_meta_cache::getinstance(); + return temp_cache.update(cache_key_name, exp_time); + } + bool save_cache(int exp_time = 0) + { + model_meta_cache &temp_cache = model_meta_cache::getinstance(); + std::size_t sqlhashid = std::hash{}(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 &temp_cache = model_meta_cache::getinstance(); + temp_cache.save(cache_key_name, cache_data, exp_time); + return true; + } + + bool save_cache(std::size_t cache_key_name, std::vector &cache_data, int exp_time = 0) + { + model_meta_cache &temp_cache = model_meta_cache::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 &temp_cache = model_meta_cache::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_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 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_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{}(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_array; + + unsigned char action_setup = 0; + unsigned int column_num = 0; + + unsigned int offset = 0; + + std::vector 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 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{}(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_array; + + unsigned char action_setup = 0; + unsigned int column_num = 0; + + unsigned int offset = 0; + + std::vector 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 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 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 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 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 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 &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 async_insert(std::vector &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 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 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::map, std::vector>> + query(const std::string &rawsql) + { + + std::vector> temprecord; + std::vector table_fieldname; + std::map table_fieldmap; + + if(rawsql.size()>10) + { + unsigned int i=0; + for(;iget_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_array; + + unsigned char action_setup = 0; + unsigned int column_num = 0; + + unsigned int offset = 0; + + std::vector 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 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::map, std::vector>>> + async_query(const std::string &rawsql) + { + + std::vector> temprecord; + std::vector table_fieldname; + std::map table_fieldmap; + + if(rawsql.size()>10) + { + unsigned int i=0; + for(;iasync_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_array; + + unsigned char action_setup = 0; + unsigned int column_num = 0; + + unsigned int offset = 0; + + std::vector 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 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 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 conn_obj; + }; +//} /*tagnamespace_replace*/ +}// namespace orm +#endif \ No newline at end of file diff --git a/frameworks/C++/paozhu/paozhu_benchmark/orm/include/fortunebase.h b/frameworks/C++/paozhu/paozhu_benchmark/orm/include/fortunebase.h old mode 100755 new mode 100644 index 8a09ecc4564..2d688b054ed --- a/frameworks/C++/paozhu/paozhu_benchmark/orm/include/fortunebase.h +++ b/frameworks/C++/paozhu/paozhu_benchmark/orm/include/fortunebase.h @@ -2,7 +2,7 @@ #define ORM_DEFAULT_FORTUNEBASEMATA_H /* *This file is auto create from cli -*本文件为自动生成 Fri, 26 Jan 2024 02:59:30 GMT +*本文件为自动生成 Sun, 02 Mar 2025 10:54:30 GMT ***/ #include #include @@ -14,28 +14,30 @@ #include #include #include -#include "mysql.h" +#include "unicode.h" + namespace orm { struct fortunebase { struct meta{ - unsigned int id= 0; // - std::string message=""; // + unsigned int id = 0; ///**/ + std::string message = ""; ///**/ } data; std::vector record; std::string _rmstag="default";//this value must be default or tag value, tag in mysqlconnect config file . -std::vector _keypos{0x00}; -MYSQL_ROW _row; +unsigned int _offset=0; std::vector::iterator begin(){ return record.begin(); } std::vector::iterator end(){ return record.end(); } std::vector::const_iterator begin() const{ return record.begin(); } std::vector::const_iterator end() const{ return record.end(); } -const std::array colnames={"id","message"}; -const std::array colnamestype= {3,253}; +static constexpr std::array col_names={"id","message"}; +static constexpr std::array col_types={3,253}; +static constexpr std::array col_length={0,0}; +static constexpr std::array col_decimals={0,0}; std::string tablename="fortune"; -std::string modelname="Fortune"; +static constexpr std::string_view modelname="Fortune"; unsigned char findcolpos(const std::string &coln){ if(coln.size()==0) @@ -82,70 +84,9 @@ break; return temp; } - void _setColnamevalue() - { - for(unsigned char i=0;i<_keypos.size();i++) - { - switch(_keypos[i]){ - case 0: - try{ - data.id=std::stoul(_row[i]); - }catch (...) { - data.id=0; - } - break; - case 1: - try{ - data.message.append((_row[i]==NULL?"":_row[i])); - }catch (...) { - data.message.clear(); - } - break; - default: - { } - - - } - - if(i>210){ - break; - } - } - } - void _addnewrowvalue(){ - fortunebase::meta metatemp; - - for(unsigned char i=0;i<_keypos.size();i++){ - - switch(_keypos[i]){ - - case 0: - try{ - metatemp.id=std::stoul(_row[i]); - }catch (...) { - metatemp.id=0; - } - break; - case 1: - try{ - metatemp.message.append((_row[i]==NULL?"":_row[i])); - }catch (...) { - metatemp.message.clear(); - } - break; - default: - { } - - - } - if(i>210){ - break; - } - } - record.emplace_back(std::move(metatemp)); - } + - inline std::string stringaddslash(std::string &content){ + inline std::string stringaddslash(const std::string &content){ std::string temp; for(unsigned int i=0;i0){ - tempsql<<"`,`"; - }else{ - tempsql<<"`"; - } - tempsql<0){ - tempsql<<"`"; - } - tempsql<<") VALUES ("; + unsigned int j=0; + std::ostringstream tempsql; + tempsql<<"INSERT INTO "; + tempsql<0){ + tempsql<<"`,`"; + }else{ + tempsql<<"`"; + } + tempsql<0){ + tempsql<<"`"; + } + tempsql<<") VALUES ("; if(data.id==0){ tempsql<<"null"; @@ -209,24 +150,24 @@ tempsql<<")"; return tempsql.str(); } - std::string _makerecordinsertsql( meta &insert_data){ - unsigned int j=0; - std::ostringstream tempsql; - tempsql<<"INSERT INTO "; - tempsql<0){ - tempsql<<"`,`"; - }else{ - tempsql<<"`"; - } - tempsql<0){ - tempsql<<"`"; - } - tempsql<<") VALUES ("; + std::string _makerecordinsertsql(const meta &insert_data){ + unsigned int j=0; + std::ostringstream tempsql; + tempsql<<"INSERT INTO "; + tempsql<0){ + tempsql<<"`,`"; + }else{ + tempsql<<"`"; + } + tempsql<0){ + tempsql<<"`"; + } + tempsql<<") VALUES ("; if(insert_data.id==0){ tempsql<<"null"; @@ -240,35 +181,35 @@ tempsql<<")"; return tempsql.str(); } - std::string _makerecordinsertsql( std::vector &insert_data){ - unsigned int j=0; - std::ostringstream tempsql; - tempsql<<"INSERT INTO "; - tempsql<0){ - tempsql<<"`,`"; - }else{ - tempsql<<"`"; - } - tempsql<0){ - tempsql<<"`"; - } - tempsql<<") VALUES "; + std::string _makerecordinsertsql(const std::vector &insert_data){ + unsigned int j=0; + std::ostringstream tempsql; + tempsql<<"INSERT INTO "; + tempsql<0){ + tempsql<<"`,`"; + }else{ + tempsql<<"`"; + } + tempsql<0){ + tempsql<<"`"; + } + tempsql<<") VALUES "; - for(unsigned int i=0;i0) - { - tempsql<<","; - } - tempsql<<"("; + for(unsigned int i=0;i0) + { + tempsql<<","; + } + tempsql<<"("; - if(insert_data[i].id==0){ + if(insert_data[i].id==0){ tempsql<<"null"; }else{ tempsql<0){ unsigned char bpos_i=findcolpos(keyname); #ifdef DEBUG - if (bpos_i == 254) + if (bpos_i == 255) { std::cout << "\033[1m\033[31m-----------\n" << keyname << " not in " << tablename << " table Field.\n-----------\033[0m" @@ -375,7 +315,7 @@ tempsql<<"`message`='"< 0) { @@ -385,7 +325,7 @@ tempsql<<"`message`='"< 0) { @@ -419,7 +359,7 @@ tempsql<<"`message`='"< 0) { @@ -429,7 +369,7 @@ tempsql<<"`message`='"< 0) { @@ -455,33 +395,12 @@ tempsql<<"`message`='"<0){ - for(;jj0) - { - tempsql<<","; - } - tempsql<0){ + std::string keyname; + unsigned char jj=0; + j=0; + if(fileld.size()>0){ + for(;jj0) @@ -491,10 +410,30 @@ tempsql<<"`message`='"<0){ + if(findcolpos(keyname)<255) + { + if(j>0) + { + tempsql<<","; + } + tempsql< keypos; if(fileld.size()>1){ for(;jj0){ - keypos.emplace_back(findcolpos(keyname)); - keyname.clear(); + keypos.emplace_back(findcolpos(keyname)); + keyname.clear(); } }else{ - for(jj=0;jj data_tomap(std::string fileld=""){ std::map tempsql; - std::string keyname; - unsigned char jj=0; - std::vector keypos; - if(fileld.size()>1){ - for(;jj keypos; + if(fileld.size()>1){ + for(;jj0){ - keypos.emplace_back(findcolpos(keyname)); - keyname.clear(); - } - }else{ - for(jj=0;jj0){ + keypos.emplace_back(findcolpos(keyname)); + keyname.clear(); + } + }else{ + for(jj=0;jj keypos; - if(fileld.size()>0){ - for(;jj keypos; + if(fileld.size()>0){ + for(;jj0){ - keypos.emplace_back(findcolpos(keyname)); - keyname.clear(); - } - }else{ - for(jj=0;jj0){ + keypos.emplace_back(findcolpos(keyname)); + keyname.clear(); + } + }else{ + for(jj=0;jj0){ tempsql<<","; } if(data.id==0){ @@ -981,43 +920,43 @@ tempsql<<"\"message\":\""< keypos; - if(fileld.size()>0){ - for(;jj keypos; + if(fileld.size()>0){ + for(;jj0){ - keypos.emplace_back(findcolpos(keyname)); - keyname.clear(); - } - }else{ - for(jj=0;jj0){ - tempsql<<",{"; - }else{ - tempsql<<"{"; - } - - for(jj=0;jj0){ + keypos.emplace_back(findcolpos(keyname)); + keyname.clear(); + } + }else{ + for(jj=0;jj0){ + tempsql<<",{"; + }else{ + tempsql<<"{"; + } + + for(jj=0;jj0){ tempsql<<","; } if(record[n].id==0){ @@ -1043,49 +982,49 @@ tempsql<<"\"message\":\""< func,std::string fileld=""){ std::ostringstream tempsql; - std::string keyname; - unsigned char jj=0; - std::vector keypos; - if(fileld.size()>0){ - for(;jj keypos; + if(fileld.size()>0){ + for(;jj0){ - keypos.emplace_back(findcolpos(keyname)); - keyname.clear(); - } - }else{ - for(jj=0;jj0){ - tempsql<<",{"; - }else{ - tempsql<<"{"; - } - tempsql<0){ + keypos.emplace_back(findcolpos(keyname)); + keyname.clear(); + } + }else{ + for(jj=0;jj0){ + tempsql<<",{"; + }else{ + tempsql<<"{"; + } + tempsql<0){ tempsql<<","; } if(record[n].id==0){ @@ -1110,12 +1049,12 @@ tempsql<<"\"message\":\""< +#include +#include +#include +#include +#include +#include +#include "request.h" +#include "unicode.h" +#include "datetime.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "mysql_conn.h" +#include "mysql_conn_pool.h" +#include "orm_cache.hpp" +/*baseincludefile*/ +namespace orm +{ +// mysql Operational SQL middleware +/*tagnamespace*/ +//{ /*tagnamespace_replace*/ + template + class world_mysql : public B_BASE + { + public: + world_mysql(const std::string &tag) : dbtag(tag) + { + std::map> &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; + } + } + world_mysql() : dbtag(B_BASE::_rmstag) + { + std::map> &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> &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_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 + 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 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_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> + 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 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.randomnumber=0; + + for(unsigned int i=0; i< value_size; i++) + { + if(result_temp_data[i]>='0'&&result_temp_data[i]<='9') + { + + data_temp.randomnumber= data_temp.randomnumber * 10 + (result_temp_data[i]-'0'); + } + if(i>32) + { + break; + } + } + 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 + requires std::is_integral_v +M_MODEL& inId(const std::vector& 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 0) + { + wheresql.push_back(','); + } + wheresql.append(std::to_string(val[i])); + } + wheresql.push_back(')'); + + return *mod; + } + + +M_MODEL& inId(const std::vector& 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 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 + requires std::is_integral_v +M_MODEL& ninId(const std::vector& 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 0) + { + wheresql.push_back(','); + } + wheresql.append(std::to_string(val[i])); + } + wheresql.push_back(')'); + + return *mod; + } + + +M_MODEL& ninId(const std::vector& 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 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 + requires std::is_integral_v +M_MODEL& or_inId(const std::vector& 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 0) + { + wheresql.push_back(','); + } + wheresql.append(std::to_string(val[i])); + } + wheresql.push_back(')'); + + return *mod; + } + + +M_MODEL& or_inId(const std::vector& 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 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 + requires std::is_integral_v +M_MODEL& or_ninId(const std::vector& 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 0) + { + wheresql.push_back(','); + } + wheresql.append(std::to_string(val[i])); + } + wheresql.push_back(')'); + + return *mod; + } + + +M_MODEL& or_ninId(const std::vector& 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 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 + requires std::is_integral_v +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 + requires std::is_integral_v +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 + requires std::is_integral_v +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 + requires std::is_integral_v +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 + requires std::is_integral_v +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 + requires std::is_integral_v +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 + requires std::is_integral_v +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 + requires std::is_integral_v +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 + requires std::is_integral_v +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 + requires std::is_integral_v +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 + requires std::is_integral_v +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 + requires std::is_integral_v +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& eqRandomnumber(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(" randomnumber = "); + + 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& nqRandomnumber(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(" randomnumber != "); + + 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& inRandomnumber(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(" randomnumber IN("); + + wheresql.append(val); + wheresql.push_back(')'); + return *mod; + } + + +template + requires std::is_integral_v +M_MODEL& inRandomnumber(const std::vector& val) + { + if (wheresql.empty()) + { + } + else + { + if (ishascontent) + { + wheresql.append(" AND "); + } + else + { + if (!iskuohao) + { + wheresql.append(" AND "); + } + } + } + if (iskuohao) + { + ishascontent = true; + } + wheresql.append(" randomnumber IN("); + + for(unsigned int i=0;i 0) + { + wheresql.push_back(','); + } + wheresql.append(std::to_string(val[i])); + } + wheresql.push_back(')'); + + return *mod; + } + + +M_MODEL& inRandomnumber(const std::vector& val) + { + if (wheresql.empty()) + { + } + else + { + if (ishascontent) + { + wheresql.append(" AND "); + } + else + { + if (!iskuohao) + { + wheresql.append(" AND "); + } + } + } + if (iskuohao) + { + ishascontent = true; + } + wheresql.append(" randomnumber IN("); + + for(unsigned int i=0;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& ninRandomnumber(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(" randomnumber NOT IN("); + + wheresql.append(val); + wheresql.push_back(')'); + return *mod; + } + + +template + requires std::is_integral_v +M_MODEL& ninRandomnumber(const std::vector& val) + { + if (wheresql.empty()) + { + } + else + { + if (ishascontent) + { + wheresql.append(" AND "); + } + else + { + if (!iskuohao) + { + wheresql.append(" AND "); + } + } + } + if (iskuohao) + { + ishascontent = true; + } + wheresql.append(" randomnumber NOT IN("); + + for(unsigned int i=0;i 0) + { + wheresql.push_back(','); + } + wheresql.append(std::to_string(val[i])); + } + wheresql.push_back(')'); + + return *mod; + } + + +M_MODEL& ninRandomnumber(const std::vector& val) + { + if (wheresql.empty()) + { + } + else + { + if (ishascontent) + { + wheresql.append(" AND "); + } + else + { + if (!iskuohao) + { + wheresql.append(" AND "); + } + } + } + if (iskuohao) + { + ishascontent = true; + } + wheresql.append(" randomnumber NOT IN("); + + for(unsigned int i=0;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& btRandomnumber(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(" randomnumber > "); + + 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& beRandomnumber(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(" randomnumber >= "); + + 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& ltRandomnumber(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(" randomnumber < "); + + 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& leRandomnumber(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(" randomnumber <= "); + + 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_eqRandomnumber(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(" randomnumber = "); + + 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_nqRandomnumber(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(" randomnumber != "); + + 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_inRandomnumber(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(" randomnumber IN("); + + wheresql.append(val); + wheresql.push_back(')'); + return *mod; + } + + +template + requires std::is_integral_v +M_MODEL& or_inRandomnumber(const std::vector& val) + { + if (wheresql.empty()) + { + } + else + { + if (ishascontent) + { + wheresql.append(" OR "); + } + else + { + if (!iskuohao) + { + wheresql.append(" OR "); + } + } + } + if (iskuohao) + { + ishascontent = true; + } + wheresql.append(" randomnumber IN("); + + for(unsigned int i=0;i 0) + { + wheresql.push_back(','); + } + wheresql.append(std::to_string(val[i])); + } + wheresql.push_back(')'); + + return *mod; + } + + +M_MODEL& or_inRandomnumber(const std::vector& val) + { + if (wheresql.empty()) + { + } + else + { + if (ishascontent) + { + wheresql.append(" OR "); + } + else + { + if (!iskuohao) + { + wheresql.append(" OR "); + } + } + } + if (iskuohao) + { + ishascontent = true; + } + wheresql.append(" randomnumber IN("); + + for(unsigned int i=0;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_ninRandomnumber(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(" randomnumber NOT IN("); + + wheresql.append(val); + wheresql.push_back(')'); + return *mod; + } + + +template + requires std::is_integral_v +M_MODEL& or_ninRandomnumber(const std::vector& val) + { + if (wheresql.empty()) + { + } + else + { + if (ishascontent) + { + wheresql.append(" OR "); + } + else + { + if (!iskuohao) + { + wheresql.append(" OR "); + } + } + } + if (iskuohao) + { + ishascontent = true; + } + wheresql.append(" randomnumber NOT IN("); + + for(unsigned int i=0;i 0) + { + wheresql.push_back(','); + } + wheresql.append(std::to_string(val[i])); + } + wheresql.push_back(')'); + + return *mod; + } + + +M_MODEL& or_ninRandomnumber(const std::vector& val) + { + if (wheresql.empty()) + { + } + else + { + if (ishascontent) + { + wheresql.append(" OR "); + } + else + { + if (!iskuohao) + { + wheresql.append(" OR "); + } + } + } + if (iskuohao) + { + ishascontent = true; + } + wheresql.append(" randomnumber NOT IN("); + + for(unsigned int i=0;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_btRandomnumber(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(" randomnumber > "); + + 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_beRandomnumber(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(" randomnumber >= "); + + 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_ltRandomnumber(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(" randomnumber < "); + + 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_leRandomnumber(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(" randomnumber <= "); + + 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 + requires std::is_integral_v +M_MODEL& eqRandomnumber(T val) + { + if (wheresql.empty()) + { + } + else + { + if (ishascontent) + { + wheresql.append(" AND "); + } + else + { + if (!iskuohao) + { + wheresql.append(" AND "); + } + } + } + if (iskuohao) + { + ishascontent = true; + } + wheresql.append(" randomnumber = "); + + wheresql.append(std::to_string(val)); + return *mod; + } + + +template + requires std::is_integral_v +M_MODEL& nqRandomnumber(T val) + { + if (wheresql.empty()) + { + } + else + { + if (ishascontent) + { + wheresql.append(" AND "); + } + else + { + if (!iskuohao) + { + wheresql.append(" AND "); + } + } + } + if (iskuohao) + { + ishascontent = true; + } + wheresql.append(" randomnumber != "); + + wheresql.append(std::to_string(val)); + return *mod; + } + + +template + requires std::is_integral_v +M_MODEL& btRandomnumber(T val) + { + if (wheresql.empty()) + { + } + else + { + if (ishascontent) + { + wheresql.append(" AND "); + } + else + { + if (!iskuohao) + { + wheresql.append(" AND "); + } + } + } + if (iskuohao) + { + ishascontent = true; + } + wheresql.append(" randomnumber > "); + + wheresql.append(std::to_string(val)); + return *mod; + } + + +template + requires std::is_integral_v +M_MODEL& beRandomnumber(T val) + { + if (wheresql.empty()) + { + } + else + { + if (ishascontent) + { + wheresql.append(" AND "); + } + else + { + if (!iskuohao) + { + wheresql.append(" AND "); + } + } + } + if (iskuohao) + { + ishascontent = true; + } + wheresql.append(" randomnumber >= "); + + wheresql.append(std::to_string(val)); + return *mod; + } + + +template + requires std::is_integral_v +M_MODEL& ltRandomnumber(T val) + { + if (wheresql.empty()) + { + } + else + { + if (ishascontent) + { + wheresql.append(" AND "); + } + else + { + if (!iskuohao) + { + wheresql.append(" AND "); + } + } + } + if (iskuohao) + { + ishascontent = true; + } + wheresql.append(" randomnumber < "); + + wheresql.append(std::to_string(val)); + return *mod; + } + + +template + requires std::is_integral_v +M_MODEL& leRandomnumber(T val) + { + if (wheresql.empty()) + { + } + else + { + if (ishascontent) + { + wheresql.append(" AND "); + } + else + { + if (!iskuohao) + { + wheresql.append(" AND "); + } + } + } + if (iskuohao) + { + ishascontent = true; + } + wheresql.append(" randomnumber <= "); + + wheresql.append(std::to_string(val)); + return *mod; + } + + +template + requires std::is_integral_v +M_MODEL& or_eqRandomnumber(T val) + { + if (wheresql.empty()) + { + } + else + { + if (ishascontent) + { + wheresql.append(" OR "); + } + else + { + if (!iskuohao) + { + wheresql.append(" OR "); + } + } + } + if (iskuohao) + { + ishascontent = true; + } + wheresql.append(" randomnumber = "); + + wheresql.append(std::to_string(val)); + return *mod; + } + + +template + requires std::is_integral_v +M_MODEL& or_nqRandomnumber(T val) + { + if (wheresql.empty()) + { + } + else + { + if (ishascontent) + { + wheresql.append(" OR "); + } + else + { + if (!iskuohao) + { + wheresql.append(" OR "); + } + } + } + if (iskuohao) + { + ishascontent = true; + } + wheresql.append(" randomnumber != "); + + wheresql.append(std::to_string(val)); + return *mod; + } + + +template + requires std::is_integral_v +M_MODEL& or_btRandomnumber(T val) + { + if (wheresql.empty()) + { + } + else + { + if (ishascontent) + { + wheresql.append(" OR "); + } + else + { + if (!iskuohao) + { + wheresql.append(" OR "); + } + } + } + if (iskuohao) + { + ishascontent = true; + } + wheresql.append(" randomnumber > "); + + wheresql.append(std::to_string(val)); + return *mod; + } + + +template + requires std::is_integral_v +M_MODEL& or_beRandomnumber(T val) + { + if (wheresql.empty()) + { + } + else + { + if (ishascontent) + { + wheresql.append(" OR "); + } + else + { + if (!iskuohao) + { + wheresql.append(" OR "); + } + } + } + if (iskuohao) + { + ishascontent = true; + } + wheresql.append(" randomnumber >= "); + + wheresql.append(std::to_string(val)); + return *mod; + } + + +template + requires std::is_integral_v +M_MODEL& or_ltRandomnumber(T val) + { + if (wheresql.empty()) + { + } + else + { + if (ishascontent) + { + wheresql.append(" OR "); + } + else + { + if (!iskuohao) + { + wheresql.append(" OR "); + } + } + } + if (iskuohao) + { + ishascontent = true; + } + wheresql.append(" randomnumber < "); + + wheresql.append(std::to_string(val)); + return *mod; + } + + +template + requires std::is_integral_v +M_MODEL& or_leRandomnumber(T val) + { + if (wheresql.empty()) + { + } + else + { + if (ishascontent) + { + wheresql.append(" OR "); + } + else + { + if (!iskuohao) + { + wheresql.append(" OR "); + } + } + } + if (iskuohao) + { + ishascontent = true; + } + wheresql.append(" randomnumber <= "); + + wheresql.append(std::to_string(val)); + 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 + 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 + 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 + 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 + 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 + 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 + 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 &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 &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 + 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 + 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 + 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> 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> 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_array; + unsigned char action_setup = 0; + unsigned int column_num = 0; + unsigned int offset = 0; + + std::vector 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 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::map, std::vector>> + 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> temprecord; + std::vector table_fieldname; + std::map table_fieldmap; + + if (iscache) + { + std::size_t sqlhashid = std::hash{}(sqlstring); + + model_meta_cache> &temp_cache = + model_meta_cache>::getinstance(); + temprecord = temp_cache.get(sqlhashid); + if (temprecord.size() > 0) + { + iscache = false; + model_meta_cache &table_cache = model_meta_cache::getinstance(); + table_fieldname = table_cache.get(sqlhashid); + + model_meta_cache> &tablemap_cache = + model_meta_cache>::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_array; + // std::vector> field_value; + + unsigned char action_setup = 0; + unsigned int column_num = 0; + + unsigned int offset = 0; + + std::vector 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 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{}(sqlstring); + + model_meta_cache> &temp_cache = + model_meta_cache>::getinstance(); + temp_cache.save(sqlhashid, temprecord, exptime); + + exptime += 1; + model_meta_cache &table_cache = model_meta_cache::getinstance(); + table_cache.save(sqlhashid, table_fieldname, exptime); + + model_meta_cache> &tablemap_cache = + model_meta_cache>::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{}(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_array; + + unsigned char action_setup = 0; + unsigned int column_num = 0; + + unsigned int offset = 0; + + std::vector 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 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{}(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_array; + + unsigned char action_setup = 0; + unsigned int column_num = 0; + + unsigned int offset = 0; + + std::vector 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{}(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_array; + + unsigned char action_setup = 0; + unsigned int column_num = 0; + + unsigned int offset = 0; + + std::vector 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 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{}(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_array; + // std::vector> field_value; + + unsigned char action_setup = 0; + unsigned int column_num = 0; + + unsigned int offset = 0; + + std::vector field_pos; + // std::map 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{}(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_array; + unsigned char action_setup = 0; + unsigned int column_num = 0; + unsigned int offset = 0; + + std::vector 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 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{}(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_array; + // std::vector> field_value; + + unsigned char action_setup = 0; + unsigned int column_num = 0; + + unsigned int offset = 0; + + std::vector field_pos; + // std::map 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 &temp_cache = model_meta_cache::getinstance(); + temp_cache.remove_exptime(); + } + void clear_cache() + { + model_meta_cache &temp_cache = model_meta_cache::getinstance(); + temp_cache.clear(); + } + bool remove_cache() + { + model_meta_cache &temp_cache = model_meta_cache::getinstance(); + std::size_t sqlhashid = std::hash{}(sqlstring); + return temp_cache.remove(sqlhashid); + } + bool remove_cache(std::size_t cache_key_name) + { + model_meta_cache &temp_cache = model_meta_cache::getinstance(); + return temp_cache.remove(cache_key_name); + } + int check_cache(std::size_t cache_key_name) + { + model_meta_cache &temp_cache = model_meta_cache::getinstance(); + return temp_cache.check(cache_key_name); + } + std::vector get_cache_data(std::size_t cache_key_name) + { + model_meta_cache &temp_cache = model_meta_cache::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 &temp_cache = model_meta_cache::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 &temp_cache = model_meta_cache::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 &temp_cache = model_meta_cache::getinstance(); + std::size_t sqlhashid = std::hash{}(sqlstring); + return temp_cache.update(sqlhashid, exp_time); + } + int update_cache(std::size_t cache_key_name, int exp_time) + { + model_meta_cache &temp_cache = model_meta_cache::getinstance(); + return temp_cache.update(cache_key_name, exp_time); + } + bool save_cache(int exp_time = 0) + { + model_meta_cache &temp_cache = model_meta_cache::getinstance(); + std::size_t sqlhashid = std::hash{}(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 &temp_cache = model_meta_cache::getinstance(); + temp_cache.save(cache_key_name, cache_data, exp_time); + return true; + } + + bool save_cache(std::size_t cache_key_name, std::vector &cache_data, int exp_time = 0) + { + model_meta_cache &temp_cache = model_meta_cache::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 &temp_cache = model_meta_cache::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_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 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_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{}(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_array; + + unsigned char action_setup = 0; + unsigned int column_num = 0; + + unsigned int offset = 0; + + std::vector 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 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{}(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_array; + + unsigned char action_setup = 0; + unsigned int column_num = 0; + + unsigned int offset = 0; + + std::vector 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 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 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 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 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 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 &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 async_insert(std::vector &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 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 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::map, std::vector>> + query(const std::string &rawsql) + { + + std::vector> temprecord; + std::vector table_fieldname; + std::map table_fieldmap; + + if(rawsql.size()>10) + { + unsigned int i=0; + for(;iget_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_array; + + unsigned char action_setup = 0; + unsigned int column_num = 0; + + unsigned int offset = 0; + + std::vector 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 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::map, std::vector>>> + async_query(const std::string &rawsql) + { + + std::vector> temprecord; + std::vector table_fieldname; + std::map table_fieldmap; + + if(rawsql.size()>10) + { + unsigned int i=0; + for(;iasync_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_array; + + unsigned char action_setup = 0; + unsigned int column_num = 0; + + unsigned int offset = 0; + + std::vector 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 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 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 conn_obj; + }; +//} /*tagnamespace_replace*/ +}// namespace orm +#endif \ No newline at end of file diff --git a/frameworks/C++/paozhu/paozhu_benchmark/orm/include/worldbase.h b/frameworks/C++/paozhu/paozhu_benchmark/orm/include/worldbase.h old mode 100755 new mode 100644 index 2bba08096e2..93f7c1f14b2 --- a/frameworks/C++/paozhu/paozhu_benchmark/orm/include/worldbase.h +++ b/frameworks/C++/paozhu/paozhu_benchmark/orm/include/worldbase.h @@ -2,7 +2,7 @@ #define ORM_DEFAULT_WORLDBASEMATA_H /* *This file is auto create from cli -*本文件为自动生成 Fri, 26 Jan 2024 02:59:30 GMT +*本文件为自动生成 Sun, 02 Mar 2025 10:54:30 GMT ***/ #include #include @@ -14,28 +14,30 @@ #include #include #include -#include "mysql.h" +#include "unicode.h" + namespace orm { struct worldbase { struct meta{ - unsigned int id= 0; // - int randomnumber= 0; // + unsigned int id = 0; ///**/ + int randomnumber = 0; ///**/ } data; std::vector record; std::string _rmstag="default";//this value must be default or tag value, tag in mysqlconnect config file . -std::vector _keypos{0x00}; -MYSQL_ROW _row; +unsigned int _offset=0; std::vector::iterator begin(){ return record.begin(); } std::vector::iterator end(){ return record.end(); } std::vector::const_iterator begin() const{ return record.begin(); } std::vector::const_iterator end() const{ return record.end(); } -const std::array colnames={"id","randomnumber"}; -const std::array colnamestype= {3,3}; +static constexpr std::array col_names={"id","randomnumber"}; +static constexpr std::array col_types={3,3}; +static constexpr std::array col_length={0,0}; +static constexpr std::array col_decimals={0,0}; std::string tablename="world"; -std::string modelname="World"; +static constexpr std::string_view modelname="World"; unsigned char findcolpos(const std::string &coln){ if(coln.size()==0) @@ -82,70 +84,9 @@ break; return temp; } - void _setColnamevalue() - { - for(unsigned char i=0;i<_keypos.size();i++) - { - switch(_keypos[i]){ - case 0: - try{ - data.id=std::stoul(_row[i]); - }catch (...) { - data.id=0; - } - break; - case 1: - try{ - data.randomnumber=std::stoi(_row[i]); - }catch (...) { - data.randomnumber=0; - } - break; - default: - { } - - - } - - if(i>210){ - break; - } - } - } - void _addnewrowvalue(){ - worldbase::meta metatemp; - - for(unsigned char i=0;i<_keypos.size();i++){ - - switch(_keypos[i]){ - - case 0: - try{ - metatemp.id=std::stoul(_row[i]); - }catch (...) { - metatemp.id=0; - } - break; - case 1: - try{ - metatemp.randomnumber=std::stoi(_row[i]); - }catch (...) { - metatemp.randomnumber=0; - } - break; - default: - { } - - - } - if(i>210){ - break; - } - } - record.emplace_back(std::move(metatemp)); - } + - inline std::string stringaddslash(std::string &content){ + inline std::string stringaddslash(const std::string &content){ std::string temp; for(unsigned int i=0;i0){ - tempsql<<"`,`"; - }else{ - tempsql<<"`"; - } - tempsql<0){ - tempsql<<"`"; - } - tempsql<<") VALUES ("; + unsigned int j=0; + std::ostringstream tempsql; + tempsql<<"INSERT INTO "; + tempsql<0){ + tempsql<<"`,`"; + }else{ + tempsql<<"`"; + } + tempsql<0){ + tempsql<<"`"; + } + tempsql<<") VALUES ("; if(data.id==0){ tempsql<<"null"; @@ -213,24 +154,24 @@ tempsql<<")"; return tempsql.str(); } - std::string _makerecordinsertsql( meta &insert_data){ - unsigned int j=0; - std::ostringstream tempsql; - tempsql<<"INSERT INTO "; - tempsql<0){ - tempsql<<"`,`"; - }else{ - tempsql<<"`"; - } - tempsql<0){ - tempsql<<"`"; - } - tempsql<<") VALUES ("; + std::string _makerecordinsertsql(const meta &insert_data){ + unsigned int j=0; + std::ostringstream tempsql; + tempsql<<"INSERT INTO "; + tempsql<0){ + tempsql<<"`,`"; + }else{ + tempsql<<"`"; + } + tempsql<0){ + tempsql<<"`"; + } + tempsql<<") VALUES ("; if(insert_data.id==0){ tempsql<<"null"; @@ -248,35 +189,35 @@ tempsql<<")"; return tempsql.str(); } - std::string _makerecordinsertsql( std::vector &insert_data){ - unsigned int j=0; - std::ostringstream tempsql; - tempsql<<"INSERT INTO "; - tempsql<0){ - tempsql<<"`,`"; - }else{ - tempsql<<"`"; - } - tempsql<0){ - tempsql<<"`"; - } - tempsql<<") VALUES "; + std::string _makerecordinsertsql(const std::vector &insert_data){ + unsigned int j=0; + std::ostringstream tempsql; + tempsql<<"INSERT INTO "; + tempsql<0){ + tempsql<<"`,`"; + }else{ + tempsql<<"`"; + } + tempsql<0){ + tempsql<<"`"; + } + tempsql<<") VALUES "; - for(unsigned int i=0;i0) - { - tempsql<<","; - } - tempsql<<"("; + for(unsigned int i=0;i0) + { + tempsql<<","; + } + tempsql<<"("; - if(insert_data[i].id==0){ + if(insert_data[i].id==0){ tempsql<<"null"; }else{ tempsql<0){ unsigned char bpos_i=findcolpos(keyname); #ifdef DEBUG - if (bpos_i == 254) + if (bpos_i == 255) { std::cout << "\033[1m\033[31m-----------\n" << keyname << " not in " << tablename << " table Field.\n-----------\033[0m" @@ -395,7 +335,7 @@ if(data.randomnumber==0){ tempsql << "REPLACE INTO "; tempsql << tablename; tempsql << " ("; - for (; j < colnames.size(); j++) + for (; j < col_names.size(); j++) { if (j > 0) { @@ -405,7 +345,7 @@ if(data.randomnumber==0){ { tempsql << "`"; } - tempsql << colnames[j]; + tempsql << col_names[j]; } if (j > 0) { @@ -443,7 +383,7 @@ if(data.randomnumber==0){ tempsql << "INSERT INTO "; tempsql << tablename; tempsql << " ("; - for (; j < colnames.size(); j++) + for (; j < col_names.size(); j++) { if (j > 0) { @@ -453,7 +393,7 @@ if(data.randomnumber==0){ { tempsql << "`"; } - tempsql << colnames[j]; + tempsql << col_names[j]; } if (j > 0) { @@ -483,33 +423,12 @@ if(data.randomnumber==0){ tempsql<<" as new ON DUPLICATE KEY UPDATE "; - std::string keyname; - unsigned char jj=0; - j=0; - if(fileld.size()>0){ - for(;jj0) - { - tempsql<<","; - } - tempsql<0){ + std::string keyname; + unsigned char jj=0; + j=0; + if(fileld.size()>0){ + for(;jj0) @@ -519,10 +438,30 @@ if(data.randomnumber==0){ tempsql<0){ + if(findcolpos(keyname)<255) + { + if(j>0) + { + tempsql<<","; + } + tempsql< keypos; if(fileld.size()>1){ for(;jj0){ - keypos.emplace_back(findcolpos(keyname)); - keyname.clear(); + keypos.emplace_back(findcolpos(keyname)); + keyname.clear(); } }else{ - for(jj=0;jj data_tomap(std::string fileld=""){ std::map tempsql; - std::string keyname; - unsigned char jj=0; - std::vector keypos; - if(fileld.size()>1){ - for(;jj keypos; + if(fileld.size()>1){ + for(;jj0){ - keypos.emplace_back(findcolpos(keyname)); - keyname.clear(); - } - }else{ - for(jj=0;jj0){ + keypos.emplace_back(findcolpos(keyname)); + keyname.clear(); + } + }else{ + for(jj=0;jj keypos; - if(fileld.size()>0){ - for(;jj keypos; + if(fileld.size()>0){ + for(;jj0){ - keypos.emplace_back(findcolpos(keyname)); - keyname.clear(); - } - }else{ - for(jj=0;jj0){ + keypos.emplace_back(findcolpos(keyname)); + keyname.clear(); + } + }else{ + for(jj=0;jj0){ tempsql<<","; } if(data.id==0){ @@ -1024,43 +963,43 @@ if(data.randomnumber==0){ } std::string to_json(std::string fileld=""){ - std::ostringstream tempsql; - std::string keyname; - unsigned char jj=0; - std::vector keypos; - if(fileld.size()>0){ - for(;jj keypos; + if(fileld.size()>0){ + for(;jj0){ - keypos.emplace_back(findcolpos(keyname)); - keyname.clear(); - } - }else{ - for(jj=0;jj0){ - tempsql<<",{"; - }else{ - tempsql<<"{"; - } - - for(jj=0;jj0){ + keypos.emplace_back(findcolpos(keyname)); + keyname.clear(); + } + }else{ + for(jj=0;jj0){ + tempsql<<",{"; + }else{ + tempsql<<"{"; + } + + for(jj=0;jj0){ tempsql<<","; } if(record[n].id==0){ @@ -1090,49 +1029,49 @@ if(record[n].randomnumber==0){ std::string to_json(std::function func,std::string fileld=""){ std::ostringstream tempsql; - std::string keyname; - unsigned char jj=0; - std::vector keypos; - if(fileld.size()>0){ - for(;jj keypos; + if(fileld.size()>0){ + for(;jj0){ - keypos.emplace_back(findcolpos(keyname)); - keyname.clear(); - } - }else{ - for(jj=0;jj0){ - tempsql<<",{"; - }else{ - tempsql<<"{"; - } - tempsql<0){ + keypos.emplace_back(findcolpos(keyname)); + keyname.clear(); + } + }else{ + for(jj=0;jj0){ + tempsql<<",{"; + }else{ + tempsql<<"{"; + } + tempsql<0){ tempsql<<","; } if(record[n].id==0){ @@ -1161,8 +1100,8 @@ if(record[n].randomnumber==0){ } long long getPK(){ return data.id; } void setPK(long long val){ data.id=val;} -unsigned int getId(){ return data.id; } - void setId(unsigned int val){ data.id=val;} + unsigned int getId(){ return data.id; } + void setId( unsigned int val){ data.id=val;} int getRandomnumber(){ return data.randomnumber; } void setRandomnumber( int val){ data.randomnumber=val;}