2018-09-28 02:46:33 +00:00
|
|
|
#include "getIdentifierQuote.h"
|
|
|
|
|
2020-05-08 14:11:19 +00:00
|
|
|
#if USE_ODBC
|
|
|
|
|
|
|
|
# include <Poco/Data/ODBC/ODBCException.h>
|
|
|
|
# include <Poco/Data/ODBC/SessionImpl.h>
|
|
|
|
# include <Poco/Data/ODBC/Utility.h>
|
|
|
|
|
|
|
|
# define POCO_SQL_ODBC_CLASS Poco::Data::ODBC
|
2018-09-28 02:46:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2020-05-08 14:11:19 +00:00
|
|
|
|
2018-10-03 10:44:43 +00:00
|
|
|
std::string getIdentifierQuote(SQLHDBC hdbc)
|
|
|
|
{
|
|
|
|
std::string identifier;
|
2018-09-28 02:46:33 +00:00
|
|
|
|
2018-10-03 10:44:43 +00:00
|
|
|
SQLSMALLINT t;
|
2018-10-10 08:38:54 +00:00
|
|
|
SQLRETURN r = POCO_SQL_ODBC_CLASS::SQLGetInfo(hdbc, SQL_IDENTIFIER_QUOTE_CHAR, nullptr, 0, &t);
|
2018-09-28 02:46:33 +00:00
|
|
|
|
2018-10-03 10:44:43 +00:00
|
|
|
if (POCO_SQL_ODBC_CLASS::Utility::isError(r))
|
|
|
|
throw POCO_SQL_ODBC_CLASS::ConnectionException(hdbc);
|
2018-09-28 02:46:33 +00:00
|
|
|
|
2018-10-03 10:44:43 +00:00
|
|
|
if (t > 0)
|
|
|
|
{
|
2018-10-09 23:19:38 +00:00
|
|
|
// I have no idea, why to add '2' here, got from: contrib/poco/Data/ODBC/src/ODBCStatementImpl.cpp:60 (SQL_DRIVER_NAME)
|
2018-10-03 10:44:43 +00:00
|
|
|
identifier.resize(static_cast<std::size_t>(t) + 2);
|
2018-09-28 02:46:33 +00:00
|
|
|
|
2018-10-03 10:44:43 +00:00
|
|
|
if (POCO_SQL_ODBC_CLASS::Utility::isError(POCO_SQL_ODBC_CLASS::SQLGetInfo(
|
|
|
|
hdbc, SQL_IDENTIFIER_QUOTE_CHAR, &identifier[0], SQLSMALLINT((identifier.length() - 1) * sizeof(identifier[0])), &t)))
|
|
|
|
throw POCO_SQL_ODBC_CLASS::ConnectionException(hdbc);
|
2018-09-28 02:46:33 +00:00
|
|
|
|
2018-10-03 10:44:43 +00:00
|
|
|
identifier.resize(static_cast<std::size_t>(t));
|
2018-09-28 02:46:33 +00:00
|
|
|
}
|
2018-10-03 10:44:43 +00:00
|
|
|
return identifier;
|
2018-09-28 02:46:33 +00:00
|
|
|
}
|
2020-05-08 14:11:19 +00:00
|
|
|
|
2018-10-03 10:44:43 +00:00
|
|
|
}
|
2020-05-08 14:11:19 +00:00
|
|
|
|
2018-10-09 23:19:38 +00:00
|
|
|
#endif
|