add more informations in db
This commit is contained in:
parent
f896185848
commit
d5314c6745
20
src/db.rs
20
src/db.rs
@ -2,10 +2,11 @@ use rusqlite::*;
|
|||||||
|
|
||||||
const DBPATH: &'static str = "data/tracker.db";
|
const DBPATH: &'static str = "data/tracker.db";
|
||||||
const STATEMENTS: [&str; 2] = [
|
const STATEMENTS: [&str; 2] = [
|
||||||
"CREATE TABLE log (id integer primary key autoincrement, time text, latitude float, longitude float);",
|
"CREATE TABLE log (id integer primary key autoincrement, time text, latitude float, longitude float, speed integer, height integer, direction integer);",
|
||||||
"CREATE INDEX idx_time on log (time);",];
|
"CREATE INDEX idx_time on log (time);",];
|
||||||
const QUERY_INSERT: &'static str =
|
const QUERY_INSERT: &'static str =
|
||||||
"INSERT INTO log (time, latitude, longitude) values (:time, :latitude, :longitude)";
|
"INSERT INTO log (time, latitude, longitude, speed, height, direction)
|
||||||
|
VALUES (:time, :latitude, :longitude, :speed, :height, :direction)";
|
||||||
|
|
||||||
pub fn connectdb() -> Result<Connection> {
|
pub fn connectdb() -> Result<Connection> {
|
||||||
let conn = Connection::open(DBPATH)?;
|
let conn = Connection::open(DBPATH)?;
|
||||||
@ -33,8 +34,19 @@ fn set_pragmas(conn: &Connection) -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert(conn: &Connection, time: &String, latitude: &f64, longitude: &f64) -> Result<()> {
|
pub fn insert(
|
||||||
match conn.execute(QUERY_INSERT, params![time, latitude, longitude]) {
|
conn: &Connection,
|
||||||
|
time: &String,
|
||||||
|
latitude: &f64,
|
||||||
|
longitude: &f64,
|
||||||
|
speed: &u16,
|
||||||
|
height: &u16,
|
||||||
|
direction: &u16,
|
||||||
|
) -> Result<()> {
|
||||||
|
match conn.execute(
|
||||||
|
QUERY_INSERT,
|
||||||
|
params![time, latitude, longitude, speed, height, direction],
|
||||||
|
) {
|
||||||
Ok(inserted) => println!("{} rows were inserted", inserted),
|
Ok(inserted) => println!("{} rows were inserted", inserted),
|
||||||
Err(err) => println!("insert failed: {}", err),
|
Err(err) => println!("insert failed: {}", err),
|
||||||
}
|
}
|
||||||
|
@ -328,6 +328,9 @@ impl Message {
|
|||||||
&t.time.format("%Y-%m-%d %H:%M:%S").to_string(),
|
&t.time.format("%Y-%m-%d %H:%M:%S").to_string(),
|
||||||
&t.latitude,
|
&t.latitude,
|
||||||
&t.longitude,
|
&t.longitude,
|
||||||
|
&t.speed,
|
||||||
|
&t.height,
|
||||||
|
&t.direction,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user