2018-09-27 15:23:42 +00:00
|
|
|
#include "IdentifierQuoteHandler.h"
|
|
|
|
|
2020-05-08 14:11:19 +00:00
|
|
|
#if USE_ODBC
|
|
|
|
|
|
|
|
# include <DataTypes/DataTypeFactory.h>
|
2021-02-19 12:51:26 +00:00
|
|
|
# include <Server/HTTP/HTMLForm.h>
|
|
|
|
# include <Server/HTTP/WriteBufferFromHTTPServerResponse.h>
|
2020-05-08 14:11:19 +00:00
|
|
|
# include <IO/WriteHelpers.h>
|
|
|
|
# include <Parsers/ParserQueryWithOutput.h>
|
|
|
|
# include <Parsers/parseQuery.h>
|
|
|
|
# include <Poco/Data/ODBC/ODBCException.h>
|
|
|
|
# include <Poco/Data/ODBC/SessionImpl.h>
|
|
|
|
# include <Poco/Data/ODBC/Utility.h>
|
|
|
|
# include <Poco/Net/HTTPServerRequest.h>
|
|
|
|
# include <Poco/Net/HTTPServerResponse.h>
|
|
|
|
# include <common/logger_useful.h>
|
|
|
|
# include <ext/scope_guard.h>
|
|
|
|
# include "getIdentifierQuote.h"
|
|
|
|
# include "validateODBCConnectionString.h"
|
2018-09-27 15:23:42 +00:00
|
|
|
|
2020-05-08 14:11:19 +00:00
|
|
|
# define POCO_SQL_ODBC_CLASS Poco::Data::ODBC
|
2018-09-27 15:23:42 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2021-02-19 12:51:26 +00:00
|
|
|
void IdentifierQuoteHandler::handleRequest(HTTPServerRequest & request, HTTPServerResponse & response)
|
2018-09-27 15:23:42 +00:00
|
|
|
{
|
2021-02-19 12:51:26 +00:00
|
|
|
HTMLForm params(request, request.getStream());
|
2020-05-23 22:24:01 +00:00
|
|
|
LOG_TRACE(log, "Request URI: {}", request.getURI());
|
2018-09-27 15:23:42 +00:00
|
|
|
|
2018-10-10 08:38:54 +00:00
|
|
|
auto process_error = [&response, this](const std::string & message)
|
|
|
|
{
|
2018-09-27 15:23:42 +00:00
|
|
|
response.setStatusAndReason(Poco::Net::HTTPResponse::HTTP_INTERNAL_SERVER_ERROR);
|
|
|
|
if (!response.sent())
|
2021-02-19 12:51:26 +00:00
|
|
|
*response.send() << message << std::endl;
|
2020-05-23 22:24:01 +00:00
|
|
|
LOG_WARNING(log, message);
|
2018-09-27 15:23:42 +00:00
|
|
|
};
|
|
|
|
|
2018-09-28 02:46:33 +00:00
|
|
|
if (!params.has("connection_string"))
|
2018-09-27 15:23:42 +00:00
|
|
|
{
|
|
|
|
process_error("No 'connection_string' in request URL");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
std::string connection_string = params.get("connection_string");
|
|
|
|
POCO_SQL_ODBC_CLASS::SessionImpl session(validateODBCConnectionString(connection_string), DBMS_DEFAULT_CONNECT_TIMEOUT_SEC);
|
|
|
|
SQLHDBC hdbc = session.dbc().handle();
|
|
|
|
|
2018-09-28 02:46:33 +00:00
|
|
|
auto identifier = getIdentifierQuote(hdbc);
|
2018-09-27 15:23:42 +00:00
|
|
|
|
2021-02-19 12:51:26 +00:00
|
|
|
WriteBufferFromHTTPServerResponse out(response, request.getMethod() == Poco::Net::HTTPRequest::HTTP_HEAD, keep_alive_timeout);
|
2021-02-20 05:31:05 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
writeStringBinary(identifier, out);
|
|
|
|
out.finalize();
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
out.finalize();
|
|
|
|
}
|
2018-09-27 15:23:42 +00:00
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
process_error("Error getting identifier quote style from ODBC '" + getCurrentExceptionMessage(false) + "'");
|
|
|
|
tryLogCurrentException(log);
|
|
|
|
}
|
|
|
|
}
|
2020-05-08 14:11:19 +00:00
|
|
|
|
2018-09-27 15:23:42 +00:00
|
|
|
}
|
2020-05-08 14:11:19 +00:00
|
|
|
|
2018-10-10 08:38:54 +00:00
|
|
|
#endif
|