Skip to content

Commit

Permalink
add debug logging around alloaction and
Browse files Browse the repository at this point in the history
deallocation of connection handles
  • Loading branch information
pacman82 committed Nov 27, 2023
1 parent 984c651 commit f332080
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
5 changes: 4 additions & 1 deletion odbc-api/src/handles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub use {
statement::{AsStatementRef, ParameterDescription, Statement, StatementImpl, StatementRef},
};

use log::debug;
use odbc_sys::{Handle, HandleType, SQLFreeHandle, SqlReturn};
use std::thread::panicking;

Expand All @@ -45,7 +46,9 @@ use std::thread::panicking;
/// `handle` Must be a valid ODBC handle and `handle_type` must match its type.
pub unsafe fn drop_handle(handle: Handle, handle_type: HandleType) {
match SQLFreeHandle(handle_type, handle) {
SqlReturn::SUCCESS => (),
SqlReturn::SUCCESS => {
debug!("SQLFreeHandle dropped {handle:?} of type {handle_type:?}.");
},
other => {
// Avoid panicking, if we already have a panic. We don't want to mask the
// original error.
Expand Down
10 changes: 9 additions & 1 deletion odbc-api/src/handles/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use super::{
statement::StatementImpl,
OutputStringBuffer, SqlResult,
};
use log::debug;
use odbc_sys::{
CompletionType, ConnectionAttribute, DriverConnectOption, HDbc, HEnv, HStmt, HWnd, Handle,
HandleType, InfoType, Pointer, SQLAllocHandle, SQLDisconnect, SQLEndTran, IS_UINTEGER,
Expand Down Expand Up @@ -395,6 +396,13 @@ impl<'c> Connection<'c> {
null_mut(),
)
.into_sql_result("SQLGetConnectAttr")
.on_success(|| out)
.on_success(|| {
let handle = self.handle;
debug!(
"SQLGetConnectAttr called with attribute '{attribute:?}' for connection \
'{handle:?}' reported '{out}'."
);
out
})
}
}
6 changes: 5 additions & 1 deletion odbc-api/src/handles/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use super::{
sql_result::{ExtSqlReturn, SqlResult},
Connection,
};
use log::debug;
use odbc_sys::{
AttrCpMatch, AttrOdbcVersion, EnvironmentAttribute, FetchOrientation, HDbc, HEnv, Handle,
HandleType, SQLAllocHandle, SQLSetEnvAttr,
Expand Down Expand Up @@ -129,7 +130,10 @@ impl Environment {
unsafe {
SQLAllocHandle(HandleType::Dbc, self.as_handle(), &mut handle)
.into_sql_result("SQLAllocHandle")
.on_success(|| Connection::new(handle as HDbc))
.on_success(|| {
let handle = handle as HDbc;
debug!("SQLAllocHandle allocated connection (Dbc) handle '{handle:?}'");
Connection::new(handle)})
}
}

Expand Down

0 comments on commit f332080

Please sign in to comment.