File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change 1+ use std:: path:: { PathBuf } ;
12use std:: io:: { Error , ErrorKind } ;
3+ use std:: fs:: File ;
24use rusqlite:: { Connection , Row } ;
35use crate :: database:: { Database , DBRawToStruct } ;
46use 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 (
You can’t perform that action at this time.
0 commit comments