Skip to content

Commit

Permalink
[AD-634] [ODBC] PowerBI not showing up Tables on the Navigator (#39)
Browse files Browse the repository at this point in the history
### Summary

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

### Description

Handle table types in call to `SQLTables` as
* nullptr
* empty string
* single value
* comma-separated values
* quoted values

### Related Issue

https://bitquill.atlassian.net/browse/AD-634

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

* [AD-634] * Improve include location.

* [AD-634] * Simplify 'dequote' function to eliminate use of regex.

* [AD-634] * Correct spacing and formatting.
  • Loading branch information
Bruce Irschick authored Mar 7, 2022
1 parent d86e53a commit 6154e19
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 1 deletion.
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);

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
31 changes: 30 additions & 1 deletion src/odbc/src/query/table_metadata_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@

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

#include <regex>
#include <vector>

#include "ignite/odbc/impl/binary/binary_common.h"
#include "ignite/odbc/common/concurrent.h"
#include "ignite/odbc/connection.h"
#include "ignite/odbc/ignite_error.h"
#include "ignite/odbc/impl/binary/binary_common.h"
#include "ignite/odbc/jni/database_metadata.h"
#include "ignite/odbc/jni/result_set.h"
#include "ignite/odbc/log.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) {
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

0 comments on commit 6154e19

Please sign in to comment.