-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathtransaction.rs
76 lines (62 loc) · 1.98 KB
/
transaction.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//!
//! Rust Firebird Client
//!
//! Example of transaction builder and transaction utilization
//!
#![allow(unused_variables, unused_mut)]
use rsfbclient::{prelude::*, FbError};
fn main() -> Result<(), FbError> {
#[cfg(feature = "linking")]
let mut builder = rsfbclient::builder_native()
.with_dyn_link()
.with_remote()
.host("localhost")
.db_name("examples.fdb")
.user("SYSDBA")
.pass("masterkey")
.clone();
#[cfg(feature = "dynamic_loading")]
let mut builder = rsfbclient::builder_native()
.with_dyn_load("./fbclient.lib")
.with_remote()
.host("localhost")
.db_name("examples.fdb")
.user("SYSDBA")
.pass("masterkey")
.clone();
#[cfg(feature = "pure_rust")]
let mut builder = rsfbclient::builder_pure_rust()
.host("localhost")
.db_name("examples.fdb")
.user("SYSDBA")
.pass("masterkey")
.clone();
let mut conn = builder
.with_transaction(|tr| tr.read_write().wait(120).with_consistency())
.connect()?;
// Default transaction
let _: Vec<(String, String)> = conn.query(
"select mon$attachment_name, mon$user from mon$attachments",
(),
)?;
conn.rollback()?;
// New scoped transaction
conn.with_transaction(|tr| {
let _: Vec<(String, String)> = tr.query(
"select mon$attachment_name, mon$user from mon$attachments",
(),
)?;
Ok(())
})?;
// New scoped transaction, but with a diferent transaction conf
conn.with_transaction_config(transaction_builder().no_wait().build(), |tr| {
let _: Vec<(String, String)> = tr.query(
"select mon$attachment_name, mon$user from mon$attachments",
(),
)?;
Ok(())
})?;
// New default transaction, but with a diferent transaction conf too
conn.begin_transaction_config(transaction_builder().read_only().build())?;
Ok(())
}