diff --git a/include/Base_Session.h b/include/Base_Session.h index 16c66009c..e491b718a 100644 --- a/include/Base_Session.h +++ b/include/Base_Session.h @@ -12,6 +12,11 @@ template class Base_Session; #ifndef CLASS_BASE_SESSION_H #define CLASS_BASE_SESSION_H +#ifndef PROXYJSON +#define PROXYJSON +namespace nlohmann { class json; } +#endif // PROXYJSON + class MySQL_STMTs_meta; class StmtLongDataHandler; class MySQL_Session; @@ -21,7 +26,7 @@ template class Base_Session { public: Base_Session(); - ~Base_Session(); + virtual ~Base_Session(); // uint64_t unsigned long long start_time; @@ -102,6 +107,10 @@ class Base_Session { B * create_backend(int, DS * _myds = NULL); B * find_or_create_backend(int, DS * _myds = NULL); void writeout(); + void return_proxysql_internal(PtrSize_t* pkt); + virtual void generate_proxysql_internal_session_json(nlohmann::json &) = 0; + virtual void RequestEnd(DS *) = 0; + virtual void SQLite3_to_MySQL(SQLite3_result*, char*, int, MySQL_Protocol*, bool in_transaction = false, bool deprecate_eof_active = false) = 0; }; #endif // CLASS_BASE_SESSION_H diff --git a/include/MySQL_Session.h b/include/MySQL_Session.h index 23511a64b..eafb23ca7 100644 --- a/include/MySQL_Session.h +++ b/include/MySQL_Session.h @@ -154,7 +154,7 @@ class MySQL_Session: public Base_Session::init(); template void Base_Session::init(); @@ -36,6 +42,9 @@ template PgSQL_Backend * Base_Session::writeout(); template void Base_Session::writeout(); +template void Base_Session::return_proxysql_internal(_PtrSize_t*); +template void Base_Session::return_proxysql_internal(_PtrSize_t*); + template Base_Session::Base_Session() { }; @@ -274,3 +283,43 @@ void PgSQL_Session::writeout() { } } #endif // 0 + + +template +void Base_Session::return_proxysql_internal(PtrSize_t* pkt) { + unsigned int l = 0; + l = strlen((char*)"PROXYSQL INTERNAL SESSION"); + if (pkt->size == (5 + l) && strncasecmp((char*)"PROXYSQL INTERNAL SESSION", (char*)pkt->ptr + 5, l) == 0) { + json j; + generate_proxysql_internal_session_json(j); + std::string s = j.dump(4, ' ', false, json::error_handler_t::replace); + SQLite3_result* resultset = new SQLite3_result(1); + resultset->add_column_definition(SQLITE_TEXT, "session_info"); + char* pta[1]; + pta[0] = (char*)s.c_str(); + resultset->add_row(pta); + bool deprecate_eof_active = client_myds->myconn->options.client_flag & CLIENT_DEPRECATE_EOF; + SQLite3_to_MySQL(resultset, NULL, 0, &client_myds->myprot, false, deprecate_eof_active); + delete resultset; + l_free(pkt->size, pkt->ptr); + return; + } + // default + client_myds->DSS = STATE_QUERY_SENT_NET; + if constexpr (std::is_same_v) { + client_myds->myprot.generate_pkt_ERR(true,NULL,NULL,1,1064,(char *)"42000",(char *)"Unknown PROXYSQL INTERNAL command",true); + } else if constexpr (std::is_same_v) { + client_myds->myprot.generate_error_packet(true, true, "Unknown PROXYSQL INTERNAL command", PGSQL_ERROR_CODES::ERRCODE_SYNTAX_ERROR, false, true); + } else { + assert(0); + } + if (mirror == false) { + RequestEnd(NULL); + } + else { + client_myds->DSS = STATE_SLEEP; + status = WAITING_CLIENT_DATA; + } + l_free(pkt->size, pkt->ptr); +} + diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index dafac743b..349dce807 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -1279,6 +1279,7 @@ void MySQL_Session::generate_proxysql_internal_session_json(json &j) { } } +#if 0 void MySQL_Session::return_proxysql_internal(PtrSize_t *pkt) { unsigned int l = 0; l = strlen((char *)"PROXYSQL INTERNAL SESSION"); @@ -1308,6 +1309,7 @@ void MySQL_Session::return_proxysql_internal(PtrSize_t *pkt) { } l_free(pkt->size,pkt->ptr); } +#endif // 0 /** * @brief Handles special queries executed by the STATUS command in mysql cli . diff --git a/lib/PgSQL_Session.cpp b/lib/PgSQL_Session.cpp index 9a6b5feb2..d851b4f6c 100644 --- a/lib/PgSQL_Session.cpp +++ b/lib/PgSQL_Session.cpp @@ -1256,6 +1256,7 @@ void PgSQL_Session::generate_proxysql_internal_session_json(json& j) { } } +#if 0 void PgSQL_Session::return_proxysql_internal(PtrSize_t* pkt) { unsigned int l = 0; l = strlen((char*)"PROXYSQL INTERNAL SESSION"); @@ -1286,6 +1287,7 @@ void PgSQL_Session::return_proxysql_internal(PtrSize_t* pkt) { } l_free(pkt->size, pkt->ptr); } +#endif // 0 /** * @brief Handles special queries executed by the STATUS command in pgsql cli .