-
Couldn't load subscription status.
- Fork 3.9k
GH-46575: [C++][FlightRPC] ODBC Diagnostics Report #47763
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
base: main
Are you sure you want to change the base?
Conversation
|
|
fe98d28 to
8d1b940
Compare
8d1b940 to
0c8fddc
Compare
|
@lidavidm @kou Please review this draft ODBC API PR. The test PR is at #47764.
|
| // 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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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]].)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
| 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; |
There was a problem hiding this comment.
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?
| diag_info_ptr && buffer_length >= 0 && buffer_length % char_size == 0; | |
| buffer_length >= 0 && buffer_length % char_size == 0; |
There was a problem hiding this comment.
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
0c8fddc to
c2a93f4
Compare
| // 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); |
There was a problem hiding this comment.
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]].)
Work on code review comments - remove `diag_info_ptr` from `IsValidStringFieldArgs` checks Co-Authored-By: rscales <[email protected]>
Addresses community comment: https://github.com/apache/arrow/pull/47763/files#r2450014186
c2a93f4 to
4a0fb9d
Compare
There was a problem hiding this 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); |
There was a problem hiding this comment.
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.
| 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, |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
Rationale for this change
ODBC needs to provide diagnostic information so users can debug the error
What changes are included in this PR?
Tests are included in separate PR (see GH-46575: [C++][FlightRPC] Add Diagnostic tests #47764)
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