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 access_token;
11
pub mod authorization_code;
12
pub mod client;
13
pub mod conn;
14
pub mod login_session;
15
pub mod refresh_token;
16
pub mod user;
17

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

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