X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fhelpers%2FBookmarksDatabaseHelper.java;h=55cc346bd7e73f09790638df6cd071e3fe104518;hb=b9b9315f5b6b0bc171082f11660ca390748c0c2b;hp=0daf7f6a9befc6edd66c308dfdda89056011f47f;hpb=b3b4105e9acd9cf8e202abef3b811d49c6c36bec;p=PrivacyBrowserAndroid.git diff --git a/app/src/main/java/com/stoutner/privacybrowser/helpers/BookmarksDatabaseHelper.java b/app/src/main/java/com/stoutner/privacybrowser/helpers/BookmarksDatabaseHelper.java index 0daf7f6a..55cc346b 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/helpers/BookmarksDatabaseHelper.java +++ b/app/src/main/java/com/stoutner/privacybrowser/helpers/BookmarksDatabaseHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2017 Soren Stoutner . + * Copyright © 2016-2017 Soren Stoutner . * * This file is part of Privacy Browser . * @@ -112,7 +112,7 @@ public class BookmarksDatabaseHelper extends SQLiteOpenHelper { SQLiteDatabase bookmarksDatabase = this.getReadableDatabase(); // Prepare the SQL statement to get the `Cursor` for `databaseId` - final String GET_ONE_BOOKMARK = "Select * FROM " + BOOKMARKS_TABLE + + final String GET_ONE_BOOKMARK = "SELECT * FROM " + BOOKMARKS_TABLE + " WHERE " + _ID + " = " + databaseId; // Return the results as a `Cursor`. The second argument is `null` because there are no `selectionArgs`. We can't close the `Cursor` because we need to use it in the parent activity. @@ -124,7 +124,7 @@ public class BookmarksDatabaseHelper extends SQLiteOpenHelper { SQLiteDatabase bookmarksDatabase = this.getReadableDatabase(); // Prepare the SQL statement to get the `Cursor` for the folder. - final String GET_FOLDER = "Select * FROM " + BOOKMARKS_TABLE + + final String GET_FOLDER = "SELECT * FROM " + BOOKMARKS_TABLE + " WHERE " + _ID + " = " + databaseId; // Get `folderCursor`. The second argument is `null` because there are no `selectionArgs`. @@ -150,7 +150,7 @@ public class BookmarksDatabaseHelper extends SQLiteOpenHelper { folderName = DatabaseUtils.sqlEscapeString(folderName); // Prepare the SQL statement to get the `Cursor` for the folder. - final String GET_FOLDER = "Select * FROM " + BOOKMARKS_TABLE + + final String GET_FOLDER = "SELECT * FROM " + BOOKMARKS_TABLE + " WHERE " + BOOKMARK_NAME + " = " + folderName + " AND " + IS_FOLDER + " = " + 1; @@ -164,7 +164,7 @@ public class BookmarksDatabaseHelper extends SQLiteOpenHelper { SQLiteDatabase bookmarksDatabase = this.getReadableDatabase(); // Prepare the SQL statement to get the `Cursor` for the folders. - final String GET_FOLDERS_EXCEPT = "Select * FROM " + BOOKMARKS_TABLE + + final String GET_FOLDERS_EXCEPT = "SELECT * FROM " + BOOKMARKS_TABLE + " WHERE " + IS_FOLDER + " = " + 1 + " AND " + BOOKMARK_NAME + " NOT IN (" + exceptFolders + ") ORDER BY " + BOOKMARK_NAME + " ASC"; @@ -182,7 +182,7 @@ public class BookmarksDatabaseHelper extends SQLiteOpenHelper { currentFolder = DatabaseUtils.sqlEscapeString(currentFolder); // Prepare the SQL statement to get the `Cursor` for the subfolders. - final String GET_SUBFOLDERS = "Select * FROM " + BOOKMARKS_TABLE + + final String GET_SUBFOLDERS = "SELECT * FROM " + BOOKMARKS_TABLE + " WHERE " + PARENT_FOLDER + " = " + currentFolder + " AND " + IS_FOLDER + " = " + 1; @@ -199,7 +199,7 @@ public class BookmarksDatabaseHelper extends SQLiteOpenHelper { currentFolder = DatabaseUtils.sqlEscapeString(currentFolder); // Prepare the SQL statement to get the parent folder. - final String GET_PARENT_FOLDER = "Select * FROM " + BOOKMARKS_TABLE + + final String GET_PARENT_FOLDER = "SELECT * FROM " + BOOKMARKS_TABLE + " WHERE " + IS_FOLDER + " = " + 1 + " AND " + BOOKMARK_NAME + " = " + currentFolder; @@ -216,12 +216,25 @@ public class BookmarksDatabaseHelper extends SQLiteOpenHelper { return parentFolder; } + public Cursor getAllFoldersCursor() { + // Get a readable database handle. + SQLiteDatabase bookmarksDatabase = this.getReadableDatabase(); + + // Prepare the SQL statement to get the `Cursor` for all the folders. + final String GET_ALL_FOLDERS = "SELECT * FROM " + BOOKMARKS_TABLE + + " WHERE " + IS_FOLDER + " = " + 1; + + // Return the results as a `Cursor`. The second argument is `null` because there are no `selectionArgs`. + // We can't close the `Cursor` because we need to use it in the parent activity. + return bookmarksDatabase.rawQuery(GET_ALL_FOLDERS, null); + } + public Cursor getAllBookmarksCursor() { // Get a readable database handle. SQLiteDatabase bookmarksDatabase = this.getReadableDatabase(); // Get everything in `BOOKMARKS_TABLE`. - final String GET_ALL_BOOKMARKS = "Select * FROM " + BOOKMARKS_TABLE; + final String GET_ALL_BOOKMARKS = "SELECT * FROM " + BOOKMARKS_TABLE; // Return the results as a Cursor. The second argument is `null` because there are no selectionArgs. // We can't close the Cursor because we need to use it in the parent activity. @@ -236,7 +249,7 @@ public class BookmarksDatabaseHelper extends SQLiteOpenHelper { folderName = DatabaseUtils.sqlEscapeString(folderName); // Get everything in the `BOOKMARKS_TABLE` with `folderName` as the `PARENT_FOLDER`. - final String GET_ALL_BOOKMARKS = "Select * FROM " + BOOKMARKS_TABLE + + final String GET_ALL_BOOKMARKS = "SELECT * FROM " + BOOKMARKS_TABLE + " WHERE " + PARENT_FOLDER + " = " + folderName + " ORDER BY " + DISPLAY_ORDER + " ASC"; @@ -264,7 +277,7 @@ public class BookmarksDatabaseHelper extends SQLiteOpenHelper { folderName = DatabaseUtils.sqlEscapeString(folderName); // Prepare the SQL statement to select all items except those with the specified IDs. - final String GET_All_BOOKMARKS_EXCEPT_SPECIFIED = "Select * FROM " + BOOKMARKS_TABLE + + final String GET_All_BOOKMARKS_EXCEPT_SPECIFIED = "SELECT * FROM " + BOOKMARKS_TABLE + " WHERE " + PARENT_FOLDER + " = " + folderName + " AND " + _ID + " NOT IN (" + doNotGetIdsString + ") ORDER BY " + DISPLAY_ORDER + " ASC"; @@ -279,7 +292,7 @@ public class BookmarksDatabaseHelper extends SQLiteOpenHelper { SQLiteDatabase bookmarksDatabase = this.getReadableDatabase(); // Prepare the SQL statement to determine if `databaseId` is a folder. - final String CHECK_IF_FOLDER = "Select * FROM " + BOOKMARKS_TABLE + + final String CHECK_IF_FOLDER = "SELECT * FROM " + BOOKMARKS_TABLE + " WHERE " + _ID + " = " + databaseId; // Populate folderCursor. The second argument is `null` because there are no `selectionArgs`. @@ -409,7 +422,7 @@ public class BookmarksDatabaseHelper extends SQLiteOpenHelper { // Get the highest `DISPLAY_ORDER` in the new folder String newFolderSqlEscaped = DatabaseUtils.sqlEscapeString(newFolder); - final String NEW_FOLDER = "Select * FROM " + BOOKMARKS_TABLE + + final String NEW_FOLDER = "SELECT * FROM " + BOOKMARKS_TABLE + " WHERE " + PARENT_FOLDER + " = " + newFolderSqlEscaped + " ORDER BY " + DISPLAY_ORDER + " ASC"; // The second argument is `null` because there are no `selectionArgs`.