ClickHouse/programs/odbc-bridge/getIdentifierQuote.cpp

52 lines
1.2 KiB
C++
Raw Normal View History

#include "getIdentifierQuote.h"
#if USE_ODBC
2021-03-22 11:40:29 +00:00
#include <common/logger_useful.h>
#include <sql.h>
#include <sqlext.h>
namespace DB
{
2021-03-24 12:32:58 +00:00
namespace ErrorCodes
{
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
}
2021-03-22 11:40:29 +00:00
std::string getIdentifierQuote(nanodbc::connection & connection)
2020-05-14 21:51:07 +00:00
{
2021-04-17 10:40:48 +00:00
std::string quote;
try
{
quote = connection.get_info<std::string>(SQL_IDENTIFIER_QUOTE_CHAR);
}
catch (...)
{
2021-04-17 15:16:26 +00:00
LOG_WARNING(&Poco::Logger::get("ODBCGetIdentifierQuote"), "Cannot fetch identifier quote. Default double quote is used. Reason: {}", getCurrentExceptionMessage(false));
2021-04-17 10:40:48 +00:00
return "\"";
}
return quote;
2020-05-14 21:51:07 +00:00
}
2021-03-22 11:40:29 +00:00
IdentifierQuotingStyle getQuotingStyle(nanodbc::connection & connection)
2020-05-14 21:51:07 +00:00
{
2021-03-22 11:40:29 +00:00
auto identifier_quote = getIdentifierQuote(connection);
2020-05-14 21:51:07 +00:00
if (identifier_quote.length() == 0)
return IdentifierQuotingStyle::None;
else if (identifier_quote[0] == '`')
return IdentifierQuotingStyle::Backticks;
else if (identifier_quote[0] == '"')
return IdentifierQuotingStyle::DoubleQuotes;
else
throw Exception("Can not map quote identifier '" + identifier_quote + "' to IdentifierQuotingStyle value", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
}
}
2018-10-09 23:19:38 +00:00
#endif