ClickHouse/programs/odbc-bridge/getIdentifierQuote.cpp

42 lines
963 B
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 <nanodbc/nanodbc.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-03-22 11:40:29 +00:00
return connection.get_info<std::string>(SQL_IDENTIFIER_QUOTE_CHAR);
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