To test Rust on real-life data, I would like to make a connection to an ODBC database. I have made some progress, but I'm struggling to retrieve the output from the cursor.
The best I have achieved so far is printing 'Hurray' 200 times, but this is not what I am looking for. I would really appreciate it if someone could guide me on how to push data to a Polars DataFrame. Does anyone know how I could accomplish this?
fn main() {
use odbc_api::{ConnectionOptions, Cursor, Environment};
let connection_string = connection_string();
let env = Environment::new().unwrap();
let conn = env
.connect_with_connection_string(&connection_string, ConnectionOptions::default())
.unwrap();
let result_set = conn
.execute(&String::from("SELECT TOP 200 * FROM pub.table"), ())
.unwrap();
if let Some(mut cursor) = result_set {
loop {
match cursor.next_row() {
Ok(Some(_cursor_row)) => {
println!("Hurray!")
}
Ok(None) => {
break;
}
Err(err) => {
eprintln!("Error while fetching next row: {:?}", err);
break;
}
}
}
} else {
eprintln!("Result set is None");
}
}
I found a working solution:
Unfortunately, I have to export the data to a CSV file and then import it into a DataFrame, which means the same Python script runs faster.