| 1 | #include "getIdentifierQuote.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 | |
| 18 | namespace DB |
| 19 | { |
| 20 | std::string getIdentifierQuote(SQLHDBC hdbc) |
| 21 | { |
| 22 | std::string identifier; |
| 23 | |
| 24 | SQLSMALLINT t; |
| 25 | SQLRETURN r = POCO_SQL_ODBC_CLASS::SQLGetInfo(hdbc, SQL_IDENTIFIER_QUOTE_CHAR, nullptr, 0, &t); |
| 26 | |
| 27 | if (POCO_SQL_ODBC_CLASS::Utility::isError(r)) |
| 28 | throw POCO_SQL_ODBC_CLASS::ConnectionException(hdbc); |
| 29 | |
| 30 | if (t > 0) |
| 31 | { |
| 32 | // I have no idea, why to add '2' here, got from: contrib/poco/Data/ODBC/src/ODBCStatementImpl.cpp:60 (SQL_DRIVER_NAME) |
| 33 | identifier.resize(static_cast<std::size_t>(t) + 2); |
| 34 | |
| 35 | if (POCO_SQL_ODBC_CLASS::Utility::isError(POCO_SQL_ODBC_CLASS::SQLGetInfo( |
| 36 | hdbc, SQL_IDENTIFIER_QUOTE_CHAR, &identifier[0], SQLSMALLINT((identifier.length() - 1) * sizeof(identifier[0])), &t))) |
| 37 | throw POCO_SQL_ODBC_CLASS::ConnectionException(hdbc); |
| 38 | |
| 39 | identifier.resize(static_cast<std::size_t>(t)); |
| 40 | } |
| 41 | return identifier; |
| 42 | } |
| 43 | } |
| 44 | #endif |
| 45 | |