transactions/
transactions.rs

1//! Transaction handling example
2extern crate odbc_safe;
3use odbc_safe::*;
4
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}