Skip to content

Commit

Permalink
[FIX] Columns with JDBC_TYPE_BIGINT is being returned as having DATA_…
Browse files Browse the repository at this point in the history
…TYPE -2 (BINARY) instead of -5 in SqlColumns (#44)

* ODBC was returing  the wrong data_type
type conversion from int8 to uint8 was causing the isse

* adding schema and table name in SQLCOLUMNS test

* changing int8 to int16
  • Loading branch information
affonsov authored Mar 10, 2022
1 parent 65aa42e commit 83507a4
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ lib64/*
*.tlog
include/*
packages/*
odbc_test_result.xml
# Visual Studio
.vs/*
src/.vs/*
Expand Down
149 changes: 149 additions & 0 deletions src/odbc-test/src/meta_queries_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "ignite/odbc/common/fixed_size_array.h"
#include "ignite/ignition.h"
#include "ignite/odbc/impl/binary/binary_utils.h"
#include "ignite/odbc/type_traits.h"
#include "odbc_test_suite.h"
#include "test_type.h"
#include "test_utils.h"
Expand Down Expand Up @@ -765,6 +766,154 @@ BOOST_AUTO_TEST_CASE(TestGetDataWithTablesReturnsOneWithTableTypes) {
CheckSingleRowResultSetWithGetData(stmt, 3, "meta_queries_test_001");
}

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

Connect(dsnConnectionString);

SQLCHAR table[] = "meta_queries_test_001";
SQLCHAR empty[] = "";
SQLCHAR *schemaName = (SQLCHAR *)databaseName.c_str();


SQLRETURN ret = SQLColumns(stmt, empty, SQL_NTS, schemaName, SQL_NTS, table,
SQL_NTS, empty, SQL_NTS);

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

char column_name[C_STR_LEN_DEFAULT]{};
SQLLEN column_name_len = sizeof(column_name);
SQLSMALLINT data_type = 0;
SQLLEN data_type_len = sizeof(data_type);
char type_name[C_STR_LEN_DEFAULT]{};
SQLLEN type_name_len = sizeof(type_name);

ret = SQLBindCol(stmt, 4, SQL_C_CHAR, column_name, C_STR_LEN_DEFAULT,
&column_name_len);
BOOST_CHECK(SQL_SUCCEEDED(ret));
ret = SQLBindCol(stmt, 5, SQL_SMALLINT, &data_type, sizeof(data_type),
&data_type_len);
BOOST_CHECK(SQL_SUCCEEDED(ret));
ret = SQLBindCol(stmt, 6, SQL_C_CHAR, type_name, C_STR_LEN_DEFAULT,
&type_name_len);
BOOST_CHECK(SQL_SUCCEEDED(ret));

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

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

using namespace ignite::odbc::type_traits;
BOOST_CHECK_EQUAL("meta_queries_test_001__id", column_name); // COLUMN_NAME
BOOST_CHECK_EQUAL(SQL_VARCHAR, data_type); // DATA_TYPE
BOOST_CHECK_EQUAL(SqlTypeName::VARCHAR, type_name); // TYPE_NAME

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

BOOST_CHECK_EQUAL("fieldDecimal128", column_name); // COLUMN_NAME
BOOST_CHECK_EQUAL(SQL_DECIMAL, data_type); // DATA_TYPE
BOOST_CHECK_EQUAL(SqlTypeName::DECIMAL, type_name); // TYPE_NAME

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

BOOST_CHECK_EQUAL("fieldDouble", column_name); // COLUMN_NAME
BOOST_CHECK_EQUAL(SQL_DOUBLE, data_type); // DATA_TYPE
BOOST_CHECK_EQUAL(SqlTypeName::DOUBLE, type_name); // TYPE_NAME

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

BOOST_CHECK_EQUAL("fieldString", column_name); // COLUMN_NAME
BOOST_CHECK_EQUAL(SQL_VARCHAR, data_type); // DATA_TYPE
BOOST_CHECK_EQUAL(SqlTypeName::VARCHAR, type_name); // TYPE_NAME

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

BOOST_CHECK_EQUAL("fieldObjectId", column_name); // COLUMN_NAME
BOOST_CHECK_EQUAL(SQL_VARCHAR, data_type); // DATA_TYPE
BOOST_CHECK_EQUAL(SqlTypeName::VARCHAR, type_name); // TYPE_NAME

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

BOOST_CHECK_EQUAL("fieldBoolean", column_name); // COLUMN_NAME
BOOST_CHECK_EQUAL(SQL_BIT, data_type); // DATA_TYPE
BOOST_CHECK_EQUAL(SqlTypeName::BIT, type_name); // TYPE_NAME

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

BOOST_CHECK_EQUAL("fieldDate", column_name); // COLUMN_NAME
BOOST_CHECK_EQUAL(SQL_TYPE_TIMESTAMP, data_type); // DATA_TYPE
BOOST_CHECK_EQUAL(SqlTypeName::TIMESTAMP, type_name); // TYPE_NAME

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

BOOST_CHECK_EQUAL("fieldInt", column_name); // COLUMN_NAME
BOOST_CHECK_EQUAL(SQL_INTEGER, data_type); // DATA_TYPE
BOOST_CHECK_EQUAL(SqlTypeName::INTEGER, type_name); // TYPE_NAME

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

BOOST_CHECK_EQUAL("fieldLong", column_name); // COLUMN_NAME
BOOST_CHECK_EQUAL(SQL_BIGINT, data_type); // DATA_TYPE
BOOST_CHECK_EQUAL(SqlTypeName::BIGINT, type_name); // TYPE_NAME

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

BOOST_CHECK_EQUAL("fieldMaxKey", column_name); // COLUMN_NAME
BOOST_CHECK_EQUAL(SQL_VARCHAR, data_type); // DATA_TYPE
BOOST_CHECK_EQUAL(SqlTypeName::VARCHAR, type_name); // TYPE_NAME

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

BOOST_CHECK_EQUAL("fieldMinKey", column_name); // COLUMN_NAME
BOOST_CHECK_EQUAL(SQL_VARCHAR, data_type); // DATA_TYPE
BOOST_CHECK_EQUAL(SqlTypeName::VARCHAR, type_name); // TYPE_NAME

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

BOOST_CHECK_EQUAL("fieldNull", column_name); // COLUMN_NAME
BOOST_CHECK_EQUAL(SQL_TYPE_NULL, data_type); // DATA_TYPE
BOOST_CHECK_EQUAL(SqlTypeName::SQL_NULL, type_name); // TYPE_NAME

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

BOOST_CHECK_EQUAL("fieldBinary", column_name); // COLUMN_NAME
BOOST_CHECK_EQUAL(SQL_VARBINARY, data_type); // DATA_TYPE
BOOST_CHECK_EQUAL(SqlTypeName::VARBINARY, type_name); // TYPE_NAME

ret = SQLFetch(stmt);

BOOST_REQUIRE_EQUAL(ret, SQL_NO_DATA);
}

BOOST_AUTO_TEST_CASE(TestGetDataWithTablesReturnsOneForQuotedTypes) {
SQLCHAR empty[] = "";
SQLCHAR table[] = "meta_queries_test_001";
Expand Down
2 changes: 1 addition & 1 deletion src/odbc/include/ignite/odbc/meta/column_meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class ColumnMeta {
* Get data type.
* @return Data type.
*/
int8_t GetDataType() const {
int16_t GetDataType() const {
return dataType;
}

Expand Down
3 changes: 3 additions & 0 deletions src/odbc/include/ignite/odbc/type_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ class SqlTypeName {
/** BINARY SQL type name constant. */
static const std::string BINARY;

/** VARBINARY SQL type name constant. */
static const std::string VARBINARY;

/** LONGVARBINARY SQL type name constant. */
static const std::string LONGVARBINARY;

Expand Down
4 changes: 2 additions & 2 deletions src/odbc/src/query/column_metadata_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ SqlResult::Type ColumnMetadataQuery::GetColumn(
}

const meta::ColumnMeta& currentColumn = *cursor;
uint8_t columnType = currentColumn.GetDataType();
int16_t columnType = currentColumn.GetDataType();

switch (columnIdx) {
case ResultColumn::TABLE_CAT: {
Expand Down Expand Up @@ -262,7 +262,7 @@ SqlResult::Type ColumnMetadataQuery::GetColumn(

case ResultColumn::TYPE_NAME: {
buffer.PutString(
type_traits::BinaryTypeToSqlTypeName(currentColumn.GetDataType()));
type_traits::BinaryTypeToSqlTypeName(columnType));
break;
}

Expand Down
12 changes: 9 additions & 3 deletions src/odbc/src/type_traits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ const std::string SqlTypeName::VARCHAR("VARCHAR");

const std::string SqlTypeName::LONGVARCHAR("LONGVARCHAR");

const std::string SqlTypeName::BINARY("VARBINARY");
const std::string SqlTypeName::BINARY("BINARY");

const std::string SqlTypeName::VARBINARY("VARBINARY");

const std::string SqlTypeName::LONGVARBINARY("LONGVARBINARY");

Expand Down Expand Up @@ -173,8 +175,10 @@ const std::string& BinaryTypeToSqlTypeName(int16_t binaryType) {
case JDBC_TYPE_NULL:
return SqlTypeName::SQL_NULL;

case JDBC_TYPE_BINARY:
case JDBC_TYPE_VARBINARY:
return SqlTypeName::VARBINARY;

case JDBC_TYPE_BINARY:
case JDBC_TYPE_BLOB:
case JDBC_TYPE_CLOB:
case JDBC_TYPE_ARRAY:
Expand Down Expand Up @@ -449,8 +453,10 @@ int16_t BinaryToSqlType(int16_t binaryType) {
case JDBC_TYPE_NULL:
return SQL_TYPE_NULL;

case JDBC_TYPE_BINARY:
case JDBC_TYPE_VARBINARY:
return SQL_VARBINARY;

case JDBC_TYPE_BINARY:
case JDBC_TYPE_BLOB:
case JDBC_TYPE_CLOB:
case JDBC_TYPE_ARRAY:
Expand Down

0 comments on commit 83507a4

Please sign in to comment.