Skip to content

SNOW-3235549 Implement ODBC environment attribute handling#519

Open
sfc-gh-daniszewski wants to merge 1 commit intomainfrom
03-16-snow-3235549_implement_odbc_environment_attribute_handling
Open

SNOW-3235549 Implement ODBC environment attribute handling#519
sfc-gh-daniszewski wants to merge 1 commit intomainfrom
03-16-snow-3235549_implement_odbc_environment_attribute_handling

Conversation

@sfc-gh-daniszewski
Copy link

@sfc-gh-daniszewski sfc-gh-daniszewski commented Mar 16, 2026

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?

  • Added support for SQL_ATTR_CONNECTION_POOLING and SQL_ATTR_CP_MATCH environment attributes with proper get/set functionality
  • Implemented validation for SQL_ATTR_ODBC_VERSION values, rejecting invalid versions with appropriate error codes
  • Added SQL_ATTR_OUTPUT_NTS as a read-only attribute that returns SQL_TRUE
  • Enhanced error handling with new InvalidAttributeValue error type and proper SQLSTATE mapping
  • Updated environment structure to store new attribute values with sensible defaults
  • Added diagnostic information handling for environment attribute operations
  • Implemented proper StringLengthPtr handling in SQLGetEnvAttr for integer attributes
  • Added ODBC constants not exposed by the odbc-sys crate

How to test?

Run the new comprehensive test suite in odbc_tests/tests/odbc-api/environment/env_attr_tests.cpp which covers:

  • Setting and getting all supported environment attributes with valid values
  • Error handling for invalid attribute values and unknown attributes
  • Diagnostic record population and clearing
  • Direct driver testing (bypassing Driver Manager) to verify exact driver behavior
  • StringLengthPtr parameter handling

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.

Copilot AI review requested due to automatic review settings March 16, 2026 13:51
Copy link
Author

sfc-gh-daniszewski commented Mar 16, 2026


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge_queue - adds this PR to the back of the merge queue
  • priority_merge_queue - for urgent changes, fast-track this PR to the front of the merge queue

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 new HY024-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.

@sfc-gh-daniszewski sfc-gh-daniszewski force-pushed the 03-16-snow-3235549_implement_odbc_environment_attribute_handling branch from 0db5c3f to 7ad835c Compare March 16, 2026 14:01
Copilot AI review requested due to automatic review settings March 16, 2026 14:26
@sfc-gh-daniszewski sfc-gh-daniszewski force-pushed the 03-16-snow-3235549_implement_odbc_environment_attribute_handling branch from 7ad835c to 03fbb05 Compare March 16, 2026 14:26
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

@sfc-gh-daniszewski sfc-gh-daniszewski force-pushed the 03-16-snow-3235549_implement_odbc_environment_attribute_handling branch 2 times, most recently from c1b4421 to 1f7c5d4 Compare March 17, 2026 13:40
Copilot AI review requested due to automatic review settings March 17, 2026 13:40
@sfc-gh-daniszewski sfc-gh-daniszewski force-pushed the 03-16-snow-3235549_implement_odbc_environment_attribute_handling branch from 1f7c5d4 to e88390b Compare March 17, 2026 13:42
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 the Environment handle.
  • 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).

