Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AD-634] [ODBC] PowerBI not showing up Tables on the Navigator #39

Merged
merged 5 commits into from
Mar 7, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions src/odbc-test/src/meta_queries_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,66 @@ BOOST_AUTO_TEST_CASE(TestGetDataWithTablesReturnsOneFromLocalServer) {
CheckSingleRowResultSetWithGetData(stmt, 3, "meta_queries_test_001");
}

BOOST_AUTO_TEST_CASE(TestGetDataWithTablesReturnsOneWithTableTypes) {
SQLCHAR empty[] = "";
SQLCHAR table[] = "meta_queries_test_001";
SQLCHAR tableTypes[] = "TABLE,VIEW"; // Test that VIEW type is ignored by JDBC

std::string dsnConnectionString;
std::string databaseName("odbc-test");
CreateDsnConnectionStringForLocalServer(dsnConnectionString, databaseName);

Connect(dsnConnectionString);

SQLRETURN ret = SQLTables(stmt, empty, SQL_NTS, empty, SQL_NTS, table,
SQL_NTS, tableTypes, SQL_NTS);
alinaliBQ marked this conversation as resolved.
Show resolved Hide resolved

if (!SQL_SUCCEEDED(ret))
BOOST_FAIL(GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt));

CheckSingleRowResultSetWithGetData(stmt, 3, "meta_queries_test_001");
}

BOOST_AUTO_TEST_CASE(TestGetDataWithTablesReturnsOneForQuotedTypes) {
SQLCHAR empty[] = "";
SQLCHAR table[] = "meta_queries_test_001";
SQLCHAR tableTypes[] = "'TABLE' , 'VIEW'"; // Test that quoted values are handled

std::string dsnConnectionString;
std::string databaseName("odbc-test");
CreateDsnConnectionStringForLocalServer(dsnConnectionString, databaseName);

Connect(dsnConnectionString);

SQLRETURN ret = SQLTables(stmt, empty, SQL_NTS, empty, SQL_NTS, table,
SQL_NTS, tableTypes, SQL_NTS);

if (!SQL_SUCCEEDED(ret))
BOOST_FAIL(GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt));

CheckSingleRowResultSetWithGetData(stmt, 3, "meta_queries_test_001");
}

BOOST_AUTO_TEST_CASE(TestGetDataWithTablesReturnsNoneForUnsupportedTableType) {
SQLCHAR empty[] = "";
SQLCHAR table[] = "meta_queries_test_001";
SQLCHAR tableTypes[] = "VIEW";

std::string dsnConnectionString;
std::string databaseName("odbc-test");
CreateDsnConnectionStringForLocalServer(dsnConnectionString, databaseName);

Connect(dsnConnectionString);

SQLRETURN ret = SQLTables(stmt, empty, SQL_NTS, empty, SQL_NTS, table,
SQL_NTS, tableTypes, SQL_NTS);
if (!SQL_SUCCEEDED(ret))
BOOST_FAIL(GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt));

ret = SQLFetch(stmt);
BOOST_CHECK_EQUAL(SQL_NO_DATA, ret);
}

BOOST_AUTO_TEST_CASE(TestGetDataWithTablesReturnsNone) {
std::string dsnConnectionString;
CreateDsnConnectionString(dsnConnectionString);
Expand Down
29 changes: 29 additions & 0 deletions src/odbc/include/ignite/odbc/query/table_metadata_query.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,35 @@ class TableMetadataQuery : public Query {
*/
SqlResult::Type MakeRequestGetTablesMeta();

/**
* Trims leading space from a string.
*
* @return the string with leading spaces trimmed.
*/
std::string ltrim(const std::string& s);

/**
* Trims trailing space from a string.
*
* @return the string with trailing spaces trimmed.
*/
std::string rtrim(const std::string& s);

/**
* Trims leading and trailing space from a string.
*
* @return the string with leading and trailing spaces trimmed.
*/
std::string trim(const std::string& s);

/**
* Remove outer matching quotes from a string. They can be either single (') or double (") quotes.
* They must be the left- and right-most characters in the string.
*
* @return the string with matched quotes removed.
*/
std::string dequote(const std::string& s);

/** Connection associated with the statement. */
Connection& connection;

Expand Down
29 changes: 29 additions & 0 deletions src/odbc/src/query/table_metadata_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "ignite/odbc/query/table_metadata_query.h"

#include <regex>
#include <vector>

#include "ignite/odbc/impl/binary/binary_common.h"
Expand Down Expand Up @@ -231,7 +232,14 @@ SqlResult::Type TableMetadataQuery::MakeRequestGetTablesMeta() {
std::vector< std::string > types;
if (tableType.empty()) {
types.emplace_back("TABLE");
} else {
std::stringstream ss(tableType);
std::string singleTableType;
while (std::getline(ss, singleTableType, ',')) {
types.push_back(dequote(trim(singleTableType)));
}
}

JniErrorInfo errInfo;
SharedPointer< ResultSet > resultSet =
databaseMetaData.Get()->GetTables(catalog, schema, table, types, errInfo);
Expand All @@ -252,6 +260,27 @@ SqlResult::Type TableMetadataQuery::MakeRequestGetTablesMeta() {

return SqlResult::AI_SUCCESS;
}

std::string TableMetadataQuery::ltrim(const std::string& s) {
birschick-bq marked this conversation as resolved.
Show resolved Hide resolved
return std::regex_replace(s, std::regex("^\\s+"), std::string(""));
}

std::string TableMetadataQuery::rtrim(const std::string& s) {
return std::regex_replace(s, std::regex("\\s+$"), std::string(""));
}

std::string TableMetadataQuery::trim(const std::string& s) {
return ltrim(rtrim(s));
}

std::string TableMetadataQuery::dequote(const std::string& s) {
if (s.size() >= 2
&& ((s.front() == '\'' && s.back() == '\'')
|| (s.front() == '"' && s.back() == '"'))) {
return s.substr(1, s.size() - 2);
}
return s;
}
} // namespace query
} // namespace odbc
} // namespace ignite