1
//! SQLite model implementation.
2
//!
3
//! # Notes
4
//!
5
//! The cursor is the **simulated** implementation. It only works when there are no add/delete
6
//! operations during a list operation.
7

            
8
use sql_builder::{esc, SqlBuilder};
9

            
10
pub mod application;
11
pub mod conn;
12
pub mod device;
13
pub mod device_route;
14
pub mod dldata_buffer;
15
pub mod network;
16
pub mod network_route;
17
pub mod unit;
18

            
19
1526
fn build_where_like<S, T>(builder: &mut SqlBuilder, field: S, mask: T) -> &mut SqlBuilder
20
1526
where
21
1526
    S: ToString,
22
1526
    T: ToString,
23
1526
{
24
1526
    let mut use_escape = false;
25
1526
    let mask = mask.to_string();
26
1526
    let like_str = mask
27
1526
        .replace("\\", "\\\\")
28
1526
        .replace("%", "\\%")
29
1526
        .replace("_", "\\_");
30
1526
    if like_str.len() > mask.len() {
31
108
        use_escape = true;
32
1418
    }
33

            
34
1526
    let mut cond = field.to_string();
35
1526
    cond.push_str(" LIKE '%");
36
1526
    cond.push_str(&esc(like_str.as_str()));
37
1526
    cond.push_str("%'");
38
1526
    if use_escape {
39
108
        cond.push_str(" ESCAPE '\\'");
40
1418
    }
41
1526
    builder.and_where(&cond)
42
1526
}