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

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