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

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