mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 10:19:33 +02:00
Support for external books in the Library
git-svn-id: https://only.mawhrin.net/repos/FBReaderJ/trunk@1738 6a642e6f-84f6-412e-ac94-c4a38d5a04b0
This commit is contained in:
parent
5f4f6ac801
commit
b9b7f61ad9
7 changed files with 120 additions and 11 deletions
|
@ -58,7 +58,8 @@ final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
|
||||
private void migrate() {
|
||||
final int version = myDatabase.getVersion();
|
||||
if (version >= 8) {
|
||||
final int currentVersion = 9;
|
||||
if (version >= currentVersion) {
|
||||
return;
|
||||
}
|
||||
ZLDialogManager.Instance().wait((version == 0) ? "creatingBooksDatabase" : "updatingBooksDatabase", new Runnable() {
|
||||
|
@ -82,12 +83,14 @@ final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
updateTables6();
|
||||
case 7:
|
||||
updateTables7();
|
||||
case 8:
|
||||
updateTables8();
|
||||
}
|
||||
myDatabase.setTransactionSuccessful();
|
||||
myDatabase.endTransaction();
|
||||
|
||||
myDatabase.execSQL("VACUUM");
|
||||
myDatabase.setVersion(8);
|
||||
myDatabase.setVersion(currentVersion);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -768,6 +771,42 @@ final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
myStorePositionStatement.execute();
|
||||
}
|
||||
|
||||
private SQLiteStatement myInsertIntoBookListStatement;
|
||||
protected boolean insertIntoBookList(long bookId) {
|
||||
if (myInsertIntoBookListStatement == null) {
|
||||
myInsertIntoBookListStatement = myDatabase.compileStatement(
|
||||
"INSERT OR IGNORE INTO BookList(book_id) VALUES (?)"
|
||||
);
|
||||
}
|
||||
myInsertIntoBookListStatement.bindLong(1, bookId);
|
||||
myInsertIntoBookListStatement.execute();
|
||||
return true;
|
||||
}
|
||||
|
||||
private SQLiteStatement myDeleteFromBookListStatement;
|
||||
protected boolean deleteFromBookList(long bookId) {
|
||||
if (myDeleteFromBookListStatement == null) {
|
||||
myDeleteFromBookListStatement = myDatabase.compileStatement(
|
||||
"DELETE FROM BookList WHERE book_id = ?"
|
||||
);
|
||||
}
|
||||
myDeleteFromBookListStatement.bindLong(1, bookId);
|
||||
myDeleteFromBookListStatement.execute();
|
||||
return true;
|
||||
}
|
||||
|
||||
private SQLiteStatement myCheckBookListStatement;
|
||||
protected boolean checkBookList(long bookId) {
|
||||
if (myCheckBookListStatement == null) {
|
||||
myCheckBookListStatement = myDatabase.compileStatement(
|
||||
"SELECT COUNT(*) FROM BookList WHERE book_id = ?"
|
||||
);
|
||||
}
|
||||
myCheckBookListStatement.bindLong(1, bookId);
|
||||
return myCheckBookListStatement.simpleQueryForLong() > 0;
|
||||
}
|
||||
|
||||
|
||||
private void createTables() {
|
||||
myDatabase.execSQL(
|
||||
"CREATE TABLE Books(" +
|
||||
|
@ -1014,4 +1053,10 @@ final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
myDatabase.execSQL("DELETE FROM BookTag WHERE book_id=" + id);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateTables8() {
|
||||
myDatabase.execSQL(
|
||||
"CREATE TABLE IF NOT EXISTS BookList ( " +
|
||||
"book_id INTEGER UNIQUE NOT NULL REFERENCES Books (book_id))");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue