-
Couldn't load subscription status.
- Fork 3.9k
GH-46098 : [C++][FlightRPC] ODBC Environment Attribute Implementation #47760
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -253,16 +253,105 @@ SQLRETURN SQLGetEnvAttr(SQLHENV env, SQLINTEGER attr, SQLPOINTER value_ptr, | |
| ARROW_LOG(DEBUG) << "SQLGetEnvAttr called with env: " << env << ", attr: " << attr | ||
| << ", value_ptr: " << value_ptr << ", buffer_length: " << buffer_length | ||
| << ", str_len_ptr: " << static_cast<const void*>(str_len_ptr); | ||
| // GH-46575 TODO: Implement SQLGetEnvAttr | ||
| return SQL_INVALID_HANDLE; | ||
|
|
||
| using ODBC::ODBCEnvironment; | ||
|
|
||
| ODBCEnvironment* environment = reinterpret_cast<ODBCEnvironment*>(env); | ||
|
|
||
| return ODBCEnvironment::ExecuteWithDiagnostics(environment, SQL_ERROR, [=]() { | ||
| switch (attr) { | ||
| case SQL_ATTR_ODBC_VERSION: { | ||
| if (!value_ptr && !str_len_ptr) { | ||
| throw DriverException("Invalid null pointer for attribute.", "HY000"); | ||
| } | ||
|
Comment on lines
+264
to
+266
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test this case as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a test Potentially this can be tested on mac/linux depending on the driver manager on these systems
Comment on lines
+264
to
+266
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we check this out of this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably not in this case. I think attribute needs to be checked first before the pointers, and ODBC needs to error out on attribute value first. |
||
|
|
||
| if (value_ptr) { | ||
| SQLINTEGER* value = reinterpret_cast<SQLINTEGER*>(value_ptr); | ||
| *value = static_cast<SQLSMALLINT>(environment->GetODBCVersion()); | ||
| } | ||
|
|
||
| if (str_len_ptr) { | ||
| *str_len_ptr = sizeof(SQLINTEGER); | ||
| } | ||
|
|
||
| return SQL_SUCCESS; | ||
| } | ||
|
|
||
| case SQL_ATTR_OUTPUT_NTS: { | ||
| if (!value_ptr && !str_len_ptr) { | ||
| throw DriverException("Invalid null pointer for attribute.", "HY000"); | ||
| } | ||
|
|
||
| if (value_ptr) { | ||
| // output nts always returns SQL_TRUE | ||
| SQLINTEGER* value = reinterpret_cast<SQLINTEGER*>(value_ptr); | ||
| *value = SQL_TRUE; | ||
| } | ||
|
|
||
| if (str_len_ptr) { | ||
| *str_len_ptr = sizeof(SQLINTEGER); | ||
| } | ||
|
|
||
| return SQL_SUCCESS; | ||
| } | ||
|
|
||
| case SQL_ATTR_CONNECTION_POOLING: { | ||
| throw DriverException("Optional feature not supported.", "HYC00"); | ||
| } | ||
|
|
||
| default: { | ||
| throw DriverException("Invalid attribute", "HYC00"); | ||
| } | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| SQLRETURN SQLSetEnvAttr(SQLHENV env, SQLINTEGER attr, SQLPOINTER value_ptr, | ||
| SQLINTEGER str_len) { | ||
| ARROW_LOG(DEBUG) << "SQLSetEnvAttr called with env: " << env << ", attr: " << attr | ||
| << ", value_ptr: " << value_ptr << ", str_len: " << str_len; | ||
| // GH-46575 TODO: Implement SQLSetEnvAttr | ||
| return SQL_INVALID_HANDLE; | ||
|
|
||
| using ODBC::ODBCEnvironment; | ||
|
|
||
| ODBCEnvironment* environment = reinterpret_cast<ODBCEnvironment*>(env); | ||
|
|
||
| return ODBCEnvironment::ExecuteWithDiagnostics(environment, SQL_ERROR, [=]() { | ||
| if (!value_ptr) { | ||
| throw DriverException("Invalid null pointer for attribute.", "HY024"); | ||
| } | ||
|
|
||
| switch (attr) { | ||
| case SQL_ATTR_ODBC_VERSION: { | ||
| SQLINTEGER version = | ||
| static_cast<SQLINTEGER>(reinterpret_cast<intptr_t>(value_ptr)); | ||
| if (version == SQL_OV_ODBC2 || version == SQL_OV_ODBC3) { | ||
| environment->SetODBCVersion(version); | ||
|
|
||
| return SQL_SUCCESS; | ||
| } else { | ||
| throw DriverException("Invalid value for attribute", "HY024"); | ||
| } | ||
| } | ||
|
|
||
| case SQL_ATTR_OUTPUT_NTS: { | ||
| // output nts can not be set to SQL_FALSE, is always SQL_TRUE | ||
| SQLINTEGER value = static_cast<SQLINTEGER>(reinterpret_cast<intptr_t>(value_ptr)); | ||
| if (value == SQL_TRUE) { | ||
| return SQL_SUCCESS; | ||
| } else { | ||
| throw DriverException("Invalid value for attribute", "HY024"); | ||
| } | ||
| } | ||
|
|
||
| case SQL_ATTR_CONNECTION_POOLING: { | ||
| throw DriverException("Optional feature not supported.", "HYC00"); | ||
| } | ||
|
|
||
| default: { | ||
| throw DriverException("Invalid attribute", "HY092"); | ||
| } | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| SQLRETURN SQLGetConnectAttr(SQLHDBC conn, SQLINTEGER attribute, SQLPOINTER value_ptr, | ||
|
|
||
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 remove this debug print now?
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 generally log the ODBC API calls for debugging so we know which ODBC APIs got passed to the driver, is it ok to keep these logs?