0

I am developing a Rust program that fetch datas from a mysql database using the sqlx crate. It compiles but it seems that nothing is returned by the crate function.

this is my function code so far (I’ve shortened this code at the [...] because it is too long):

#[post("/domaine")]
async fn recupdomain(req: Json<Domaine>) -> HttpResponse {
    let test = req.domain.clone();
    if test[0].eq("") {
        return HttpResponse::Ok().body("rien reçu");
    }
    println!("test={:?}",test);
    let mut pool = mysql::MySqlConnectOptions::new()
        .host("mysql.default")
        .username("database_user")
        .password("password")
        .database("project_database")
        .connect().await.expect("defaut de connexion");
        
        
    let mut donnees: Vec<DATAResult> = Vec::new();
    
        
        for i in &req.domain {
        let mut domaine = i.clone();
        let mut domaine2 = i.clone();
        
        
        
            let mut result = sqlx::query("SELECT * FROM servers INNER JOIN domains WHERE `servers`.`domaine` = `domains`.`domain` AND `servers`.`domaine` = ?;")
                .bind(&domaine)
            .bind(&domaine2)
                .fetch(&mut pool);
    
        
        
        
        
        
        while let Some(row) = result.try_next().await.expect("ah") {
            
            
            let donnee = DATAResult {tls: Retour {certificat: row.try_get("`tls.certificat`").expect("recuperation ratée"), liste: vec![row.try_get("`tls.liste`").expect("recuperation ratée")], cyfaible: row.try_get("`tls.cyfaible`").expect("recuperation ratée") [...] };
            
            println!("fetched: {:?}",donnee);
            
            donnees.push(donnee);
        }
            
            
            
            
        }
        
        println!("all datas fetched: {:?}",donnees);
        
        let renvoi = serde_json::to_string(&donnees);
        
        println!("after serialization: {:?}",renvoi);
        
        return HttpResponse::Ok().body(renvoi.expect("returning failure!").clone());
    

}

I tried multiple synthaxes for row.try_get("tls.certificat").expect("recuperation ratée"), with or without character use the synthaxtable_name.field_nameor thetable_name.field_name` but nothing solved the problem, the logs are still empty.

Yuri Astrakhan
  • 8,808
  • 6
  • 63
  • 97
  • 1
    Your SQL query looks suspicious: you have two `.bind()` parameters but only one `?` placeholder. – kmdreko May 27 '23 at 20:35

0 Answers0