odbc_api::handles

Struct Connection

Source
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 set_packet_size(&self, packet_size: u32) -> SqlResult<()>

Specifying the network packet size in bytes. Note: Many data sources either do not support this option or only can return but not set the network packet size. If the specified size exceeds the maximum packet size or is smaller than the minimum packet size, the driver substitutes that value and returns SQLSTATE 01S02 (Option value changed). If the application sets packet size after a connection has already been made, the driver will return SQLSTATE HY011 (Attribute cannot be set now).

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.

Source

pub fn packet_size(&self) -> SqlResult<u32>

Networ packet size in bytes.

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
Source§

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

According to the ODBC documentation this is safe. See: https://docs.microsoft.com/en-us/sql/odbc/reference/develop-app/multithreading

In addition to that, this has not caused trouble in a while. So we mark sending connections to other threads as safe. Reading through the documentation, one might get the impression that Connections are also Sync. This could be theoretically true on the level of the handle, but at the latest once the interior mutability due to error handling comes in to play, higher level abstraction have to content themselves with Send. This is currently how far my trust with most ODBC drivers.

Auto Trait Implementations§

§

impl<'c> Freeze for Connection<'c>

§

impl<'c> RefUnwindSafe 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 T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> Diagnostics for T
where T: AsHandle + ?Sized,

Source§

fn diagnostic_record( &self, rec_number: i16, message_text: &mut [u16], ) -> Option<DiagnosticResult>

Call this method to retrieve diagnostic information for the last call to an ODBC function. Read more
Source§

fn diagnostic_record_vec( &self, rec_number: i16, message_text: &mut Vec<SqlChar>, ) -> Option<DiagnosticResult>

Call this method to retrieve diagnostic information for the last call to an ODBC function. This method builds on top of Self::diagnostic_record, if the message does not fit in the buffer, it will grow the message buffer and extract it again. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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 T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.