Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion odbc-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ prompt = ["dep:winit"]

[dependencies]
# Low level bindings to ODBC API calls into libodbc.so
odbc-sys = { version = "0.31.2", default-features = false, features = ["odbc_version_3_50"] }
odbc-sys = { version = "0.31.3", default-features = false, features = ["odbc_version_3_50"] }
# Used to generate code for the error type
thiserror = "2.0.18"
# Used as a log frontend to emit log messages for applications
Expand Down
11 changes: 11 additions & 0 deletions odbc-api/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::{
self, KeepConnectionOpen, SqlText, State, Statement, StatementConnection, StatementImpl,
slice_to_utf8,
},
sys::TransactionCapable,
};
use log::error;
use std::{
Expand Down Expand Up @@ -488,6 +489,16 @@ impl<'env> Connection<'env> {
.into_result(&self.connection)
}

/// Level of transaction support offered by the data source. See
/// [`crate::sys::TransactionCapable`] for the possible values.
///
/// This corresponds to the `SQL_TXN_CAPABLE` information type in the ODBC specification.
pub fn transaction_capable(&self) -> Result<TransactionCapable, Error> {
self.connection
.transaction_capable()
.into_result(&self.connection)
}

/// To commit a transaction in manual-commit mode.
pub fn commit(&self) -> Result<(), Error> {
self.connection.commit().into_result(&self.connection)
Expand Down
8 changes: 7 additions & 1 deletion odbc-api/src/handles/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use super::{
use log::trace;
use odbc_sys::{
CompletionType, ConnectionAttribute, DriverConnectOption, HDbc, HEnv, HWnd, Handle, HandleType,
IS_UINTEGER, InfoType, Pointer, SQLAllocHandle, SQLDisconnect, SQLEndTran,
IS_UINTEGER, InfoType, Pointer, SQLAllocHandle, SQLDisconnect, SQLEndTran, TransactionCapable,
};
use std::{cmp::max, ffi::c_void, marker::PhantomData, mem::size_of, ptr::null_mut};

Expand Down Expand Up @@ -347,6 +347,12 @@ impl Connection<'_> {
self.info_u16(InfoType::MaxColumnNameLen)
}

/// Level of transaction support of the data source. Corresponds to `SQL_TXN_CAPABLE`.
pub fn transaction_capable(&self) -> SqlResult<TransactionCapable> {
self.info_u16(InfoType::TransactionCapable)
.map(TransactionCapable)
}

/// Fetch the name of the current catalog being used by the connection and store it into the
/// provided `buf`.
pub fn fetch_current_catalog(&self, buffer: &mut Vec<SqlChar>) -> SqlResult<()> {
Expand Down
12 changes: 11 additions & 1 deletion odbc-api/tests/integration/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use odbc_api::{
},
sys::{
CDataType, FetchOrientation, HandleType, Numeric, Pointer, SQLFreeHandle, SQLPrepareW,
SqlDataType, SqlReturn, SsAccessToken, Timestamp,
SqlDataType, SqlReturn, SsAccessToken, Timestamp, TransactionCapable,
},
};

Expand Down Expand Up @@ -1940,6 +1940,16 @@ fn is_autocommit_is_false_after_disabling_autocommit(profile: &Profile) {
assert!(!conn.is_autocommit().unwrap());
}

#[test_case(MSSQL, TransactionCapable::ALL; "Microsoft SQL Server")]
#[test_case(MARIADB, TransactionCapable::DDL_COMMIT; "Maria DB")]
#[test_case(SQLITE_3, TransactionCapable::ALL; "SQLite 3")]
#[test_case(POSTGRES, TransactionCapable::ALL; "PostgreSQL")]
fn transaction_capable(profile: &Profile, expected: TransactionCapable) {
let conn = profile.connection().unwrap();

assert_eq!(expected, conn.transaction_capable().unwrap());
}

/// This test checks the behaviour if a connections goes out of scope with a transaction still
/// open.
#[test_case(MSSQL; "Microsoft SQL Server")]
Expand Down
Loading