From 983552f7ad42a271428b3a26bd4d756013c2e3ab Mon Sep 17 00:00:00 2001 From: Wouters Dorian Date: Wed, 29 Jan 2014 21:42:33 +0100 Subject: [PATCH] Fix #37 (empty URL caused a bad SQLite request) --- src/org/tint/providers/BookmarksWrapper.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/org/tint/providers/BookmarksWrapper.java b/src/org/tint/providers/BookmarksWrapper.java index 48ba425..777f2a2 100644 --- a/src/org/tint/providers/BookmarksWrapper.java +++ b/src/org/tint/providers/BookmarksWrapper.java @@ -391,10 +391,20 @@ public static void deleteHistoryRecord(ContentResolver contentResolver, long id) public static void updateHistory(ContentResolver contentResolver, String title, String url, String originalUrl) { String[] colums = new String[] { BookmarksProvider.Columns._ID, BookmarksProvider.Columns.URL, BookmarksProvider.Columns.BOOKMARK, BookmarksProvider.Columns.VISITS }; + if ((url == null || url.length() == 0) && (originalUrl == null || originalUrl.length() == 0)) + return; + String escapedUrl = url != null ? DatabaseUtils.sqlEscapeString(url) : ""; String escapedOriginalUrl = originalUrl != null ? DatabaseUtils.sqlEscapeString(originalUrl) : ""; - String whereClause = BookmarksProvider.Columns.URL + " = " + escapedUrl + " OR " + BookmarksProvider.Columns.URL + " = " + escapedOriginalUrl; + String whereClause = ((escapedUrl.length() > 0) ? + BookmarksProvider.Columns.URL + " = " + escapedUrl : "") + + + ((escapedUrl.length() > 0 && escapedOriginalUrl.length() > 0) ? + " OR " : "") + + + ((escapedOriginalUrl.length() > 0) ? + BookmarksProvider.Columns.URL + " = " + escapedOriginalUrl : ""); Cursor cursor = contentResolver.query(BookmarksProvider.BOOKMARKS_URI, colums, whereClause, null, null);