Skip to content

Connection Session & Database Attributes#560

Open
sfc-gh-daniszewski wants to merge 2 commits into03-16-snow-3235549_implement_odbc_environment_attribute_handlingfrom
daniszewski-SNOW-3235550-connection-session-db-attrs
Open

Connection Session & Database Attributes#560
sfc-gh-daniszewski wants to merge 2 commits into03-16-snow-3235549_implement_odbc_environment_attribute_handlingfrom
daniszewski-SNOW-3235550-connection-session-db-attrs

Conversation

@sfc-gh-daniszewski
Copy link

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

TL;DR

Implemented comprehensive support for ODBC connection attributes including access mode, autocommit, transaction isolation, current catalog, connection status, and packet size settings.

What changed?

Added support for 9 new ODBC connection attributes:

  • SQL_ATTR_ACCESS_MODE - Read/write mode setting (advisory only)
  • SQL_ATTR_AUTOCOMMIT - Transaction autocommit behavior with session parameter integration
  • SQL_ATTR_TXN_ISOLATION - Transaction isolation level (returns READ_COMMITTED with warnings for unsupported levels)
  • SQL_ATTR_CURRENT_CATALOG - Database switching via USE DATABASE statements; server ANSI SQL state (e.g. 3D000) is now propagated through the error chain
  • SQL_ATTR_QUIET_MODE - Window handle pointer storage
  • SQL_ATTR_PACKET_SIZE - Network packet size (pre-connection only)
  • SQL_ATTR_CONNECTION_DEAD - Connection status indicator (read-only)
  • SQL_ATTR_AUTO_IPD - Automatic IPD population flag (read-only, returns FALSE)

Also fixed from_protobuf_error to forward the server's ANSI SQL state from DriverException.sql_state through the ODBC error chain, so server-originated errors (e.g. 3D000 for an invalid catalog name) surface with the correct SQLSTATE instead of being discarded.

How to test?

Run the new test suite odbc_api_conn_attr_tests which includes comprehensive test cases for:

  • Setting and getting each attribute in connected/disconnected states
  • Error handling for read-only attributes and invalid values
  • Warning generation for unsupported transaction isolation levels
  • Database switching functionality
  • Connection status detection

Why make this change?

These connection attributes are essential ODBC functionality required for compatibility with standard ODBC applications. Many database tools and frameworks rely on these attributes to configure connection behavior, manage transactions, and detect connection status.

Known limitations

Two spec requirements are intentionally deferred:

SQL_ATTR_CURRENT_CATALOG set — 24000 if a cursor is open (connection.rs)
Requires Connection to maintain a back-reference list of its child statement handles, which is a structural change (statements currently borrow Connection but not vice versa). Practically harmless: result data is already buffered in Arrow batches locally, so switching databases mid-fetch does not corrupt in-flight results.

SQL_ATTR_TXN_ISOLATION set — HY011 if a transaction is open (connection.rs)
Requires either a server round-trip (SELECT CURRENT_TRANSACTION()) or local transaction state tracking threaded through statement execution. Practically harmless: Snowflake only supports READ_COMMITTED and the set path never executes anything on the server, so the missing check has no behavioral impact.

Copy link
Author

sfc-gh-daniszewski commented Mar 17, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more


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.

@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
@sfc-gh-daniszewski sfc-gh-daniszewski force-pushed the daniszewski-SNOW-3235550-connection-session-db-attrs branch 2 times, most recently from 2750dce to f3f5675 Compare 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
@sfc-gh-daniszewski sfc-gh-daniszewski force-pushed the daniszewski-SNOW-3235550-connection-session-db-attrs branch from f3f5675 to d5e6e43 Compare March 18, 2026 15:33
@sfc-gh-daniszewski sfc-gh-daniszewski force-pushed the 03-16-snow-3235549_implement_odbc_environment_attribute_handling branch from 831fe72 to 498e484 Compare March 18, 2026 15:37
@sfc-gh-daniszewski sfc-gh-daniszewski force-pushed the daniszewski-SNOW-3235550-connection-session-db-attrs branch from d5e6e43 to 9a1004e Compare March 18, 2026 15:37
@sfc-gh-daniszewski sfc-gh-daniszewski force-pushed the 03-16-snow-3235549_implement_odbc_environment_attribute_handling branch from 498e484 to dd6c029 Compare March 18, 2026 16:37
@sfc-gh-daniszewski sfc-gh-daniszewski force-pushed the daniszewski-SNOW-3235550-connection-session-db-attrs branch 2 times, most recently from b4ebc87 to d49d039 Compare March 18, 2026 16:52
@sfc-gh-daniszewski sfc-gh-daniszewski marked this pull request as ready for review March 18, 2026 16:52
@sfc-gh-daniszewski sfc-gh-daniszewski requested a review from a team as a code owner March 18, 2026 16:52
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

