Skip to content

Conversation

alinaliBQ
Copy link
Contributor

@alinaliBQ alinaliBQ commented Oct 8, 2025

Rationale for this change

ODBC driver needs to set and get environment attributes, such as ODBC driver version.

What changes are included in this PR?

  • Implement SQLGetEnvAttr and SQLSetEnvAttr APIs for retrieving and setting environment attribute values
  • Tests

Are these changes tested?

  • Will be tested in CI when PR is ready for review

Are there any user-facing changes?

No

@alinaliBQ alinaliBQ force-pushed the gh-46098-sql-env-attr branch from 8d6f722 to 5da7b4f Compare October 8, 2025 19:56
@alinaliBQ
Copy link
Contributor Author

@lidavidm @kou Please review this draft ODBC API PR. The testing folder structure will be in a separate PR

namespace arrow::flight::sql::odbc {

TEST(SQLGetEnvAttr, TestSQLGetEnvAttrODBCVersion) {
// ODBC Environment
Copy link
Member

Choose a reason for hiding this comment

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

nit, but I don't think these comments add anything

Comment on lines +112 to +114
if (!value_ptr && !str_len_ptr) {
throw DriverException("Invalid null pointer for attribute.", "HY000");
}
Copy link
Member

Choose a reason for hiding this comment

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

Test this case as well?

@github-actions github-actions bot added awaiting changes Awaiting changes and removed awaiting review Awaiting review labels Oct 8, 2025
Comment on lines +19 to +21
#ifdef _WIN32
# include <windows.h>
#endif
Copy link
Member

Choose a reason for hiding this comment

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

Should we use cpp/src/arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/platform.h instead?

// Allocate an environment handle
SQLRETURN return_env = SQLAllocEnv(&env);

EXPECT_EQ(SQL_SUCCESS, return_env);
Copy link
Member

Choose a reason for hiding this comment

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

Should we use ASSERT_EQ() not EXPECT_EQ()?
Do we need to proceed this test even when this assertion is failed?

SQLRETURN return_set =
SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, reinterpret_cast<void*>(SQL_OV_ODBC2), 0);

EXPECT_EQ(SQL_SUCCESS, return_set);
Copy link
Member

Choose a reason for hiding this comment

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

Is SQL_SUCCESS expected?

Copy link
Member

Choose a reason for hiding this comment

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

Should we assert set value by SQLGetEnvAttr()?


EXPECT_EQ(SQL_SUCCESS, return_env);

// Attempt to set to unsupported version
Copy link
Member

Choose a reason for hiding this comment

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

Is this comment correct?

Comment on lines 100 to 102
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);
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 remove this debug print now?

Comment on lines +112 to +114
if (!value_ptr && !str_len_ptr) {
throw DriverException("Invalid null pointer for attribute.", "HY000");
}
Copy link
Member

Choose a reason for hiding this comment

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

Should we check this out of this switch?

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