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
use TokenStream;
use ;
use crateexpand;
/// Use this to derive the trait `FetchRow` for structs defined in the application logic.
///
/// # Example
///
/// ```
/// use odbc_api_derive::Fetch;
/// use odbc_api::{Connection, Error, Cursor, parameter::VarCharArray, buffers::RowVec};
///
/// #[derive(Default, Clone, Copy, Fetch)]
/// struct Person {
/// first_name: VarCharArray<255>,
/// last_name: VarCharArray<255>,
/// }
///
/// fn send_greetings(conn: &mut Connection) -> Result<(), Error> {
/// let max_rows_in_batch = 250;
/// let buffer = RowVec::<Person>::new(max_rows_in_batch);
/// let mut cursor = conn.execute("SELECT first_name, last_name FROM Persons", (), None)?
/// .expect("SELECT must yield a result set");
/// let mut block_cursor = cursor.bind_buffer(buffer)?;
///
/// while let Some(batch) = block_cursor.fetch()? {
/// for person in batch.iter() {
/// let first = person.first_name.as_str()
/// .expect("First name must be UTF-8")
/// .expect("First Name must not be NULL");
/// let last = person.last_name.as_str()
/// .expect("Last name must be UTF-8")
/// .expect("Last Name must not be NULL");
/// println!("Hello {first} {last}!")
/// }
/// }
/// Ok(())
/// }
/// ```