Skip to content

feat: Connection::is_autocommit - #960

Merged
pacman82 merged 1 commit into
pacman82:mainfrom
alfhellmund:feat/is-autocommit-transaction-capable
Nov 8, 2026
Merged

pacman82 merged 1 commit into
pacman82:mainfrom
alfhellmund:feat/is-autocommit-transaction-capable

Conversation

@alfhellmund

@alfhellmund alfhellmund commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Adds Connection::is_autocommit, which reads SQL_ATTR_AUTOCOMMIT via SQLGetConnectAttr, as discussed in #959.

Following your review, this PR now covers only the autocommit accessor. Reading SQL_TXN_CAPABLE follows in a separate PR once TransactionCapable is available as a strict alias in odbc-sys (pacman82/odbc-sys#112).

The integration tests cover all four drivers under test, split into one test for the default (true) and one after set_autocommit(false) (false).

One observation that may save you a debugging session: MariaDB Connector/ODBC 3.2.x (e.g. 3.2.10 from Homebrew) reports a stale SQL_ATTR_AUTOCOMMIT right after SQLSetConnectAttr — it still returns 1 until the next statement has been executed. The 3.2 driver reads the value from a cached server status (driver/ma_connection.cpp, getAutocommit() → mariadb-connector-cpp Protocol::getAutocommit, refreshed only in getServerStatus()), while 3.1.x returns the value set by the application. The CI image ships 3.1.15, so the test passes there. I didn't find a matching MariaDB JIRA issue.

Part of #959

🤖 Generated with Claude Code

Comment thread odbc-api/src/handles/connection.rs Outdated
0 => false,
1 => true,
other => panic!("Unexpected result value from SQLGetConnectAttr: {other}"),
other => panic!("Unexpected result value from SQLGetConnectAttr SQL_ATTR_AUTOCOMMIT: {other}"),

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Not necessary to annotate the attribute. Yet, if we do it it should be correct. This one is getting CONNECTION_DEAD.

If we name it, maybe we can improve on the sentence, rather than just adding it. E.g. "Unexpected result value retrieving SQL_ATTR_AUTOCOMMIT via SQLGetConnectAttr.

Comment thread odbc-api/tests/integration/main.rs Outdated
#[test_case(MARIADB; "Maria DB")]
#[test_case(SQLITE_3; "SQLite 3")]
#[test_case(POSTGRES; "PostgreSQL")]
fn is_autocommit(profile: &Profile) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Please split this in two tests. One for true and and for false.

Comment thread odbc-api/tests/integration/main.rs Outdated
fn transaction_capable(profile: &Profile) {
let conn = profile.connection().unwrap();
assert_ne!(
TransactionCapable::None,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Please change assertion to what is returned as opposed to what is not

You can use a second argument to control different test expectations for the various databases.

/// See:
/// <https://learn.microsoft.com/en-us/sql/odbc/reference/syntax/sqlgetinfo-function>
#[derive(Clone, Copy, Hash, Debug, Eq, PartialEq)]
pub enum TransactionCapable {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I would prefer this to be strict alias over u16 and defined in odbc-sys instead of odbc-api.

odbc-sys owns the definition of the ODBC interface. This is analogous to ConnectionAttribute which you already used for fetching autocommit information.

@pacman82

pacman82 commented Nov 6, 2026

Copy link
Copy Markdown
Owner

Thanks for the contribution. Sorry for the long feedback cycles, I am currently don't have enough spare time to be as responsive to OS contributions as I would like to be.

It's often better to split separate features in different commits and PRs. This way unresolved issues in one do not block progress on the other.

I'll leave it to up to you, whether you want to introduce an additional TransactionCapable enum after the strict alias in odbc-sys lands.

@alfhellmund alfhellmund changed the title feat: Connection::is_autocommit and Connection::transaction_capable feat: Connection::is_autocommit Nov 7, 2026
@alfhellmund

Copy link
Copy Markdown
Contributor Author

Thanks for the review, and no worries about the timing.

I followed your suggestion and split it up:

On the inline comments:

  • The panic messages now name the attribute that is actually read: SQL_ATTR_CONNECTION_DEAD in is_dead and SQL_ATTR_AUTOCOMMIT in is_autocommit, using your wording.
  • The autocommit test is split into one test for true and one for false.
  • The assertion on the returned value, with a second test-case argument for the expected value per database, applies to the transaction_capable test and moves with it into the follow-up PR. There the expectation differs per driver (e.g. MariaDB Connector/ODBC reports SQL_TC_DDL_COMMIT), so the second argument is needed.

@pacman82
pacman82 enabled auto-merge (rebase) November 8, 2026 10:22
@pacman82
pacman82 disabled auto-merge November 8, 2026 13:32
Adds two read accessors to `Connection`, as discussed in pacman82#959:

- `is_autocommit()` reads `SQL_ATTR_AUTOCOMMIT` via `SQLGetConnectAttr`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pacman82
pacman82 force-pushed the feat/is-autocommit-transaction-capable branch from 4f48b62 to d9ce608 Compare November 8, 2026 13:48
@pacman82
pacman82 enabled auto-merge (rebase) November 8, 2026 13:49
@pacman82
pacman82 merged commit 21f9e25 into pacman82:main Nov 8, 2026
10 checks passed
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