Skip to content

Commit

Permalink
introduce OdbcConnection::take
Browse files Browse the repository at this point in the history
  • Loading branch information
pacman82 committed Jul 14, 2024
1 parent b0d2c96 commit e0349cd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ use log::debug;
use crate::{try_, ArrowOdbcError, ENV};

/// Opaque type to transport connection to an ODBC Datasource over language boundry
pub struct OdbcConnection(pub Connection<'static>);
pub struct OdbcConnection(Connection<'static>);

impl OdbcConnection {
/// Take the inner connection out of its wrapper
pub fn take(self) -> Connection<'static> {
self.0
}
}

/// Allocate and open an ODBC connection using the specified connection string. In case of an error
/// this function returns a NULL pointer.
Expand Down
2 changes: 1 addition & 1 deletion src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub unsafe extern "C" fn arrow_odbc_reader_set_connection(
connection: NonNull<OdbcConnection>,
) {
let connection = *Box::from_raw(connection.as_ptr());
reader.as_mut().set_connection(connection.0);
reader.as_mut().set_connection(connection.take());
}

/// Creates an Arrow ODBC reader instance.
Expand Down
2 changes: 1 addition & 1 deletion src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub unsafe extern "C" fn arrow_odbc_writer_make(
writer_out: *mut *mut ArrowOdbcWriter,
) -> *mut ArrowOdbcError {
let connection = *Box::from_raw(connection.as_ptr());
let connection = connection.0;
let connection = connection.take();

let table = slice::from_raw_parts(table_buf, table_len);
let table = str::from_utf8(table).unwrap();
Expand Down

0 comments on commit e0349cd

Please sign in to comment.