mirror of
https://github.com/scottlamb/moonfire-nvr.git
synced 2025-11-09 13:39:46 -05:00
update rusqlite
The big difference here is query_named and execute_named have gone away. Fair number of lines changes but straightforward.
This commit is contained in:
@@ -7,7 +7,7 @@ use crate::db;
|
||||
use crate::recording;
|
||||
use failure::Error;
|
||||
use log::warn;
|
||||
use rusqlite::params;
|
||||
use rusqlite::{named_params, params};
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub fn run(_args: &super::Args, tx: &rusqlite::Transaction) -> Result<(), Error> {
|
||||
@@ -179,32 +179,30 @@ fn fill_recording(tx: &rusqlite::Transaction) -> Result<HashMap<i32, CameraState
|
||||
Some((run_id, expected_start)) if expected_start == start_time_90k => run_id,
|
||||
_ => composite_id,
|
||||
};
|
||||
insert1.execute_named(&[
|
||||
(":composite_id", &composite_id),
|
||||
(":camera_id", &camera_id),
|
||||
(":run_offset", &(composite_id - run_id)),
|
||||
(
|
||||
":flags",
|
||||
&(if trailing_zero {
|
||||
insert1.execute(named_params! {
|
||||
":composite_id": &composite_id,
|
||||
":camera_id": &camera_id,
|
||||
":run_offset": &(composite_id - run_id),
|
||||
":flags": &(
|
||||
if trailing_zero {
|
||||
db::RecordingFlags::TrailingZero as i32
|
||||
} else {
|
||||
0
|
||||
}),
|
||||
),
|
||||
(":sample_file_bytes", &sample_file_bytes),
|
||||
(":start_time_90k", &start_time_90k),
|
||||
(":duration_90k", &duration_90k),
|
||||
(":local_time_delta_90k", &local_time_delta_90k),
|
||||
(":video_samples", &video_samples),
|
||||
(":video_sync_samples", &video_sync_samples),
|
||||
(":video_sample_entry_id", &video_sample_entry_id),
|
||||
])?;
|
||||
insert2.execute_named(&[
|
||||
(":composite_id", &composite_id),
|
||||
(":sample_file_uuid", &&sample_file_uuid.0.as_bytes()[..]),
|
||||
(":sample_file_sha1", &sample_file_sha1),
|
||||
(":video_index", &video_index),
|
||||
])?;
|
||||
":sample_file_bytes": &sample_file_bytes,
|
||||
":start_time_90k": &start_time_90k,
|
||||
":duration_90k": &duration_90k,
|
||||
":local_time_delta_90k": &local_time_delta_90k,
|
||||
":video_samples": &video_samples,
|
||||
":video_sync_samples": &video_sync_samples,
|
||||
":video_sample_entry_id": &video_sample_entry_id,
|
||||
})?;
|
||||
insert2.execute(named_params! {
|
||||
":composite_id": &composite_id,
|
||||
":sample_file_uuid": &sample_file_uuid.0.as_bytes()[..],
|
||||
":sample_file_sha1": &sample_file_sha1,
|
||||
":video_index": &video_index,
|
||||
})?;
|
||||
camera_state.current_run = if trailing_zero {
|
||||
None
|
||||
} else {
|
||||
@@ -224,10 +222,10 @@ fn update_camera(
|
||||
"#,
|
||||
)?;
|
||||
for (ref id, ref state) in &camera_state {
|
||||
stmt.execute_named(&[
|
||||
(":id", &id),
|
||||
(":next_recording_id", &state.next_recording_id),
|
||||
])?;
|
||||
stmt.execute(named_params! {
|
||||
":id": &id,
|
||||
":next_recording_id": &state.next_recording_id,
|
||||
})?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ use crate::schema::DirMeta;
|
||||
use failure::{bail, format_err, Error};
|
||||
use nix::fcntl::{FlockArg, OFlag};
|
||||
use nix::sys::stat::Mode;
|
||||
use rusqlite::params;
|
||||
use rusqlite::{named_params, params};
|
||||
use std::os::unix::io::AsRawFd;
|
||||
use uuid::Uuid;
|
||||
|
||||
@@ -397,14 +397,14 @@ fn fix_video_sample_entry(tx: &rusqlite::Transaction) -> Result<(), Error> {
|
||||
let mut rows = select.query(params![])?;
|
||||
while let Some(row) = rows.next()? {
|
||||
let data: Vec<u8> = row.get(4)?;
|
||||
insert.execute_named(&[
|
||||
(":id", &row.get::<_, i32>(0)?),
|
||||
(":sha1", &row.get::<_, Vec<u8>>(1)?),
|
||||
(":width", &row.get::<_, i32>(2)?),
|
||||
(":height", &row.get::<_, i32>(3)?),
|
||||
(":rfc6381_codec", &rfc6381_codec_from_sample_entry(&data)?),
|
||||
(":data", &data),
|
||||
])?;
|
||||
insert.execute(named_params! {
|
||||
":id": &row.get::<_, i32>(0)?,
|
||||
":sha1": &row.get::<_, Vec<u8>>(1)?,
|
||||
":width": &row.get::<_, i32>(2)?,
|
||||
":height": &row.get::<_, i32>(3)?,
|
||||
":rfc6381_codec": &rfc6381_codec_from_sample_entry(&data)?,
|
||||
":data": &data,
|
||||
})?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ pub fn run(_args: &super::Args, tx: &rusqlite::Transaction) -> Result<(), Error>
|
||||
)?;
|
||||
let mut rows = stmt.query(params![])?;
|
||||
while let Some(row) = rows.next()? {
|
||||
let path = row.get_raw_checked(0)?.as_str()?;
|
||||
let path = row.get_ref(0)?.as_str()?;
|
||||
info!("path: {}", path);
|
||||
let dir_uuid: FromSqlUuid = row.get(1)?;
|
||||
let open_id: Option<u32> = row.get(2)?;
|
||||
|
||||
@@ -102,7 +102,7 @@ pub fn run(_args: &super::Args, tx: &rusqlite::Transaction) -> Result<(), Error>
|
||||
let id: i32 = row.get(0)?;
|
||||
let width: u16 = row.get::<_, i32>(1)?.try_into()?;
|
||||
let height: u16 = row.get::<_, i32>(2)?.try_into()?;
|
||||
let rfc6381_codec: &str = row.get_raw_checked(3)?.as_str()?;
|
||||
let rfc6381_codec: &str = row.get_ref(3)?.as_str()?;
|
||||
let mut data: Vec<u8> = row.get(4)?;
|
||||
let avcc = parse(&data)?;
|
||||
if avcc.num_of_sequence_parameter_sets() != 1 {
|
||||
@@ -132,7 +132,7 @@ pub fn run(_args: &super::Args, tx: &rusqlite::Transaction) -> Result<(), Error>
|
||||
BigEndian::write_u32(&mut data[0..4], u32::try_from(len)?);
|
||||
}
|
||||
|
||||
insert.execute_named(named_params! {
|
||||
insert.execute(named_params! {
|
||||
":id": id,
|
||||
":width": width,
|
||||
":height": height,
|
||||
@@ -253,7 +253,7 @@ pub fn run(_args: &super::Args, tx: &rusqlite::Transaction) -> Result<(), Error>
|
||||
cur_stream_id = Some(stream_id);
|
||||
}
|
||||
insert
|
||||
.execute_named(named_params! {
|
||||
.execute(named_params! {
|
||||
":composite_id": composite_id,
|
||||
":open_id": open_id,
|
||||
":stream_id": stream_id,
|
||||
|
||||
Reference in New Issue
Block a user