@sfc-gh-daniszewski sfc-gh-daniszewski marked this pull request as ready for review March 17, 2026 13:44
@sfc-gh-daniszewski sfc-gh-daniszewski requested a review from a team as a code owner March 17, 2026 13:45
@sfc-gh-daniszewski sfc-gh-daniszewski force-pushed the 03-16-snow-3235549_implement_odbc_environment_attribute_handling branch 3 times, most recently from a3c0331 to 553a569 Compare March 17, 2026 18:45
Copilot AI review requested due to automatic review settings March 17, 2026 18:45
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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/SQLGetEnvAttr on SQL_ATTR_ODBC_VERSION, SQL_ATTR_CONNECTION_POOLING, SQL_ATTR_CP_MATCH, and SQL_ATTR_OUTPUT_NTS, including HY024 validation for invalid ODBC version values.
  • Added environment-level diagnostics clearing/setting around env attribute calls, and StringLengthPtr writing for SQLGetEnvAttr.
  • Introduced a new C++ test target covering env attribute behavior (including direct-driver tests via dlopen on 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
sfc-gh-mhofman previously approved these changes Mar 18, 2026
Copy link
Collaborator

@sfc-gh-mhofman sfc-gh-mhofman left a comment

Choose a reason for hiding this comment

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

made some suggestions, check the comments but besides that looks fine

@sfc-gh-daniszewski sfc-gh-daniszewski force-pushed the 03-16-snow-3235549_implement_odbc_environment_attribute_handling branch from 553a569 to 49eaea3 Compare March 18, 2026 11:31
Copilot AI review requested due to automatic review settings March 18, 2026 15:05
@sfc-gh-daniszewski sfc-gh-daniszewski force-pushed the 03-16-snow-3235549_implement_odbc_environment_attribute_handling branch from 49eaea3 to c9e677c Compare March 18, 2026 15:05
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

@sfc-gh-daniszewski sfc-gh-daniszewski force-pushed the 03-16-snow-3235549_implement_odbc_environment_attribute_handling branch from 4ac6cf5 to 24667a5 Compare March 19, 2026 15:24
Copilot AI review requested due to automatic review settings March 20, 2026 11:16
@sfc-gh-daniszewski sfc-gh-daniszewski force-pushed the 03-16-snow-3235549_implement_odbc_environment_attribute_handling branch from 24667a5 to d1fd932 Compare March 20, 2026 11:16
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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, validated SQL_ATTR_ODBC_VERSION, and read-only SQL_ATTR_OUTPUT_NTS.
  • Added Snowflake statement attribute SQL_SF_STMT_ATTR_LAST_QUERY_ID and warning-driven truncation behavior for SQLGetStmtAttr.
  • 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.

@sfc-gh-daniszewski sfc-gh-daniszewski force-pushed the 03-16-snow-3235549_implement_odbc_environment_attribute_handling branch from d1fd932 to ae96e2f Compare March 23, 2026 11:11
Copilot AI review requested due to automatic review settings March 23, 2026 12:43
@sfc-gh-daniszewski sfc-gh-daniszewski force-pushed the 03-16-snow-3235549_implement_odbc_environment_attribute_handling branch from ae96e2f to 1f6c812 Compare March 23, 2026 12:43
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.

@sfc-gh-daniszewski sfc-gh-daniszewski force-pushed the 03-16-snow-3235549_implement_odbc_environment_attribute_handling branch from 1f6c812 to 0c94bcc Compare March 23, 2026 12:55
Copilot AI review requested due to automatic review settings March 23, 2026 13:24
@sfc-gh-daniszewski sfc-gh-daniszewski force-pushed the 03-16-snow-3235549_implement_odbc_environment_attribute_handling branch from 0c94bcc to d5f8172 Compare March 23, 2026 13:24
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated no new comments.

@sfc-gh-daniszewski sfc-gh-daniszewski force-pushed the 03-16-snow-3235549_implement_odbc_environment_attribute_handling branch from d5f8172 to dc14b58 Compare March 23, 2026 14:03
@sfc-gh-daniszewski sfc-gh-daniszewski dismissed sfc-gh-mhofman’s stale review March 23, 2026 14:46

It was many code-versions ago

Copy link
Collaborator

@sfc-gh-jszczerbinski sfc-gh-jszczerbinski left a comment

Choose a reason for hiding this comment

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

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,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be an enum

Copy link
Collaborator

Choose a reason for hiding this comment

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

Same for cp_match

@@ -0,0 +1,528 @@
#include <sql.h>
Copy link
Collaborator

Choose a reason for hiding this comment

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

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");
Copy link
Collaborator

Choose a reason for hiding this comment

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

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");
Copy link
Collaborator

Choose a reason for hiding this comment

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

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");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't use SKIP_OLD_DRIVER

Copy link
Collaborator

@sfc-gh-jszczerbinski sfc-gh-jszczerbinski left a comment

Choose a reason for hiding this comment

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

Approve by mistake, see previous comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants