Skip to content

Commit 2fae02a

Browse files
author
Drew Wells
committed
report write errors if sqlite can not be created
1 parent b74d5f1 commit 2fae02a

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/database/sqlite.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
use std::path::{PathBuf};
12
use std::io::{Error, ErrorKind};
3+
use std::fs::File;
24
use rusqlite::{Connection, Row};
35
use crate::database::{Database, DBRawToStruct};
46
use crate::results::TelemetryData;
@@ -13,7 +15,25 @@ pub fn init (database_file : &Option<String>) -> std::io::Result<Connection> {
1315
Err(Error::new(ErrorKind::Other,"Error setup sqlite invalid database file."))
1416
}
1517
Some(database_file) => {
16-
let connection = Connection::open(database_file);
18+
let mut database_path = PathBuf::from(database_file);
19+
if !database_path.is_absolute() {
20+
database_path = PathBuf::from(std::env::current_dir().unwrap().join(database_file));
21+
}
22+
23+
println!("Using sqlite database file: {}", database_path.display());
24+
25+
if !database_path.exists() {
26+
let create_file = File::create(&database_path);
27+
match create_file {
28+
Ok(_) => {
29+
println!("Created sqlite database file: {}", database_path.display());
30+
}
31+
Err(e) => {
32+
return Err(Error::new(ErrorKind::Other,format!("Error setup sqlite {:?}",e)));
33+
}
34+
}
35+
}
36+
let connection = Connection::open(database_path);
1737
match connection {
1838
Ok(connection) => {
1939
let create_table = connection.execute(

0 commit comments

Comments
 (0)