diff --git a/programs/library-bridge/LibraryBridgeHandlers.cpp b/programs/library-bridge/LibraryBridgeHandlers.cpp index bdb5f3ca02b..a28148bd1f7 100644 --- a/programs/library-bridge/LibraryBridgeHandlers.cpp +++ b/programs/library-bridge/LibraryBridgeHandlers.cpp @@ -19,7 +19,6 @@ #include #include #include -#include namespace DB @@ -92,27 +91,25 @@ void ExternalDictionaryLibraryBridgeRequestHandler::handleRequest(HTTPServerRequ LOG_TRACE(log, "Request URI: {}", request.getURI()); HTMLForm params(getContext()->getSettingsRef(), request); + size_t version; + if (!params.has("version")) - { - processError(response, "No 'version' in request URL"); - return; - } + version = 0; /// assumed version for too old servers which do not send a version else { String version_str = params.get("version"); - size_t version; - auto [_, ec] = std::from_chars(version_str.data(), version_str.data() + version_str.size(), version); - if (ec != std::errc()) + if (!tryParse(version, version_str)) { processError(response, "Unable to parse 'version' string in request URL: '" + version_str + "' Check if the server and library-bridge have the same version."); return; } - if (version != LIBRARY_BRIDGE_PROTOCOL_VERSION) - { - // backwards compatibility is for now deemed unnecessary, just let the user upgrade the server and bridge to the same version - processError(response, "Server and library-bridge have different versions: '" + std::to_string(version) + "' vs. '" + std::to_string(LIBRARY_BRIDGE_PROTOCOL_VERSION) + "'"); - return; - } + } + + if (version != LIBRARY_BRIDGE_PROTOCOL_VERSION) + { + /// backwards compatibility is considered unnecessary for now, just let the user know that the server and the bridge must be upgraded together + processError(response, "Server and library-bridge have different versions: '" + std::to_string(version) + "' vs. '" + std::to_string(LIBRARY_BRIDGE_PROTOCOL_VERSION) + "'"); + return; } if (!params.has("method")) diff --git a/programs/odbc-bridge/ColumnInfoHandler.cpp b/programs/odbc-bridge/ColumnInfoHandler.cpp index 7d2f6f57d34..0ea2495af78 100644 --- a/programs/odbc-bridge/ColumnInfoHandler.cpp +++ b/programs/odbc-bridge/ColumnInfoHandler.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -23,8 +24,6 @@ #include #include -#include - namespace DB { @@ -83,27 +82,25 @@ void ODBCColumnsInfoHandler::handleRequest(HTTPServerRequest & request, HTTPServ LOG_WARNING(log, fmt::runtime(message)); }; + size_t version; + if (!params.has("version")) - { - process_error("No 'version' in request URL"); - return; - } + version = 0; /// assumed version for too old servers which do not send a version else { String version_str = params.get("version"); - size_t version; - auto [_, ec] = std::from_chars(version_str.data(), version_str.data() + version_str.size(), version); - if (ec != std::errc()) + if (!tryParse(version, version_str)) { process_error("Unable to parse 'version' string in request URL: '" + version_str + "' Check if the server and library-bridge have the same version."); return; } - if (version != XDBC_BRIDGE_PROTOCOL_VERSION) - { - // backwards compatibility is for now deemed unnecessary, just let the user upgrade the server and bridge to the same version - process_error("Server and library-bridge have different versions: '" + std::to_string(version) + "' vs. '" + std::to_string(LIBRARY_BRIDGE_PROTOCOL_VERSION) + "'"); - return; - } + } + + if (version != XDBC_BRIDGE_PROTOCOL_VERSION) + { + /// backwards compatibility is considered unnecessary for now, just let the user know that the server and the bridge must be upgraded together + process_error("Server and library-bridge have different versions: '" + std::to_string(version) + "' vs. '" + std::to_string(LIBRARY_BRIDGE_PROTOCOL_VERSION) + "'"); + return; } if (!params.has("table")) diff --git a/programs/odbc-bridge/IdentifierQuoteHandler.cpp b/programs/odbc-bridge/IdentifierQuoteHandler.cpp index b162a2ea324..8157e3b6159 100644 --- a/programs/odbc-bridge/IdentifierQuoteHandler.cpp +++ b/programs/odbc-bridge/IdentifierQuoteHandler.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -17,8 +18,6 @@ #include "validateODBCConnectionString.h" #include "ODBCPooledConnectionFactory.h" -#include - namespace DB { @@ -35,27 +34,25 @@ void IdentifierQuoteHandler::handleRequest(HTTPServerRequest & request, HTTPServ LOG_WARNING(log, fmt::runtime(message)); }; + size_t version; + if (!params.has("version")) - { - process_error("No 'version' in request URL"); - return; - } + version = 0; /// assumed version for too old servers which do not send a version else { String version_str = params.get("version"); - size_t version; - auto [_, ec] = std::from_chars(version_str.data(), version_str.data() + version_str.size(), version); - if (ec != std::errc()) + if (!tryParse(version, version_str)) { process_error("Unable to parse 'version' string in request URL: '" + version_str + "' Check if the server and library-bridge have the same version."); return; } - if (version != XDBC_BRIDGE_PROTOCOL_VERSION) - { - // backwards compatibility is for now deemed unnecessary, just let the user upgrade the server and bridge to the same version - process_error("Server and library-bridge have different versions: '" + std::to_string(version) + "' vs. '" + std::to_string(LIBRARY_BRIDGE_PROTOCOL_VERSION) + "'"); - return; - } + } + + if (version != XDBC_BRIDGE_PROTOCOL_VERSION) + { + /// backwards compatibility is considered unnecessary for now, just let the user know that the server and the bridge must be upgraded together + process_error("Server and library-bridge have different versions: '" + std::to_string(version) + "' vs. '" + std::to_string(LIBRARY_BRIDGE_PROTOCOL_VERSION) + "'"); + return; } if (!params.has("connection_string")) diff --git a/programs/odbc-bridge/MainHandler.cpp b/programs/odbc-bridge/MainHandler.cpp index 6ece12198d3..fe22d8facfd 100644 --- a/programs/odbc-bridge/MainHandler.cpp +++ b/programs/odbc-bridge/MainHandler.cpp @@ -22,7 +22,6 @@ #include #include -#include #include #include @@ -57,29 +56,28 @@ void ODBCHandler::handleRequest(HTTPServerRequest & request, HTTPServerResponse HTMLForm params(getContext()->getSettingsRef(), request); LOG_TRACE(log, "Request URI: {}", request.getURI()); + size_t version; + if (!params.has("version")) - { - processError(response, "No 'version' in request URL"); - return; - } + version = 0; /// assumed version for too old servers which do not send a version else { String version_str = params.get("version"); - size_t version; - auto [_, ec] = std::from_chars(version_str.data(), version_str.data() + version_str.size(), version); - if (ec != std::errc()) + if (!tryParse(version, version_str)) { processError(response, "Unable to parse 'version' string in request URL: '" + version_str + "' Check if the server and library-bridge have the same version."); return; } - if (version != XDBC_BRIDGE_PROTOCOL_VERSION) - { - // backwards compatibility is for now deemed unnecessary, just let the user upgrade the server and bridge to the same version - processError(response, "Server and library-bridge have different versions: '" + std::to_string(version) + "' vs. '" + std::to_string(LIBRARY_BRIDGE_PROTOCOL_VERSION) + "'"); - return; - } } + if (version != XDBC_BRIDGE_PROTOCOL_VERSION) + { + /// backwards compatibility is considered unnecessary for now, just let the user know that the server and the bridge must be upgraded together + processError(response, "Server and library-bridge have different versions: '" + std::to_string(version) + "' vs. '" + std::to_string(LIBRARY_BRIDGE_PROTOCOL_VERSION) + "'"); + return; + } + + if (mode == "read") params.read(request.getStream()); diff --git a/programs/odbc-bridge/SchemaAllowedHandler.cpp b/programs/odbc-bridge/SchemaAllowedHandler.cpp index f70474fc898..4d20c8bc3b7 100644 --- a/programs/odbc-bridge/SchemaAllowedHandler.cpp +++ b/programs/odbc-bridge/SchemaAllowedHandler.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -14,8 +15,6 @@ #include #include -#include - namespace DB { @@ -43,29 +42,28 @@ void SchemaAllowedHandler::handleRequest(HTTPServerRequest & request, HTTPServer LOG_WARNING(log, fmt::runtime(message)); }; + size_t version; + if (!params.has("version")) - { - process_error("No 'version' in request URL"); - return; - } + version = 0; /// assumed version for too old servers which do not send a version else { String version_str = params.get("version"); - size_t version; - auto [_, ec] = std::from_chars(version_str.data(), version_str.data() + version_str.size(), version); - if (ec != std::errc()) + if (!tryParse(version, version_str)) { process_error("Unable to parse 'version' string in request URL: '" + version_str + "' Check if the server and library-bridge have the same version."); return; } - if (version != XDBC_BRIDGE_PROTOCOL_VERSION) - { - // backwards compatibility is for now deemed unnecessary, just let the user upgrade the server and bridge to the same version - process_error("Server and library-bridge have different versions: '" + std::to_string(version) + "' vs. '" + std::to_string(LIBRARY_BRIDGE_PROTOCOL_VERSION) + "'"); - return; - } } + if (version != XDBC_BRIDGE_PROTOCOL_VERSION) + { + /// backwards compatibility is considered unnecessary for now, just let the user know that the server and the bridge must be upgraded together + process_error("Server and library-bridge have different versions: '" + std::to_string(version) + "' vs. '" + std::to_string(LIBRARY_BRIDGE_PROTOCOL_VERSION) + "'"); + return; + } + + if (!params.has("connection_string")) { process_error("No 'connection_string' in request URL");