aboutsummaryrefslogtreecommitdiff
path: root/src/database.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/database.rs')
-rw-r--r--src/database.rs34
1 files changed, 27 insertions, 7 deletions
diff --git a/src/database.rs b/src/database.rs
index fe20bb2..24298ff 100644
--- a/src/database.rs
+++ b/src/database.rs
@@ -88,7 +88,7 @@ impl Database {
pub fn view_history(
conn: Connection,
agent_filter: Option<String>,
- note_filter: Option<String>) -> Result<()>
+ note_filter: Option<Vec<String>>) -> Result<()>
{
let mut hist_query: String = "
SELECT date(r.register_date, 'auto'), a.name, r.amount, r.note
@@ -97,24 +97,44 @@ impl Database {
ON a.id = r.agent_id
".to_owned();
+ let mut filter_note_string = String::new();
let mut stmt: Statement;
let mut regs: Rows;
+ if let Some(notes) = note_filter.clone() {
+ let mut i: u32 = 0;
+ for note in notes.iter() {
+ if i == 0 && agent_filter != None {
+ filter_note_string.push_str(" AND (note LIKE '");
+ } else if i == 0 && agent_filter == None {
+ filter_note_string.push_str(" (note LIKE '");
+ } else {
+ filter_note_string.push_str(" OR note LIKE '");
+ }
+ filter_note_string.push_str(note.as_str());
+ filter_note_string.push_str("'");
+ i+=1;
+ }
+ filter_note_string.push(')');
+ }
+
match (agent_filter, note_filter) {
- (Some(name), Some(note)) => {
- hist_query.push_str("WHERE name = ?1 and note LIKE ?2");
+ (Some(name), Some(_)) => {
+ hist_query.push_str("WHERE name = ?1");
+ hist_query.push_str(filter_note_string.as_str());
stmt = conn.prepare(hist_query.as_str())?;
- regs = stmt.query([name, note])?;
+ regs = stmt.query([name])?;
},
(Some(name), None) => {
hist_query.push_str("WHERE name = ?1");
stmt = conn.prepare(hist_query.as_str())?;
regs = stmt.query([name])?;
},
- (None, Some(note)) => {
- hist_query.push_str("WHERE note LIKE ?1");
+ (None, Some(_)) => {
+ hist_query.push_str("WHERE");
+ hist_query.push_str(filter_note_string.as_str());
stmt = conn.prepare(hist_query.as_str())?;
- regs = stmt.query([note])?;
+ regs = stmt.query([])?;
},
(None, None) => {
stmt = conn.prepare(hist_query.as_str())?;
Feel free to download, copy and edit any repo