Struct odbc_safe::DataSource[][src]

pub struct DataSource<'env, S: HDbcWrapper<'env> = Unconnected<'env>> { /* fields omitted */ }

A DataSource is used to query and manipulate a data source.

  • The state of the connection
  • The current connection-level diagnostics
  • The handles of statements and descriptors currently allocated on the connection
  • The current settings of each connection attribute

States

A DataSource is in one of two states Connected or Unconnected. These are modeled in the type at compile time. Every new DataSource starts out as Unconnected. To execute a query it needs to be Connected. You can achieve this by calling e.g. connect and capture the result in a new binding which will be of type DataSource::<'env, Connected<'env>>.

See [Connection Handles in the ODBC Reference][1] [1]: https://docs.microsoft.com/sql/odbc/reference/develop-app/connection-handles

Implementations

impl<'env, Any> DataSource<'env, Any> where
    Any: HDbcWrapper<'env>, 
[src]

pub fn into_raw(self) -> SQLHDBC[src]

Consumes the DataSource, returning the wrapped raw SQLHDBC

Leaks the Connection Handle. This is usually done in order to pass ownership from Rust to another language. After calling this method, the caller is responsible for invoking SQLFreeHandle.

pub fn as_raw(&self) -> SQLHDBC[src]

Provides access to the raw ODBC Connection Handle

pub unsafe fn from_raw(raw: SQLHDBC) -> Self[src]

May only be invoked with a valid Statement Handle which has been allocated using SQLAllocHandle. Special care must be taken that the Connection Handle passed is in a State which matches the type.

impl<'env> DataSource<'env, Unconnected<'env>>[src]

pub fn with_parent<V>(parent: &'env Environment<V>) -> Return<Self> where
    V: Version
[src]

Allocates a new DataSource. A DataSource may not outlive its parent Environment.

See [Allocating a Connection Handle ODBC][1] [1]: https://docs.microsoft.com/sql/odbc/reference/develop-app/allocating-a-connection-handle-odbc

pub fn connect<DSN: ?Sized, U: ?Sized, P: ?Sized>(
    mut self: Self,
    data_source_name: &DSN,
    user: &U,
    pwd: &P
) -> Return<Connection<'env, AutocommitOn>, DataSource<'env, Unconnected<'env>>> where
    DSN: SqlStr,
    U: SqlStr,
    P: SqlStr
[src]

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

  • See [Connecting with SQLConnect][1]
  • See [SQLConnectFunction][2]

State transition

On success this method changes the Connection handles state from Allocated to Connected . Since this state change is expressed in the type system, the method consumes self. And returns a new instance in the result type.

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 - Authenticatien string (typically the password). [1]: https://docs.microsoft.com/sql/odbc/reference/syntax/sqlconnect-function [2]: https://docs.microsoft.com/sql/odbc/reference/syntax/sqlconnect-function

pub fn connect_with_connection_string<C: ?Sized>(
    mut self: Self,
    connection_string: &C
) -> Return<Connection<'env, AutocommitOn>, Self> where
    C: SqlStr
[src]

Connects to a data source using a connection string.

For the syntax regarding the connections string see [SQLDriverConnect][1]. This method is equivalent of calling odbc_sys::SQLDriverConnect with the SQL_DRIVER_NOPROMPT parameter.

See [Choosing a Data Source or Driver][2] [1]: https://docs.microsoft.com/sql/odbc/reference/syntax/sqldriverconnect-function [2]: https://docs.microsoft.com/sql/odbc/reference/develop-app/choosing-a-data-source-or-driver

impl<'env, AC: AutocommitMode> DataSource<'env, Connected<'env, AC>>[src]

pub fn disconnect(
    mut self: Self
) -> Return<DataSource<'env, Unconnected<'env>>, Connection<'env, AC>>
[src]

When an application has finished using a data source, it calls disconnect. disconnect disconnects the driver from the data source.

  • See [Disconnecting from a Data Source or Driver][1]
  • See [SQLDisconnect Function][2] [1]: https://docs.microsoft.com/sql/odbc/reference/develop-app/disconnecting-from-a-data-source-or-driver [2]: https://docs.microsoft.com/sql/odbc/reference/syntax/sqldisconnect-function

pub fn is_read_only(&mut self) -> Return<bool>[src]

true if the data source is set to READ ONLY mode, false otherwise.

impl<'env> DataSource<'env, Connected<'env, AC>>[src]

pub fn enable_autocommit(
    mut self: Self
) -> Return<Connection<'env, AutocommitOn>, Self>
[src]

Set autocommit mode on, per ODBC spec triggers implicit commit of any running transaction

pub fn commit(&mut self) -> Return<()>[src]

Commit transaction if any, can be safely called and will be no-op if no transaction present or autocommit mode is enabled

pub fn rollback(&mut self) -> Return<()>[src]

Rollback transaction if any, can be safely called and will be no-op if no transaction present or autocommit mode is enabled

impl<'env> DataSource<'env, Connected<'env, AC>>[src]

pub fn disable_autocommit(
    mut self: Self
) -> Return<Connection<'env, AutocommitOff>, Self>
[src]

Set autocommit mode off

Trait Implementations

impl<'env, S: Debug + HDbcWrapper<'env>> Debug for DataSource<'env, S> where
    S::Handle: Debug
[src]

impl<'env, S> Diagnostics for DataSource<'env, S> where
    S: HDbcWrapper<'env>, 
[src]

Auto Trait Implementations

impl<'env, S> RefUnwindSafe for DataSource<'env, S> where
    <S as HDbcWrapper<'env>>::Handle: RefUnwindSafe
[src]

impl<'env, S> Send for DataSource<'env, S> where
    <S as HDbcWrapper<'env>>::Handle: Send
[src]

impl<'env, S> Sync for DataSource<'env, S> where
    <S as HDbcWrapper<'env>>::Handle: Sync
[src]

impl<'env, S> Unpin for DataSource<'env, S> where
    <S as HDbcWrapper<'env>>::Handle: Unpin
[src]

impl<'env, S> UnwindSafe for DataSource<'env, S> where
    <S as HDbcWrapper<'env>>::Handle: UnwindSafe
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.