Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

report write errors if sqlite can not be created #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions src/database/sqlite.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
use std::io::{Error, ErrorKind};
use rusqlite::{Connection, Row};
use crate::database::{Database, DBRawToStruct};
use crate::database::{DBRawToStruct, Database};
use crate::results::TelemetryData;
use rusqlite::{Connection, Row};
use std::io::{Error, ErrorKind};
use std::path::PathBuf;

pub struct SQLite {
pub connection: Connection,
}

pub fn init (database_file : &Option<String>) -> std::io::Result<Connection> {
pub fn init(database_file: &Option<String>) -> std::io::Result<Connection> {
match database_file {
None => {
Err(Error::new(ErrorKind::Other,"Error setup sqlite invalid database file."))
}
None => 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));
}

// attempt to create the parent directory and ignore errors if it already exists
let _ = std::fs::create_dir_all(database_path.parent().unwrap());

let connection = Connection::open(database_path);
match connection {
Ok(connection) => {
let create_table = connection.execute(
Expand Down