/// Run a query to check whether the SHA1 is present, print the results.
Run a query to check whether the SHA1 is present, print the results.
Run a query to check whether the SHA1 is present print the results .
fn check_password<
  Store: noblit::store::Store,
  Heap: noblit::heap::Heap,
>(
    db: &database::Database<Store, Heap>,
    sha1: &[u8; 20],
) {
    use noblit::query::{Query, Statement, Var};
    let mut temporaries = Temporaries::new();
    let cid_pw_sha1 = temporaries.push_string("pw.sha1".to_string());
    let cid_pw_count = temporaries.push_string("pw.count".to_string());
    let cid_sha1 = temporaries.push_bytes(Box::new(sha1.clone()));
    let mut view = db.view(temporaries);
    // Encode this query:
    // TODO: Add a more user-friendly way of doing this.
    // where
    //   pw pw.sha1 <sha1>
    //   pw pw.count c
    // select
    //   c
    let mut query = Query {
        variable_names: vec![
            "pw".to_string(), // 0
            "c".to_string(),  // 1
        ],
        where_statements: vec![
            Statement::named_const(Var(0), cid_pw_sha1, Value::from_const_bytes(cid_sha1)),
            Statement::named_var(Var(0), cid_pw_count, Var(1)),
        ],
        select: vec![Var(1)],
    };
    query.fix_attributes(&mut view);
    query.infer_types(&view).expect("Query contains a type error.");
    let plan = noblit::planner::Planner::plan(&query);
    let eval = noblit::eval::Evaluator::new(&plan, &view);
    let rows: Vec<_> = eval.collect();
    match rows.len() {
        0 => println!("SHA1 is not present in the database."),
        1 => println!("SHA1 is present with count {}.", rows[0][0].as_u64(view.heap())),
        _ => panic!("SHA1 was found more than once."),
    }
    // TODO: Print timing information.
}
fn check_password < Store : noblit :: store :: Store , Heap : noblit :: heap :: Heap , > ( db : & database :: Database < Store , Heap > , sha1 : & [ u8 ; 20 ] , ) { use noblit :: query :: { Query , Statement , Var } ; let mut temporaries = Temporaries :: new ( ) ; let cid_pw_sha1 = temporaries . push_string ( " " . to_string ( ) ) ; let cid_pw_count = temporaries . push_string ( " " . to_string ( ) ) ; let cid_sha1 = temporaries . push_bytes ( Box :: new ( sha1 . clone ( ) ) ) ; let mut view = db . view ( temporaries ) ; // Encode this query: // TODO: Add a more user-friendly way of doing this. // where //   pw pw.sha1 <sha1> //   pw pw.count c // select //   c let mut query = Query { variable_names : vec ! [ " " to_string ( ) // 0 " " to_string ( ) // 1 ] , where_statements : vec ! [ Statement named_const ( Var ( 0 ) cid_pw_sha1 Value from_const_bytes ( cid_sha1 ) ) Statement named_var ( Var ( 0 ) cid_pw_count Var ( 1 ) ) ] , select : vec ! [ Var ( 1 ) ] , } ; query . fix_attributes ( & mut view ) ; query . infer_types ( & view ) . expect ( " " ) ; let plan = noblit :: planner :: Planner :: plan ( & query ) ; let eval = noblit :: eval :: Evaluator :: new ( & plan , & view ) ; let rows : Vec < _ > = eval . collect ( ) ; match rows . len ( ) { 0 => println ! ( " " ) , 1 => println ! ( " " rows [ 0 ] [ 0 ] as_u64 ( view heap ( ) ) ) , _ => panic ! ( " " ) , } // TODO: Print timing information. }
Run a query to check whether the SHA1 is present, print the results.
Run a query to check whether the SHA1 is present print the results .
db
&database::Database<Store, Heap>
sha1
&[u8; 20]