SNOW-3235549 Implement ODBC environment attribute handling#519
SNOW-3235549 Implement ODBC environment attribute handling#519sfc-gh-daniszewski wants to merge 1 commit intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds end-to-end handling for ODBC environment attributes in the Rust driver layer and introduces a dedicated Catch2 test suite to validate set/get behavior and diagnostics for SQLSetEnvAttr / SQLGetEnvAttr.
Changes:
- Added new ODBC API tests covering env attribute set/get, invalid values, unknown attributes, and diagnostics clearing.
- Implemented environment attribute storage and handling (
ODBC_VERSION,CONNECTION_POOLING,CP_MATCH,OUTPUT_NTS) plus a newHY024-mapped error for invalid values. - Wired diagnostics lifecycle into the exported C API functions for environment attribute calls, and updated the C ABI signatures to include buffer/length parameters.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
odbc_tests/tests/odbc-api/environment/env_attr_tests.cpp |
New Catch2 coverage for env attributes and diagnostics behavior. |
odbc_tests/tests/odbc-api/environment/CMakeLists.txt |
Adds a new test target for the environment attribute suite. |
odbc_tests/tests/odbc-api/CMakeLists.txt |
Includes the new environment test subdirectory. |
odbc/src/c_api.rs |
Clears/sets diagnostics around env attr calls; updates exported signatures to match ODBC API parameters. |
odbc/src/api/types.rs |
Extends Environment to store additional env attributes. |
odbc/src/api/handle_allocation.rs |
Initializes default env attribute values on environment allocation. |
odbc/src/api/error.rs |
Adds InvalidAttributeValue and maps it to HY024. |
odbc/src/api/environment.rs |
Implements SQLSetEnvAttr / SQLGetEnvAttr logic for additional environment attributes. |
0db5c3f to
7ad835c
Compare
7ad835c to
03fbb05
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds ODBC environment attribute support to the driver and wires up a new Catch2 test suite to validate SQLSetEnvAttr / SQLGetEnvAttr behavior and diagnostics.
Changes:
- Implement handling and storage for environment attributes (
SQL_ATTR_CONNECTION_POOLING,SQL_ATTR_CP_MATCH,SQL_ATTR_OUTPUT_NTS) and validate values with appropriate SQLSTATEs. - Update the exported C ODBC entrypoints to clear/set diagnostic records for environment attribute calls and to use the correct parameter types.
- Add a new ODBC API environment test target and integrate it into the test CMake structure.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
odbc/src/c_api.rs |
Clears and populates diagnostics for SQLSetEnvAttr / SQLGetEnvAttr, and updates parameter types/signatures. |
odbc/src/api/types.rs |
Extends Environment handle state to store additional environment attribute values. |
odbc/src/api/handle_allocation.rs |
Initializes new Environment fields with defaults on handle allocation. |
odbc/src/api/error.rs |
Adds a new error variant for invalid attribute values and maps it to HY024. |
odbc/src/api/environment.rs |
Implements env-attribute set/get logic for version, pooling, CP match, and output NTS. |
odbc_tests/tests/odbc-api/environment/env_attr_tests.cpp |
New Catch2 suite covering env attribute set/get, invalid values, and diagnostics clearing. |
odbc_tests/tests/odbc-api/environment/CMakeLists.txt |
Adds the new environment attribute test target. |
odbc_tests/tests/odbc-api/CMakeLists.txt |
Registers the new environment/ subdirectory in the ODBC API test tree. |
c1b4421 to
1f7c5d4
Compare
1f7c5d4 to
e88390b
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds driver-level handling for additional ODBC environment attributes, wiring SQLSetEnvAttr/SQLGetEnvAttr through the Rust API layer with diagnostics support, and introduces a new ODBC API test suite for environment attributes.
Changes:
- Implemented get/set logic for additional environment attributes in
odbc/src/api/environment.rs, and stored their values in theEnvironmenthandle. - Updated the exported C API entrypoints to clear and populate diagnostics for env-attribute calls and to use the correct ODBC parameter types.
- Added a new Catch2 test target covering environment attributes (including a “direct driver” path that bypasses the driver manager), plus a demo program source.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
odbc_tests/tests/odbc-api/environment/env_attr_tests.cpp |
Adds environment attribute tests, including driver-manager behavior expectations and direct-driver (dlopen) checks. |
odbc_tests/tests/odbc-api/environment/CMakeLists.txt |
Defines the new odbc_api_env_attr_tests test target. |
odbc_tests/tests/odbc-api/CMakeLists.txt |
Registers the new environment test subdirectory. |
odbc/src/c_api.rs |
Updates SQLSetEnvAttr/SQLGetEnvAttr signatures and adds diagnostic clear/set for env-attribute calls. |
odbc/src/api/types.rs |
Extends Environment handle storage with pooling, CP match, and output NTS fields. |
odbc/src/api/handle_allocation.rs |
Initializes new Environment fields with defaults during handle allocation. |
odbc/src/api/error.rs |
Adds InvalidAttributeValue error variant and maps it to HY024. |
odbc/src/api/environment.rs |
Implements env attribute routing and value handling for the supported attributes. |
demo_env_attrs.c |
Adds a small demo program exercising env attribute APIs and diagnostics. |
demo_env_attrs |
Adds a compiled executable artifact (should not be committed). |
a3c0331 to
553a569
Compare
There was a problem hiding this comment.
Pull request overview
Implements ODBC environment attribute handling in the Rust driver (get/set + diagnostics) and adds a new Catch2 test suite to validate behavior both through the Driver Manager and by calling the driver directly.
Changes:
- Added driver-side support for
SQLSetEnvAttr/SQLGetEnvAttronSQL_ATTR_ODBC_VERSION,SQL_ATTR_CONNECTION_POOLING,SQL_ATTR_CP_MATCH, andSQL_ATTR_OUTPUT_NTS, includingHY024validation for invalid ODBC version values. - Added environment-level diagnostics clearing/setting around env attribute calls, and
StringLengthPtrwriting forSQLGetEnvAttr. - Introduced a new C++ test target covering env attribute behavior (including direct-driver tests via
dlopenon POSIX).
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
odbc/src/c_api.rs |
Wraps env-attr entrypoints with diagnostic clearing + result-to-diag mapping; updates signatures to include length parameters. |
odbc/src/api/environment.rs |
Implements env attribute storage + get/set behavior and StringLengthPtr handling. |
odbc/src/api/types.rs |
Extends Environment struct to store new attribute values. |
odbc/src/api/handle_allocation.rs |
Initializes new Environment fields with defaults during allocation. |
odbc/src/api/error.rs |
Adds InvalidAttributeValue error variant and maps it to HY024. |
odbc_tests/tests/odbc-api/environment/env_attr_tests.cpp |
Adds comprehensive Catch2 tests for env attributes, diagnostics, and direct driver behavior. |
odbc_tests/tests/odbc-api/environment/CMakeLists.txt |
Adds new env-attr test target. |
odbc_tests/tests/odbc-api/CMakeLists.txt |
Registers the new environment test subdirectory. |
sfc-gh-mhofman
left a comment
There was a problem hiding this comment.
made some suggestions, check the comments but besides that looks fine
553a569 to
49eaea3
Compare
49eaea3 to
c9e677c
Compare
498e484 to
dd6c029
Compare
dd6c029 to
4ac6cf5
Compare
There was a problem hiding this comment.
Pull request overview
This PR extends the driver’s ODBC environment attribute support by wiring SQLSetEnvAttr/SQLGetEnvAttr through the diagnostic system, persisting additional environment attributes on the Environment handle, and adding a dedicated Catch2 test suite (including direct-driver tests that bypass the Driver Manager on POSIX).
Changes:
- Implemented get/set handling for key env attributes (
SQL_ATTR_ODBC_VERSION,SQL_ATTR_CONNECTION_POOLING,SQL_ATTR_CP_MATCH,SQL_ATTR_OUTPUT_NTS) plus validation and SQLSTATE mapping for invalid ODBC version values. - Added environment-handle fields/defaults for new attributes and introduced new error variants for better diagnostics/SQLSTATE mapping.
- Added/registered new ODBC API environment attribute tests and updated CMake to support direct-driver (
dlopen) tests on non-Windows platforms.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
odbc_tests/tests/odbc-api/environment/env_attr_tests.cpp |
New Catch2 coverage for env attribute get/set, diagnostics, and direct-driver behavior on POSIX. |
odbc_tests/tests/odbc-api/environment/CMakeLists.txt |
Adds the new env attribute test target. |
odbc_tests/tests/odbc-api/CMakeLists.txt |
Registers the new environment/ test subdirectory. |
odbc_tests/tests/e2e/CMakeLists.txt |
Adds a new e2e test target entry (currently references a missing source file). |
odbc_tests/CMakeLists.txt |
Links ${CMAKE_DL_LIBS} on non-Windows to support dlopen usage in tests. |
odbc/src/c_api.rs |
Updates SQLSetEnvAttr/SQLGetEnvAttr signatures and routes calls through diag clear/set with invalid-handle guarding. |
odbc/src/api/types/odbc_types.rs |
Extends Environment struct to store new env attribute values. |
odbc/src/api/handle_allocation.rs |
Initializes new Environment fields with defaults at allocation time. |
odbc/src/api/error.rs |
Adds ReadOnlyAttribute / InvalidAttributeValue errors and maps them to SQLSTATEs. |
odbc/src/api/environment.rs |
Implements env attribute set/get logic, including ODBC version validation and StringLengthPtr handling. |
4ac6cf5 to
24667a5
Compare
24667a5 to
d1fd932
Compare
There was a problem hiding this comment.
Pull request overview
Implements additional ODBC environment-attribute support and improves attribute-related diagnostics/warnings, along with new ODBC API and E2E tests to validate spec-compliant error handling and truncation behavior.
Changes:
- Added env-attr get/set handling for
SQL_ATTR_CONNECTION_POOLING,SQL_ATTR_CP_MATCH, validatedSQL_ATTR_ODBC_VERSION, and read-onlySQL_ATTR_OUTPUT_NTS. - Added Snowflake statement attribute
SQL_SF_STMT_ATTR_LAST_QUERY_IDand warning-driven truncation behavior forSQLGetStmtAttr. - Introduced new Catch2 test targets (ODBC API + E2E) and wiring in CMake/feature definitions.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
tests/definitions/odbc/query/attr_error_handling.feature |
Adds feature coverage for buffer-length and truncation error semantics. |
odbc_tests/tests/odbc-api/environment/env_attr_tests.cpp |
New ODBC API tests for env attributes, diagnostics, and direct-driver behavior (POSIX). |
odbc_tests/tests/odbc-api/environment/CMakeLists.txt |
Adds new env-attr ODBC API test target. |
odbc_tests/tests/odbc-api/CMakeLists.txt |
Includes the new environment/ test subtree. |
odbc_tests/tests/e2e/query/attr_error_handling.cpp |
Adds E2E regression tests for HY090 and 01004 behaviors. |
odbc_tests/tests/e2e/CMakeLists.txt |
Registers the new E2E test target. |
odbc_tests/CMakeLists.txt |
Links CMAKE_DL_LIBS on non-Windows for direct-driver tests. |
odbc/src/c_api.rs |
Adds env-attr diagnostics clearing/setting and warning-aware SQLGetStmtAttr* plumbing. |
odbc/src/api/types/odbc_types.rs |
Adds new connection/statement attrs and stores env/stmt state needed for them. |
odbc/src/api/statement.rs |
Captures last query ID and exposes it via new statement attribute; adds negative-length validation + truncation warnings. |
odbc/src/api/handle_allocation.rs |
Initializes new environment fields and statement last_query_id. |
odbc/src/api/error.rs |
Adds ReadOnlyAttribute and InvalidAttributeValue error variants and SQLSTATE mapping. |
odbc/src/api/environment.rs |
Implements env-attr get/set for version/pooling/cp-match/output-nts and StringLengthPtr behavior. |
odbc/src/api/connection.rs |
Adds SQL_ATTR_CURRENT_CATALOG handling and negative buffer-length validation for string attrs. |
odbc/include/sf_odbc.h |
Exposes Snowflake-specific statement attribute IDs for consumers/tests. |
d1fd932 to
ae96e2f
Compare
ae96e2f to
1f6c812
Compare
1f6c812 to
0c94bcc
Compare
0c94bcc to
d5f8172
Compare
d5f8172 to
dc14b58
Compare
It was many code-versions ago
sfc-gh-jszczerbinski
left a comment
There was a problem hiding this comment.
Most of the the parameters (if not all) seem to be handled by driver manager. Big question for me is that do we even need this implementation? And to what extent?
|
|
||
| pub struct Environment { | ||
| pub odbc_version: sql::Integer, | ||
| pub connection_pooling: sql::UInteger, |
There was a problem hiding this comment.
This should be an enum
There was a problem hiding this comment.
Same for cp_match
| @@ -0,0 +1,528 @@ | |||
| #include <sql.h> | |||
There was a problem hiding this comment.
None of those tests are calling our driver since DM loads them when first connection is initiated.
| } | ||
|
|
||
| TEST_CASE("SQLGetStmtAttr string attribute truncation returns SQL_SUCCESS_WITH_INFO.") { | ||
| SKIP_OLD_DRIVER("SNOW-3235549", "String truncation warning is new driver only"); |
There was a problem hiding this comment.
Don't use SKIP_OLD_DRIVER, create behavior difference and make sure that we assert on both behaviors
| #include "sf_odbc.h" | ||
|
|
||
| TEST_CASE("SQLGetStmtAttr with negative buffer length returns HY090.") { | ||
| SKIP_OLD_DRIVER("SNOW-3235549", "Negative buffer length validation is new driver only"); |
There was a problem hiding this comment.
Don't use SKIP_OLD_DRIVER here
| } | ||
|
|
||
| TEST_CASE("SQLGetConnectAttr with negative buffer length returns HY090.") { | ||
| SKIP_OLD_DRIVER("SNOW-3235549", "Negative buffer length validation is new driver only"); |
There was a problem hiding this comment.
Don't use SKIP_OLD_DRIVER

TL;DR
Enhanced ODBC environment attribute handling by implementing support for connection pooling and CP match attributes, adding proper validation and error handling, and including comprehensive test coverage.
What changed?
SQL_ATTR_CONNECTION_POOLINGandSQL_ATTR_CP_MATCHenvironment attributes with proper get/set functionalitySQL_ATTR_ODBC_VERSIONvalues, rejecting invalid versions with appropriate error codesSQL_ATTR_OUTPUT_NTSas a read-only attribute that returnsSQL_TRUEInvalidAttributeValueerror type and proper SQLSTATE mappingStringLengthPtrhandling inSQLGetEnvAttrfor integer attributesodbc-syscrateHow to test?
Run the new comprehensive test suite in
odbc_tests/tests/odbc-api/environment/env_attr_tests.cppwhich covers:Why make this change?
This change improves ODBC compliance by properly implementing environment attribute management according to the ODBC specification. The enhanced validation prevents invalid configurations, while comprehensive error handling provides better debugging information. The addition of connection pooling attributes prepares the driver for future pooling implementations, and the extensive test coverage ensures reliability and prevents regressions.