1#include "IdentifierQuoteHandler.h"
2#if USE_POCO_SQLODBC || USE_POCO_DATAODBC
3
4#if USE_POCO_SQLODBC
5#include <Poco/SQL/ODBC/ODBCException.h>
6#include <Poco/SQL/ODBC/SessionImpl.h>
7#include <Poco/SQL/ODBC/Utility.h>
8#define POCO_SQL_ODBC_CLASS Poco::SQL::ODBC
9#endif
10#if USE_POCO_DATAODBC
11#include <Poco/Data/ODBC/ODBCException.h>
12#include <Poco/Data/ODBC/SessionImpl.h>
13#include <Poco/Data/ODBC/Utility.h>
14#define POCO_SQL_ODBC_CLASS Poco::Data::ODBC
15#endif
16
17#include <DataTypes/DataTypeFactory.h>
18#include <IO/WriteBufferFromHTTPServerResponse.h>
19#include <IO/WriteHelpers.h>
20#include <Parsers/ParserQueryWithOutput.h>
21#include <Parsers/parseQuery.h>
22#include <Poco/Net/HTMLForm.h>
23#include <Poco/Net/HTTPServerRequest.h>
24#include <Poco/Net/HTTPServerResponse.h>
25#include <common/logger_useful.h>
26#include <ext/scope_guard.h>
27#include "getIdentifierQuote.h"
28#include "validateODBCConnectionString.h"
29
30namespace DB
31{
32void IdentifierQuoteHandler::handleRequest(Poco::Net::HTTPServerRequest & request, Poco::Net::HTTPServerResponse & response)
33{
34 Poco::Net::HTMLForm params(request, request.stream());
35 LOG_TRACE(log, "Request URI: " + request.getURI());
36
37 auto process_error = [&response, this](const std::string & message)
38 {
39 response.setStatusAndReason(Poco::Net::HTTPResponse::HTTP_INTERNAL_SERVER_ERROR);
40 if (!response.sent())
41 response.send() << message << std::endl;
42 LOG_WARNING(log, message);
43 };
44
45 if (!params.has("connection_string"))
46 {
47 process_error("No 'connection_string' in request URL");
48 return;
49 }
50
51 try
52 {
53 std::string connection_string = params.get("connection_string");
54 POCO_SQL_ODBC_CLASS::SessionImpl session(validateODBCConnectionString(connection_string), DBMS_DEFAULT_CONNECT_TIMEOUT_SEC);
55 SQLHDBC hdbc = session.dbc().handle();
56
57 auto identifier = getIdentifierQuote(hdbc);
58
59 WriteBufferFromHTTPServerResponse out(request, response, keep_alive_timeout);
60 writeStringBinary(identifier, out);
61 }
62 catch (...)
63 {
64 process_error("Error getting identifier quote style from ODBC '" + getCurrentExceptionMessage(false) + "'");
65 tryLogCurrentException(log);
66 }
67}
68}
69#endif
70