Adds ODBC connection-attribute support in the Rust driver and introduces a new Catch2 test suite to validate common SQLSetConnectAttr / SQLGetConnectAttr behaviors, while also improving server-originated SQLSTATE propagation through the ODBC diagnostic chain.

Changes:

  • Implement support for multiple standard ODBC connection attributes (e.g., access mode, autocommit, txn isolation, current catalog, connection-dead, etc.) with warning/diagnostic integration.
  • Propagate server-provided ANSI SQLSTATE (e.g., 3D000) from protobuf errors into the driver’s ODBC error mapping.
  • Add a new ODBC API test binary (odbc_api_conn_attr_tests) covering several connection-attribute scenarios.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
odbc_tests/tests/odbc-api/connecting/conn_attr_tests.cpp New Catch2 tests for connection attributes (coverage gaps noted for catalog set + SQLSTATE propagation).
odbc_tests/tests/odbc-api/connecting/CMakeLists.txt Registers the new connection-attribute test binary.
odbc/src/c_api.rs Plumbs warning collection into SQLSetConnectAttr{A,W} return-code + diagnostics.
odbc/src/api/types.rs Extends ConnectionAttribute enum and Connection struct to store new attribute state.
odbc/src/api/sql_state.rs Adds 3D000 (InvalidCatalogName) to SQLSTATE parsing/formatting.
odbc/src/api/handle_allocation.rs Initializes new Connection fields (access_mode, quiet_mode, packet_size).
odbc/src/api/error.rs Boxes CoreProtobufError and forwards server sql_state into to_sql_state() mapping.
odbc/src/api/connection.rs Implements set/get logic for the new connection attributes + internal SQL execution helpers.

@sfc-gh-daniszewski sfc-gh-daniszewski force-pushed the 03-16-snow-3235549_implement_odbc_environment_attribute_handling branch from dd6c029 to 4ac6cf5 Compare March 19, 2026 15:18
@sfc-gh-daniszewski sfc-gh-daniszewski force-pushed the daniszewski-SNOW-3235550-connection-session-db-attrs branch 2 times, most recently from 5cbf171 to 4a90cfb Compare March 19, 2026 15:24
@sfc-gh-daniszewski sfc-gh-daniszewski force-pushed the 03-16-snow-3235549_implement_odbc_environment_attribute_handling branch 2 times, most recently from 24667a5 to d1fd932 Compare March 20, 2026 11:16
@sfc-gh-daniszewski sfc-gh-daniszewski force-pushed the daniszewski-SNOW-3235550-connection-session-db-attrs branch from 4a90cfb to 90c9a05 Compare March 20, 2026 11:16
@sfc-gh-daniszewski sfc-gh-daniszewski force-pushed the daniszewski-SNOW-3235550-connection-session-db-attrs branch from 90c9a05 to e3ef9a7 Compare March 23, 2026 11:11
@sfc-gh-daniszewski sfc-gh-daniszewski force-pushed the 03-16-snow-3235549_implement_odbc_environment_attribute_handling branch 2 times, most recently from ae96e2f to 1f6c812 Compare March 23, 2026 12:43
@sfc-gh-daniszewski sfc-gh-daniszewski force-pushed the daniszewski-SNOW-3235550-connection-session-db-attrs branch from e3ef9a7 to 5c10863 Compare March 23, 2026 12:43
@sfc-gh-daniszewski sfc-gh-daniszewski changed the base branch from 03-16-snow-3235549_implement_odbc_environment_attribute_handling to graphite-base/560 March 23, 2026 12:55
@sfc-gh-daniszewski sfc-gh-daniszewski force-pushed the daniszewski-SNOW-3235550-connection-session-db-attrs branch from 5c10863 to 0ebf730 Compare March 23, 2026 14:08
@sfc-gh-daniszewski sfc-gh-daniszewski changed the base branch from graphite-base/560 to 03-16-snow-3235549_implement_odbc_environment_attribute_handling March 23, 2026 14:08
@sfc-gh-daniszewski sfc-gh-daniszewski force-pushed the daniszewski-SNOW-3235550-connection-session-db-attrs branch from 0ebf730 to f701041 Compare March 23, 2026 16:14
@sfc-gh-daniszewski sfc-gh-daniszewski force-pushed the daniszewski-SNOW-3235550-connection-session-db-attrs branch from f701041 to df91a8a Compare March 23, 2026 16:40
…T_CATALOG SET

The Windows Driver Manager intercepts SQLSetConnectAttr for
SQL_ATTR_CURRENT_CATALOG and returns SQL_SUCCESS without calling the
driver, so the 3D000 error path is unreachable on Windows. Wrap the
test with #if !defined(_WIN32) following the same pattern used in
env_attr_tests.cpp for other direct-driver tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

2 participants