Skip to content

Commit

Permalink
report write errors if sqlite can not be created
Browse files Browse the repository at this point in the history
  • Loading branch information
drewwells committed Nov 26, 2024
1 parent b74d5f1 commit 2fae02a
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/database/sqlite.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use std::path::{PathBuf};
use std::io::{Error, ErrorKind};
use std::fs::File;
use rusqlite::{Connection, Row};
use crate::database::{Database, DBRawToStruct};
use crate::results::TelemetryData;
Expand All @@ -13,7 +15,25 @@ pub fn init (database_file : &Option<String>) -> std::io::Result<Connection> {
Err(Error::new(ErrorKind::Other,"Error setup sqlite invalid database file."))
}
Some(database_file) => {
let connection = Connection::open(database_file);
let mut database_path = PathBuf::from(database_file);
if !database_path.is_absolute() {
database_path = PathBuf::from(std::env::current_dir().unwrap().join(database_file));
}

println!("Using sqlite database file: {}", database_path.display());

if !database_path.exists() {
let create_file = File::create(&database_path);
match create_file {
Ok(_) => {
println!("Created sqlite database file: {}", database_path.display());
}
Err(e) => {
return Err(Error::new(ErrorKind::Other,format!("Error setup sqlite {:?}",e)));
}
}
}
let connection = Connection::open(database_path);
match connection {
Ok(connection) => {
let create_table = connection.execute(
Expand Down

0 comments on commit 2fae02a

Please sign in to comment.