Skip to content

Conversation

@alinaliBQ
Copy link
Contributor

@alinaliBQ alinaliBQ commented Oct 8, 2025

Rationale for this change

ODBC needs to provide diagnostic information so users can debug the error

What changes are included in this PR?

Are these changes tested?

Tests will be in a separate PR (see #47764). Other APIs depend on SQLGetDiagField and SQLGetDiagRec to get error reporting functionality, and tests for SQLGetDiagField and SQLGetDiagRec depend on other APIs for creating errors, as these diagnostic APIs alone do not initiate any errors.

Changes tested locally

Are there any user-facing changes?

No

@alinaliBQ alinaliBQ changed the title GH-46096: [C++][FlightRPC] ODBC Diagnostics Report GH-46575: [C++][FlightRPC] ODBC Diagnostics Report Oct 8, 2025
@github-actions github-actions bot added the awaiting review Awaiting review label Oct 8, 2025
@github-actions
Copy link

github-actions bot commented Oct 8, 2025

⚠️ GitHub issue #46575 has been automatically assigned in GitHub to PR creator.

@alinaliBQ
Copy link
Contributor Author

alinaliBQ commented Oct 8, 2025

@lidavidm @kou Please review this draft ODBC API PR. The test PR is at #47764.

Tests will be in a separate PR (see #47764). Other APIs depend on SQLGetDiagField and SQLGetDiagRec to get error reporting functionality, and tests for SQLGetDiagField and SQLGetDiagRec depend on other APIs for creating errors, as these diagnostic APIs alone do not initiate any errors.

// The length of the sql state is always 5 characters plus null
SQLSMALLINT size = 6;
const std::string& state = diagnostics->GetSQLState(record_index);
GetStringAttribute(is_unicode, state, false, sql_state, size, &size, *diagnostics);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we not need to check the return value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to Microsoft documentation https://learn.microsoft.com/en-us/sql/odbc/reference/syntax/sqlgetdiagrec-function?view=sql-server-ver17#diagnostics, SQL_SUCCESS_WITH_INFO should be returned if *message_text buffer was too small to hold the requested diagnostic message. But the doc does not mention any SQLGetDiagRec return value that is associated with sql_state buffer, so the return value for writing sql_state buffer is ignored by the driver. I have added an in-line comment for this.

sql_state is meant to always contain a 5-character string, so error risk for writing it is low.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we be explicit with ARROW_UNUSED? (Also, not necessarily for this PR, but if SQLRETURN is meant to be an error code, perhaps functions returning it should be annotated [[nodiscard]].)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, added ARROW_UNUSED here.

Regarding [[nodiscard]], we can add it in this PR for ODBC API internal headers (odbc_api_internal.h).
On the other hand, since BI applications (and ODBC tests) will use the ODBC API definition headers at sql.h which doesn't have [[nodiscard]], I think we could skip adding [[nodiscard]] to entry_points.cc as it won't make any impact.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can split it out too. [[nodiscard]] isn't a hard requirement, just a potential suggestion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup. It's not a big change so we could do it

@github-actions github-actions bot added awaiting changes Awaiting changes and removed awaiting review Awaiting review labels Oct 9, 2025
SQLSMALLINT* string_length_ptr, bool is_unicode) {
const SQLSMALLINT char_size = is_unicode ? GetSqlWCharSize() : sizeof(char);
const bool has_valid_buffer =
diag_info_ptr && buffer_length >= 0 && buffer_length % char_size == 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need diag_info_ptr && here?

Suggested change
diag_info_ptr && buffer_length >= 0 && buffer_length % char_size == 0;
buffer_length >= 0 && buffer_length % char_size == 0;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, removed diag_info_ptr from has_valid_buffer

@alinaliBQ alinaliBQ force-pushed the gh-46575-odbc-diagnostics branch from 0c8fddc to c2a93f4 Compare October 21, 2025 21:43
@github-actions github-actions bot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Oct 21, 2025
// The length of the sql state is always 5 characters plus null
SQLSMALLINT size = 6;
const std::string& state = diagnostics->GetSQLState(record_index);
GetStringAttribute(is_unicode, state, false, sql_state, size, &size, *diagnostics);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we be explicit with ARROW_UNUSED? (Also, not necessarily for this PR, but if SQLRETURN is meant to be an error code, perhaps functions returning it should be annotated [[nodiscard]].)

@github-actions github-actions bot added awaiting merge Awaiting merge and removed awaiting change review Awaiting change review labels Oct 22, 2025
alinaliBQ and others added 3 commits October 22, 2025 13:40
Work on code review comments

- remove `diag_info_ptr` from `IsValidStringFieldArgs` checks

Co-Authored-By: rscales <[email protected]>
@alinaliBQ alinaliBQ force-pushed the gh-46575-odbc-diagnostics branch from c2a93f4 to 4a0fb9d Compare October 22, 2025 20:59
Copy link
Contributor Author

@alinaliBQ alinaliBQ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worked on review comment, thanks for reviewing!

// The length of the sql state is always 5 characters plus null
SQLSMALLINT size = 6;
const std::string& state = diagnostics->GetSQLState(record_index);
GetStringAttribute(is_unicode, state, false, sql_state, size, &size, *diagnostics);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, added ARROW_UNUSED here.

Regarding [[nodiscard]], we can add it in this PR for ODBC API internal headers (odbc_api_internal.h).
On the other hand, since BI applications (and ODBC tests) will use the ODBC API definition headers at sql.h which doesn't have [[nodiscard]], I think we could skip adding [[nodiscard]] to entry_points.cc as it won't make any impact.

@github-actions github-actions bot added awaiting changes Awaiting changes and removed awaiting merge Awaiting merge labels Oct 22, 2025
SQLSMALLINT buffer_length, SQLSMALLINT* name_length_ptr,
SQLSMALLINT* data_type_ptr, SQLULEN* column_size_ptr,
SQLSMALLINT* decimal_digits_ptr, SQLSMALLINT* nullable_ptr);
[[nodiscard]] SQLRETURN SQLAllocHandle(SQLSMALLINT type, SQLHANDLE parent,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added [[nodiscard]] here

// The length of the sql state is always 5 characters plus null
SQLSMALLINT size = 6;
const std::string& state = diagnostics->GetSQLState(record_index);
GetStringAttribute(is_unicode, state, false, sql_state, size, &size, *diagnostics);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup. It's not a big change so we could do it

@github-actions github-actions bot removed the awaiting changes Awaiting changes label Oct 24, 2025
@github-actions github-actions bot added the awaiting merge Awaiting merge label Oct 24, 2025
@alinaliBQ alinaliBQ marked this pull request as ready for review October 27, 2025 22:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants