News for hackers. Stuff that matters.
Re:Compile Time Prevention of SQL-Injections in Rust by C4K3 on Tuesday May 22, 2018 @10:27AM (#17126121)
to_owned() converts to a String, not to a &'static str. Those are not the same. You can't create a &'static str dynamically (though you can mutate one using unsafe.)
Re:Compile Time Prevention of SQL-Injections in Rust by derkha on Tuesday May 22, 2018 @10:40AM (#17126196)
You can convert a `String` into a `&'static str` using only safe stdlib functions via `Box::leak(s.into())`. This uses `unsafe` internally, of course... but so does almost any code.
Re:Compile Time Prevention of SQL-Injections in Rust by C4K3 on Tuesday May 22, 2018 @10:47AM (#17126242)
Ah cool, I hadn't heard about Box::leak until now. Coming to stable in 1.26 it seems.
Re:Compile Time Prevention of SQL-Injections in Rust by EugeneOZ on Tuesday May 22, 2018 @10:36AM (#17126168)
lol, so you call your SQL just with constants? "username" in his example just for one user forever? Still a bullshit.
Re:Compile Time Prevention of SQL-Injections in Rust by C4K3 on Tuesday May 22, 2018 @10:49AM (#17126261)
No, only the SQL statement has to be 'static. It's not bullshit.
Re:Compile Time Prevention of SQL-Injections in Rust by EugeneOZ on Tuesday May 22, 2018 @11:11AM (#17126437)
Can you provide real-world example please?
Re:Compile Time Prevention of SQL-Injections in Rust by Khoth on Tuesday May 22, 2018 @11:44AM (#17126775)
From TFA:

let _rows = sql_query("SELECT * FROM users WHERE username=?", &[username]);

The statement is static, but the [username] part is not, it's just a variable that can have whatever username you want.

Re:Compile Time Prevention of SQL-Injections in Rust by EugeneOZ on Tuesday May 22, 2018 @08:16PM (#17130553)
and I already told that this example has no meaning, it's just a bullshit - nobody will use it in real app. You want to fetch from db info about the only one user, who's name is a constant? Yeah, all apps do it every day.