Connection

Type Alias Connection 

Source
pub type Connection<'env, AC> = DataSource<'env, Connected<'env, AC>>;
Expand description

Connection can be used as a shorthand for a DataSource in Connected state.

Aliased Type§

pub struct Connection<'env, AC> { /* private fields */ }

Implementations§

Source§

impl<'env, AC: AutocommitMode> Connection<'env, AC>

Source

pub fn disconnect( self, ) -> Return<DataSource<'env, Unconnected<'env>>, Connection<'env, AC>>

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
Source

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

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

Source§

impl<'env> Connection<'env, AutocommitOff>

Source

pub fn enable_autocommit(self) -> Return<Connection<'env, AutocommitOn>, Self>

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

Source

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

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

Examples found in repository?
examples/transactions.rs (line 21)
5fn main() {
6    let env = Environment::new().unwrap();
7    let env = env.declare_version_3().unwrap();
8
9    let ds = DataSource::with_parent(&env).unwrap();
10    let conn = ds.connect("TestDataSource", "", "").unwrap();
11    let mut conn = conn.disable_autocommit().unwrap();
12
13    {
14        //Any statement now will start transaction which could be ended with conn.commit() or conn.rollback()
15        //If either commit or rollback was not called before connection drop automatic rollback will be issued
16        let stmt = Statement::with_parent(&conn).unwrap();
17        let res = stmt.exec_direct("SELECT 'HELLO' FROM MOVIES");
18        println!("Result {:?}", res);
19    }
20
21    let end_tx_result = conn.commit();
22
23    println!("End TX result {:?}", end_tx_result);
24}
Source

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

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

Source§

impl<'env> Connection<'env, AutocommitOn>

Source

pub fn disable_autocommit(self) -> Return<Connection<'env, AutocommitOff>, Self>

Set autocommit mode off

Examples found in repository?
examples/transactions.rs (line 11)
5fn main() {
6    let env = Environment::new().unwrap();
7    let env = env.declare_version_3().unwrap();
8
9    let ds = DataSource::with_parent(&env).unwrap();
10    let conn = ds.connect("TestDataSource", "", "").unwrap();
11    let mut conn = conn.disable_autocommit().unwrap();
12
13    {
14        //Any statement now will start transaction which could be ended with conn.commit() or conn.rollback()
15        //If either commit or rollback was not called before connection drop automatic rollback will be issued
16        let stmt = Statement::with_parent(&conn).unwrap();
17        let res = stmt.exec_direct("SELECT 'HELLO' FROM MOVIES");
18        println!("Result {:?}", res);
19    }
20
21    let end_tx_result = conn.commit();
22
23    println!("End TX result {:?}", end_tx_result);
24}