-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathselect.rs
75 lines (64 loc) · 2.24 KB
/
select.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
//!
//! Rust Firebird Client
//!
//! Example of select
//!
//! You need create a database with this table:
//! create table test (col_a int generated by default as identity, col_b float, col_c varchar(10));
//!
//! You can use the insert example to populate
//! the database ;)
//!
#![allow(unused_variables, unused_mut)]
use rsfbclient::{prelude::*, FbError};
fn main() -> Result<(), FbError> {
#[cfg(feature = "linking")]
let mut conn = rsfbclient::builder_native()
.with_dyn_link()
.with_remote()
.host("localhost")
.db_name("examples.fdb")
.user("SYSDBA")
.pass("masterkey")
.transaction(TransactionConfiguration {
lock_resolution: TrLockResolution::NoWait,
..TransactionConfiguration::default()
})
.connect()?;
#[cfg(feature = "dynamic_loading")]
let mut conn = rsfbclient::builder_native()
.with_dyn_load("./fbclient.lib")
.with_remote()
.host("localhost")
.db_name("examples.fdb")
.user("SYSDBA")
.pass("masterkey")
.transaction(TransactionConfiguration {
lock_resolution: TrLockResolution::NoWait,
..TransactionConfiguration::default()
})
.connect()?;
#[cfg(feature = "pure_rust")]
let mut conn = rsfbclient::builder_pure_rust()
.host("localhost")
.db_name("examples.fdb")
.user("SYSDBA")
.pass("masterkey")
.transaction(TransactionConfiguration {
lock_resolution: TrLockResolution::NoWait,
..TransactionConfiguration::default()
})
.connect()?;
// `query_iter` for large quantities of rows, will allocate space for one row at a time
let rows = conn.query_iter("select col_a, col_b, col_c from test", ())?;
println!("| col_a | col_b | col_c |");
println!("| ----- | ----- | ------- |");
for row in rows {
let (col_a, col_b, col_c): (i32, f32, String) = row?;
println!("| {:^5} | {:^5} | {:7} |", col_a, col_b, col_c);
}
// `query` for small quantities of rows, will allocate a vector with all rows
let rows: Vec<(i32, f32, String)> = conn.query("select col_a, col_b, col_c from test", ())?;
println!("{:?}", rows);
Ok(())
}