Connection Session & Database Attributes#560
Conversation
|
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.
How to use the Graphite Merge QueueAdd either label to this PR to merge it via 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. |
553a569 to
49eaea3
Compare
2750dce to
f3f5675
Compare
49eaea3 to
c9e677c
Compare
f3f5675 to
d5e6e43
Compare
831fe72 to
498e484
Compare
d5e6e43 to
9a1004e
Compare
498e484 to
dd6c029
Compare
b4ebc87 to
d49d039
Compare
There was a problem hiding this comment.
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. |
dd6c029 to
4ac6cf5
Compare
5cbf171 to
4a90cfb
Compare
24667a5 to
d1fd932
Compare
4a90cfb to
90c9a05
Compare
90c9a05 to
e3ef9a7
Compare
ae96e2f to
1f6c812
Compare
e3ef9a7 to
5c10863
Compare
1f6c812 to
dc14b58
Compare
5c10863 to
0ebf730
Compare
0ebf730 to
f701041
Compare
f701041 to
df91a8a
Compare
…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>

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:
USE DATABASEstatements; server ANSI SQL state (e.g.3D000) is now propagated through the error chainAlso fixed
from_protobuf_errorto forward the server's ANSI SQL state fromDriverException.sql_statethrough the ODBC error chain, so server-originated errors (e.g.3D000for 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_testswhich includes comprehensive test cases for: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_CATALOGset — 24000 if a cursor is open (connection.rs)Requires
Connectionto maintain a back-reference list of its child statement handles, which is a structural change (statements currently borrowConnectionbut 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_ISOLATIONset — 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.