Skip to content

Commit

Permalink
Fix: database's 'user_version' pragma checking
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementNerma committed Dec 8, 2023
1 parent ff08121 commit 666e4e4
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/history/sqlite_backed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ impl SqliteBackedHistory {

// Get the user version
// By default, it is set to 0
let db_version: i32 = db.query_row(
let mut db_version: i32 = db.query_row(
"SELECT user_version FROM pragma_user_version",
params![],
|r| r.get(0),
Expand Down Expand Up @@ -316,6 +316,7 @@ impl SqliteBackedHistory {

// Update the version to indicate the DB is up-to-date
statements.push("pragma user_version = 1;");
db_version = 1;

// We use a transaction to ensure consistency, given we're doing multiple operations
let transaction = db.transaction()?;
Expand Down Expand Up @@ -472,17 +473,21 @@ impl SqliteBackedHistory {
Box::new(session_timestamp.timestamp_millis()),
));
}

let mut wheres = wheres.join(" and ");

if wheres.is_empty() {
wheres = "true".to_string();
}

let query = format!(
"SELECT {select_expression} \
FROM history \
WHERE ({wheres}) \
ORDER BY idx {asc} \
{limit}"
);

(query, params)
}
}
Expand Down

0 comments on commit 666e4e4

Please sign in to comment.