Skip to content

Commit 8d35fd1

Browse files
rscalesalinaliBQ
authored andcommitted
Return nameLengthPtr value as length in characters
1 parent 76a9154 commit 8d35fd1

File tree

4 files changed

+24
-45
lines changed

4 files changed

+24
-45
lines changed

cpp/src/arrow/flight/sql/odbc/odbc_api.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1435,7 +1435,8 @@ SQLRETURN SQLDescribeCol(SQLHSTMT stmt, SQLUSMALLINT columnNumber, SQLWCHAR* col
14351435
ird->GetField(columnNumber, SQL_DESC_NAME, columnName, bufferLength,
14361436
&outputLengthInt);
14371437
if (nameLengthPtr) {
1438-
*nameLengthPtr = static_cast<SQLSMALLINT>(outputLengthInt);
1438+
// returned length should be in characters
1439+
*nameLengthPtr = static_cast<SQLSMALLINT>(outputLengthInt / GetSqlWCharSize());
14391440
}
14401441
}
14411442

cpp/src/arrow/flight/sql/odbc/tests/columns_test.cc

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2431,11 +2431,9 @@ TEST_F(FlightSQLODBCMockTestBase, SQLDescribeColQueryAllDataTypesMetadata) {
24312431

24322432
EXPECT_EQ(ret, SQL_SUCCESS);
24332433

2434-
EXPECT_GT(nameLength, 0);
2434+
EXPECT_EQ(nameLength, wcslen(columnNames[i]));
24352435

2436-
// Returned nameLength is in bytes so convert to length in characters
2437-
size_t charCount = static_cast<size_t>(nameLength) / ODBC::GetSqlWCharSize();
2438-
std::wstring returned(columnName, columnName + charCount);
2436+
std::wstring returned(columnName, columnName + nameLength);
24392437
EXPECT_EQ(returned, columnNames[i]);
24402438
EXPECT_EQ(columnDataType, columnDataTypes[i]);
24412439
EXPECT_EQ(columnSize, 1024);
@@ -2515,11 +2513,9 @@ TEST_F(FlightSQLODBCRemoteTestBase, SQLDescribeColQueryAllDataTypesMetadata) {
25152513

25162514
EXPECT_EQ(ret, SQL_SUCCESS);
25172515

2518-
EXPECT_GT(nameLength, 0);
2516+
EXPECT_EQ(nameLength, wcslen(columnNames[i]));
25192517

2520-
// Returned nameLength is in bytes so convert to length in characters
2521-
size_t charCount = static_cast<size_t>(nameLength) / ODBC::GetSqlWCharSize();
2522-
std::wstring returned(columnName, columnName + charCount);
2518+
std::wstring returned(columnName, columnName + nameLength);
25232519
EXPECT_EQ(returned, columnNames[i]);
25242520
EXPECT_EQ(columnDataType, columnDataTypes[i]);
25252521
EXPECT_EQ(columnSize, columnSizes[i]);
@@ -2579,11 +2575,9 @@ TEST_F(FlightSQLODBCRemoteTestBase, SQLDescribeColODBCTestTableMetadata) {
25792575

25802576
EXPECT_EQ(ret, SQL_SUCCESS);
25812577

2582-
EXPECT_GT(nameLength, 0);
2578+
EXPECT_EQ(nameLength, wcslen(columnNames[i]));
25832579

2584-
// Returned nameLength is in bytes so convert to length in characters
2585-
size_t charCount = static_cast<size_t>(nameLength) / ODBC::GetSqlWCharSize();
2586-
std::wstring returned(columnName, columnName + charCount);
2580+
std::wstring returned(columnName, columnName + nameLength);
25872581
EXPECT_EQ(returned, columnNames[i]);
25882582
EXPECT_EQ(columnDataType, columnDataTypes[i]);
25892583
EXPECT_EQ(columnSize, columnSizes[i]);
@@ -2643,11 +2637,9 @@ TEST_F(FlightSQLODBCRemoteTestBase, SQLDescribeColODBCTestTableMetadataODBC2) {
26432637

26442638
EXPECT_EQ(ret, SQL_SUCCESS);
26452639

2646-
EXPECT_GT(nameLength, 0);
2640+
EXPECT_EQ(nameLength, wcslen(columnNames[i]));
26472641

2648-
// Returned nameLength is in bytes so convert to length in characters
2649-
size_t charCount = static_cast<size_t>(nameLength) / ODBC::GetSqlWCharSize();
2650-
std::wstring returned(columnName, columnName + charCount);
2642+
std::wstring returned(columnName, columnName + nameLength);
26512643
EXPECT_EQ(returned, columnNames[i]);
26522644
EXPECT_EQ(columnDataType, columnDataTypes[i]);
26532645
EXPECT_EQ(columnSize, columnSizes[i]);
@@ -2701,11 +2693,9 @@ TEST_F(FlightSQLODBCMockTestBase, SQLDescribeColAllTypesTableMetadata) {
27012693

27022694
EXPECT_EQ(ret, SQL_SUCCESS);
27032695

2704-
EXPECT_GT(nameLength, 0);
2696+
EXPECT_EQ(nameLength, wcslen(columnNames[i]));
27052697

2706-
// Returned nameLength is in bytes so convert to length in characters
2707-
size_t charCount = static_cast<size_t>(nameLength) / ODBC::GetSqlWCharSize();
2708-
std::wstring returned(columnName, columnName + charCount);
2698+
std::wstring returned(columnName, columnName + nameLength);
27092699
EXPECT_EQ(returned, columnNames[i]);
27102700
EXPECT_EQ(columnDataType, columnDataTypes[i]);
27112701
EXPECT_EQ(columnSize, columnSizes[i]);
@@ -2755,11 +2745,9 @@ TEST_F(FlightSQLODBCMockTestBase, SQLDescribeColUnicodeTableMetadata) {
27552745

27562746
EXPECT_EQ(ret, SQL_SUCCESS);
27572747

2758-
EXPECT_GT(nameLength, 0);
2748+
EXPECT_EQ(nameLength, wcslen(expectedColumnName));
27592749

2760-
// Returned nameLength is in bytes so convert to length in characters
2761-
size_t charCount = static_cast<size_t>(nameLength) / ODBC::GetSqlWCharSize();
2762-
std::wstring returned(columnName, columnName + charCount);
2750+
std::wstring returned(columnName, columnName + nameLength);
27632751
EXPECT_EQ(returned, expectedColumnName);
27642752
EXPECT_EQ(columnDataType, expectedColumnDataType);
27652753
EXPECT_EQ(columnSize, expectedColumnSize);
@@ -2810,11 +2798,9 @@ TYPED_TEST(FlightSQLODBCTestBase, SQLColumnsGetMetadataBySQLDescribeCol) {
28102798

28112799
EXPECT_EQ(ret, SQL_SUCCESS);
28122800

2813-
EXPECT_GT(nameLength, 0);
2801+
EXPECT_EQ(nameLength, wcslen(columnNames[i]));
28142802

2815-
// Returned nameLength is in bytes so convert to length in characters
2816-
size_t charCount = static_cast<size_t>(nameLength) / ODBC::GetSqlWCharSize();
2817-
std::wstring returned(columnName, columnName + charCount);
2803+
std::wstring returned(columnName, columnName + nameLength);
28182804
EXPECT_EQ(returned, columnNames[i]);
28192805
EXPECT_EQ(columnDataType, columnDataTypes[i]);
28202806
EXPECT_EQ(columnSize, columnSizes[i]);
@@ -2880,11 +2866,9 @@ TYPED_TEST(FlightSQLODBCTestBase, SQLColumnsGetMetadataBySQLDescribeColODBC2) {
28802866

28812867
EXPECT_EQ(ret, SQL_SUCCESS);
28822868

2883-
EXPECT_GT(nameLength, 0);
2869+
EXPECT_EQ(nameLength, wcslen(columnNames[i]));
28842870

2885-
// Returned nameLength is in bytes so convert to length in characters
2886-
size_t charCount = static_cast<size_t>(nameLength) / ODBC::GetSqlWCharSize();
2887-
std::wstring returned(columnName, columnName + charCount);
2871+
std::wstring returned(columnName, columnName + nameLength);
28882872
EXPECT_EQ(returned, columnNames[i]);
28892873
EXPECT_EQ(columnDataType, columnDataTypes[i]);
28902874
EXPECT_EQ(columnSize, columnSizes[i]);

cpp/src/arrow/flight/sql/odbc/tests/tables_test.cc

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -607,11 +607,9 @@ TYPED_TEST(FlightSQLODBCTestBase, SQLTablesGetMetadataBySQLDescribeCol) {
607607

608608
EXPECT_EQ(ret, SQL_SUCCESS);
609609

610-
EXPECT_GT(nameLength, 0);
610+
EXPECT_EQ(nameLength, wcslen(columnNames[i]));
611611

612-
// Returned nameLength is in bytes so convert to length in characters
613-
size_t charCount = static_cast<size_t>(nameLength) / ODBC::GetSqlWCharSize();
614-
std::wstring returned(columnName, columnName + charCount);
612+
std::wstring returned(columnName, columnName + nameLength);
615613
EXPECT_EQ(returned, columnNames[i]);
616614
EXPECT_EQ(columnDataType, columnDataTypes[i]);
617615
EXPECT_EQ(columnSize, columnSizes[i]);
@@ -660,11 +658,9 @@ TYPED_TEST(FlightSQLODBCTestBase, SQLTablesGetMetadataBySQLDescribeColODBC2) {
660658

661659
EXPECT_EQ(ret, SQL_SUCCESS);
662660

663-
EXPECT_GT(nameLength, 0);
661+
EXPECT_EQ(nameLength, wcslen(columnNames[i]));
664662

665-
// Returned nameLength is in bytes so convert to length in characters
666-
size_t charCount = static_cast<size_t>(nameLength) / ODBC::GetSqlWCharSize();
667-
std::wstring returned(columnName, columnName + charCount);
663+
std::wstring returned(columnName, columnName + nameLength);
668664
EXPECT_EQ(returned, columnNames[i]);
669665
EXPECT_EQ(columnDataType, columnDataTypes[i]);
670666
EXPECT_EQ(columnSize, columnSizes[i]);

cpp/src/arrow/flight/sql/odbc/tests/type_info_test.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,9 @@ void checkSQLDescribeCol(SQLHSTMT stmt, const SQLUSMALLINT columnIndex,
4949

5050
EXPECT_EQ(ret, SQL_SUCCESS);
5151

52-
EXPECT_GT(nameLength, 0);
52+
EXPECT_EQ(nameLength, expectedName.size());
5353

54-
// returned nameLength is in bytes so convert to length in characters
55-
size_t charCount = static_cast<size_t>(nameLength) / ODBC::GetSqlWCharSize();
56-
std::wstring returned(columnName, columnName + charCount);
54+
std::wstring returned(columnName, columnName + nameLength);
5755
EXPECT_EQ(returned, expectedName);
5856
EXPECT_EQ(columnDataType, expectedDataType);
5957
EXPECT_EQ(columnSize, expectedColumnSize);

0 commit comments

Comments
 (0)