From 2c7ceb900b07ebd8291a6b8e74f28910872b1357 Mon Sep 17 00:00:00 2001 From: Jay Date: Thu, 21 May 2020 23:13:21 -0400 Subject: [PATCH] Fixed sql query crash --- .../tachiyomi/data/database/queries/ChapterQueries.kt | 3 ++- .../tachiyomi/data/database/queries/HistoryQueries.kt | 9 +++++---- .../eu/kanade/tachiyomi/util/lang/StringExtensions.kt | 3 +++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/ChapterQueries.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/ChapterQueries.kt index 413242d021..873769172e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/ChapterQueries.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/ChapterQueries.kt @@ -13,6 +13,7 @@ import eu.kanade.tachiyomi.data.database.resolvers.ChapterSourceOrderPutResolver import eu.kanade.tachiyomi.data.database.resolvers.MangaChapterGetResolver import eu.kanade.tachiyomi.data.database.resolvers.MangaChapterHistoryGetResolver import eu.kanade.tachiyomi.data.database.tables.ChapterTable +import eu.kanade.tachiyomi.util.lang.sqLite import java.util.Date interface ChapterQueries : DbProvider { @@ -39,7 +40,7 @@ interface ChapterQueries : DbProvider { fun getUpdatedManga(date: Date, search: String = "", endless: Boolean) = db.get() .listOfObjects(MangaChapterHistory::class.java) .withQuery(RawQuery.builder() - .query(getRecentsQueryDistinct(search, endless)) + .query(getRecentsQueryDistinct(search.sqLite, endless)) .args(date.time) .observesTables(ChapterTable.TABLE) .build()) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/HistoryQueries.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/HistoryQueries.kt index f835d79f60..e17c5046da 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/HistoryQueries.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/HistoryQueries.kt @@ -9,6 +9,7 @@ import eu.kanade.tachiyomi.data.database.resolvers.HistoryLastReadPutResolver import eu.kanade.tachiyomi.data.database.resolvers.MangaChapterHistoryGetResolver import eu.kanade.tachiyomi.data.database.tables.HistoryTable import eu.kanade.tachiyomi.data.database.tables.MangaTable +import eu.kanade.tachiyomi.util.lang.sqLite import java.util.Date interface HistoryQueries : DbProvider { @@ -27,7 +28,7 @@ interface HistoryQueries : DbProvider { fun getRecentManga(date: Date, offset: Int = 0, search: String = "") = db.get() .listOfObjects(MangaChapterHistory::class.java) .withQuery(RawQuery.builder() - .query(getRecentMangasQuery(offset, search)) + .query(getRecentMangasQuery(offset, search.sqLite)) .args(date.time) .observesTables(HistoryTable.TABLE) .build()) @@ -42,7 +43,7 @@ interface HistoryQueries : DbProvider { fun getRecentlyAdded(date: Date, search: String = "", endless: Boolean) = db.get() .listOfObjects(MangaChapterHistory::class.java) .withQuery(RawQuery.builder() - .query(getRecentAdditionsQuery(search, endless)) + .query(getRecentAdditionsQuery(search.sqLite, endless)) .args(date.time) .observesTables(MangaTable.TABLE) .build()) @@ -57,7 +58,7 @@ interface HistoryQueries : DbProvider { fun getRecentMangaLimit(date: Date, limit: Int = 0, search: String = "") = db.get() .listOfObjects(MangaChapterHistory::class.java) .withQuery(RawQuery.builder() - .query(getRecentMangasLimitQuery(limit, search)) + .query(getRecentMangasLimitQuery(limit, search.sqLite)) .args(date.time) .observesTables(HistoryTable.TABLE) .build()) @@ -72,7 +73,7 @@ interface HistoryQueries : DbProvider { fun getRecentsWithUnread(date: Date, search: String = "", endless: Boolean) = db.get() .listOfObjects(MangaChapterHistory::class.java) .withQuery(RawQuery.builder() - .query(getRecentReadWithUnreadChapters(search, endless)) + .query(getRecentReadWithUnreadChapters(search.sqLite, endless)) .args(date.time) .observesTables(HistoryTable.TABLE) .build()) diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/lang/StringExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/lang/StringExtensions.kt index d8a550a762..060744c5da 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/lang/StringExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/lang/StringExtensions.kt @@ -22,6 +22,9 @@ fun String.removeArticles(): String { } } +val String.sqLite:String + get() = replace("'", "''") + fun String.trimOrNull(): String? { val trimmed = trim() return if (trimmed.isBlank()) null else trimmed