+ public String getFolderName (int databaseId) {
+ // Get a readable database handle.
+ SQLiteDatabase bookmarksDatabase = this.getReadableDatabase();
+
+ // Prepare the SQL statement to get the `Cursor` for the folder.
+ final String GET_FOLDER = "Select * FROM " + BOOKMARKS_TABLE +
+ " WHERE " + _ID + " = " + databaseId;
+
+ // Get `folderCursor`. The second argument is `null` because there are no `selectionArgs`.
+ Cursor folderCursor = bookmarksDatabase.rawQuery(GET_FOLDER, null);
+
+ // Get `folderName`.
+ folderCursor.moveToFirst();
+ String folderName = folderCursor.getString(folderCursor.getColumnIndex(BOOKMARK_NAME));
+
+ // Close the cursor and the database handle.
+ folderCursor.close();
+ bookmarksDatabase.close();
+
+ // Return the folder name.
+ return folderName;
+ }
+
+ public Cursor getFolderCursor(String folderName) {
+ // Get a readable database handle.
+ SQLiteDatabase bookmarksDatabase = this.getReadableDatabase();
+
+ // SQL escape `folderName`.
+ folderName = DatabaseUtils.sqlEscapeString(folderName);
+
+ // Prepare the SQL statement to get the `Cursor` for the folder.
+ final String GET_FOLDER = "Select * FROM " + BOOKMARKS_TABLE +
+ " WHERE " + BOOKMARK_NAME + " = " + folderName +
+ " AND " + 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_FOLDER, null);
+ }
+
+ public Cursor getFoldersCursorExcept(String exceptFolders) {
+ // Get a readable database handle.
+ SQLiteDatabase bookmarksDatabase = this.getReadableDatabase();
+
+ // Prepare the SQL statement to get the `Cursor` for the folders.
+ final String GET_FOLDERS_EXCEPT = "Select * FROM " + BOOKMARKS_TABLE +
+ " WHERE " + IS_FOLDER + " = " + 1 +
+ " AND " + BOOKMARK_NAME + " NOT IN (" + exceptFolders +
+ ") ORDER BY " + BOOKMARK_NAME + " ASC";
+
+ // 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_FOLDERS_EXCEPT, null);
+ }
+
+ public Cursor getSubfoldersCursor(String currentFolder) {
+ // Get a readable database handle.
+ SQLiteDatabase bookmarksDatabase = this.getReadableDatabase();
+
+ // SQL escape `currentFolder.
+ currentFolder = DatabaseUtils.sqlEscapeString(currentFolder);
+
+ // Prepare the SQL statement to get the `Cursor` for the subfolders.
+ final String GET_SUBFOLDERS = "Select * FROM " + BOOKMARKS_TABLE +
+ " WHERE " + PARENT_FOLDER + " = " + currentFolder +
+ " AND " + 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_SUBFOLDERS, null);
+ }
+
+ public String getParentFolder(String currentFolder) {
+ // Get a readable database handle.
+ SQLiteDatabase bookmarksDatabase = this.getReadableDatabase();
+
+ // SQL escape `currentFolder`.
+ currentFolder = DatabaseUtils.sqlEscapeString(currentFolder);
+
+ // Prepare the SQL statement to get the parent folder.
+ final String GET_PARENT_FOLDER = "Select * FROM " + BOOKMARKS_TABLE +
+ " WHERE " + IS_FOLDER + " = " + 1 +
+ " AND " + BOOKMARK_NAME + " = " + currentFolder;
+
+ // The second argument is `null` because there are no `selectionArgs`.
+ Cursor bookmarkCursor = bookmarksDatabase.rawQuery(GET_PARENT_FOLDER, null);
+ bookmarkCursor.moveToFirst();
+
+ // Store the name of the parent folder.
+ String parentFolder = bookmarkCursor.getString(bookmarkCursor.getColumnIndex(PARENT_FOLDER));
+
+ // Close the `Cursor`.
+ bookmarkCursor.close();
+
+ return parentFolder;
+ }
+
+ public Cursor getAllBookmarksCursor() {
+ // Get a readable database handle.
+ SQLiteDatabase bookmarksDatabase = this.getReadableDatabase();
+
+ // Get everything in the 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.
+ return bookmarksDatabase.rawQuery(GET_ALL_BOOKMARKS, null);
+ }
+
+ public Cursor getAllBookmarksCursorByDisplayOrder(String folderName) {
+ // Get a readable database handle.
+ SQLiteDatabase bookmarksDatabase = this.getReadableDatabase();
+
+ // SQL escape `folderName`.
+ folderName = DatabaseUtils.sqlEscapeString(folderName);
+
+ // Get everything in the BOOKMARKS_TABLE.
+ final String GET_ALL_BOOKMARKS = "Select * FROM " + BOOKMARKS_TABLE +
+ " WHERE " + PARENT_FOLDER + " = " + folderName +
+ " ORDER BY " + DISPLAY_ORDER + " ASC";
+
+ // 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_BOOKMARKS, null);
+ }
+
+ public Cursor getBookmarksCursorExcept(long[] exceptIdLongArray, String folderName) {