ClickHouse/programs/odbc-bridge/getIdentifierQuote.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

54 lines
1.3 KiB
C++
Raw Normal View History

#include "getIdentifierQuote.h"
#if USE_ODBC
2022-04-27 15:05:45 +00:00
#include <Common/logger_useful.h>
2021-03-22 11:40:29 +00:00
#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-06-07 18:09:16 +00:00
std::string getIdentifierQuote(nanodbc::ConnectionHolderPtr connection_holder)
2020-05-14 21:51:07 +00:00
{
2021-04-17 10:40:48 +00:00
std::string quote;
try
{
2021-06-07 18:09:16 +00:00
quote = execute<std::string>(connection_holder,
[&](nanodbc::connection & connection) { return connection.get_info<std::string>(SQL_IDENTIFIER_QUOTE_CHAR); });
2021-04-17 10:40:48 +00:00
}
catch (...)
{
2024-01-23 17:04:50 +00:00
LOG_WARNING(getLogger("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-06-07 18:09:16 +00:00
IdentifierQuotingStyle getQuotingStyle(nanodbc::ConnectionHolderPtr connection)
2020-05-14 21:51:07 +00:00
{
2021-03-22 11:40:29 +00:00
auto identifier_quote = getIdentifierQuote(connection);
2024-05-09 01:58:34 +00:00
if (identifier_quote.empty())
2024-09-25 03:28:38 +00:00
return IdentifierQuotingStyle::Backticks;
2020-05-14 21:51:07 +00:00
if (identifier_quote[0] == '`')
return IdentifierQuotingStyle::Backticks;
if (identifier_quote[0] == '"')
return IdentifierQuotingStyle::DoubleQuotes;
2024-09-19 11:51:02 +00:00
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
"Can not map quote identifier '{}' to IdentifierQuotingStyle value", identifier_quote);
2020-05-14 21:51:07 +00:00
}
}
2018-10-09 23:19:38 +00:00
#endif