Adapted to the new database schema.
This commit is contained in:
parent
8ef3238ac3
commit
56624427d5
1 changed files with 18 additions and 10 deletions
|
@ -17,8 +17,16 @@ pub struct BookEntry {
|
||||||
fn get_epubs_from_database(tx: &Transaction) -> Vec<BookEntry> {
|
fn get_epubs_from_database(tx: &Transaction) -> Vec<BookEntry> {
|
||||||
let mut book_entries = Vec::new();
|
let mut book_entries = Vec::new();
|
||||||
|
|
||||||
let mut stmt = tx
|
let version: i32 = tx
|
||||||
.prepare(
|
.query_row(r#"SELECT id FROM version"#, [], |r| r.get(0))
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let books_or_files = match version {
|
||||||
|
x if x >= 38 => "files",
|
||||||
|
_ => "books",
|
||||||
|
};
|
||||||
|
|
||||||
|
let stmt_str = format!(
|
||||||
r#"
|
r#"
|
||||||
SELECT books.id, folders.name, files.filename, books.firstauthor,
|
SELECT books.id, folders.name, files.filename, books.firstauthor,
|
||||||
books.author, genres.name, first_author_letter, series
|
books.author, genres.name, first_author_letter, series
|
||||||
|
@ -30,10 +38,12 @@ fn get_epubs_from_database(tx: &Transaction) -> Vec<BookEntry> {
|
||||||
ON books.id = btg.bookid
|
ON books.id = btg.bookid
|
||||||
LEFT OUTER JOIN genres
|
LEFT OUTER JOIN genres
|
||||||
ON genres.id = btg.genreid
|
ON genres.id = btg.genreid
|
||||||
WHERE files.storageid = 1 AND (books.ext = 'epub' OR files.filename LIKE '%.epub')
|
WHERE files.storageid = 1 AND {}.ext = 'epub'
|
||||||
ORDER BY books.id"#,
|
ORDER BY books.id"#,
|
||||||
)
|
&books_or_files
|
||||||
.unwrap();
|
);
|
||||||
|
|
||||||
|
let mut stmt = tx.prepare(&stmt_str).unwrap();
|
||||||
|
|
||||||
let mut rows = stmt.query([]).unwrap();
|
let mut rows = stmt.query([]).unwrap();
|
||||||
|
|
||||||
|
@ -233,9 +243,7 @@ pub fn fix_db_entries() -> Statistics {
|
||||||
ON CONFLICT DO NOTHING"#,
|
ON CONFLICT DO NOTHING"#,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
stmt.execute(
|
stmt.execute(named_params![":bookid": &entry.id, ":genre": &epub_metadata.genre])
|
||||||
named_params![":bookid": &entry.id, ":genre": &epub_metadata.genre],
|
|
||||||
)
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
stat.genres_fixed = stat.genres_fixed + 1;
|
stat.genres_fixed = stat.genres_fixed + 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue