pub struct Connection<'c> { /* private fields */ }
Expand description

The connection handle references storage of all information about the connection to the data source, including status, transaction state, and error information.

Connection is not Sync, this implies that many methods which one would suspect should take &mut self are actually &self. This is important if several statement exists which borrow the same connection.

Implementations§

source§

impl<'c> Connection<'c>

source

pub unsafe fn new(handle: HDbc) -> Self

Safety

Call this method only with a valid (successfully allocated) ODBC connection handle.

source

pub fn as_sys(&self) -> HDbc

Directly acces the underlying ODBC handle.

source

pub fn connect( &mut self, data_source_name: &SqlText<'_>, user: &SqlText<'_>, pwd: &SqlText<'_> ) -> SqlResult<()>

Establishes connections to a driver and a data source.

Arguments
  • data_source_name - Data source name. The data might be located on the same computer as the program, or on another computer somewhere on a network.
  • user - User identifier.
  • pwd - Authentication string (typically the password).
source

pub fn connect_with_connection_string( &mut self, connection_string: &SqlText<'_> ) -> SqlResult<()>

An alternative to connect. It supports data sources that require more connection information than the three arguments in connect and data sources that are not defined in the system information.

source

pub unsafe fn driver_connect( &mut self, connection_string: &SqlText<'_>, parent_window: HWnd, completed_connection_string: &mut OutputStringBuffer, driver_completion: DriverConnectOption ) -> SqlResult<()>

An alternative to connect for connecting with a connection string. Allows for completing a connection string with a GUI prompt on windows.

Return

SqlResult::NoData in case the prompt completing the connection string has been aborted.

Safety

parent_window must either be a valid window handle or NULL.

source

pub fn disconnect(&mut self) -> SqlResult<()>

Disconnect from an ODBC data source.

source

pub fn allocate_statement(&self) -> SqlResult<StatementImpl<'_>>

Allocate a new statement handle. The Statement must not outlive the Connection.

source

pub fn set_autocommit(&self, enabled: bool) -> SqlResult<()>

Specify the transaction mode. By default, ODBC transactions are in auto-commit mode (unless SQLSetConnectAttr and SQLSetConnectOption are not supported, which is unlikely). Switching from manual-commit mode to auto-commit mode automatically commits any open transaction on the connection.

source

pub fn set_login_timeout_sec(&self, timeout: u32) -> SqlResult<()>

Number of seconds to wait for a login request to complete before returning to the application. The default is driver-dependent. If 0 the timeout is dasabled and a connection attempt will wait indefinitely.

If the specified timeout exceeds the maximum login timeout in the data source, the driver substitutes that value and uses the maximum login timeout instead.

This corresponds to the SQL_ATTR_LOGIN_TIMEOUT attribute in the ODBC specification.

See: https://learn.microsoft.com/en-us/sql/odbc/reference/syntax/sqlsetconnectattr-function

source

pub fn commit(&self) -> SqlResult<()>

To commit a transaction in manual-commit mode.

source

pub fn rollback(&self) -> SqlResult<()>

Roll back a transaction in manual-commit mode.

source

pub fn fetch_database_management_system_name( &self, buf: &mut Vec<SqlChar> ) -> SqlResult<()>

Fetch the name of the database management system used by the connection and store it into the provided buf.

source

pub fn max_catalog_name_len(&self) -> SqlResult<u16>

Maximum length of catalog names.

source

pub fn max_schema_name_len(&self) -> SqlResult<u16>

Maximum length of schema names.

source

pub fn max_table_name_len(&self) -> SqlResult<u16>

Maximum length of table names.

source

pub fn max_column_name_len(&self) -> SqlResult<u16>

Maximum length of column names.

source

pub fn fetch_current_catalog(&self, buffer: &mut Vec<SqlChar>) -> SqlResult<()>

Fetch the name of the current catalog being used by the connection and store it into the provided buf.

source

pub fn is_dead(&self) -> SqlResult<bool>

Indicates the state of the connection. If true the connection has been lost. If false, the connection is still active.

Trait Implementations§

source§

impl<'c> AsHandle for Connection<'c>

source§

fn as_handle(&self) -> Handle

The raw underlying ODBC handle used to talk to the ODBC C API. The handle must be valid.
source§

fn handle_type(&self) -> HandleType

The type of the ODBC handle returned by as_handle. This is a method rather than a constant in order to make the type object safe.
source§

impl<'c> Drop for Connection<'c>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'c> RefUnwindSafe for Connection<'c>

§

impl<'c> !Send for Connection<'c>

§

impl<'c> !Sync for Connection<'c>

§

impl<'c> Unpin for Connection<'c>

§

impl<'c> UnwindSafe for Connection<'c>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.