+ // Get a cursor for all bookmarks and folders ordered by display order.
+ public Cursor getAllBookmarksByDisplayOrder() {
+ // Get a readable database handle.
+ SQLiteDatabase bookmarksDatabase = this.getReadableDatabase();
+
+ // Get everything in the bookmarks table ordered by display order.
+ String GET_ALL_BOOKMARKS = "SELECT * FROM " + BOOKMARKS_TABLE +
+ " ORDER BY " + DISPLAY_ORDER + " ASC";
+
+ // Return the result as a cursor. The cursor cannot be closed because it is used in the parent activity.
+ return bookmarksDatabase.rawQuery(GET_ALL_BOOKMARKS, null);
+ }
+
+ // Get a cursor for all bookmarks and folders except those with the specified IDs.
+ public Cursor getAllBookmarksExcept(long[] exceptIdLongArray) {
+ // Get a readable database handle.
+ SQLiteDatabase bookmarksDatabase = this.getReadableDatabase();
+
+ // Prepare a string builder to contain the comma-separated list of IDs not to get.
+ StringBuilder idsNotToGetStringBuilder = new StringBuilder();
+
+ // Extract the array of IDs not to get to the string builder.
+ for (long databaseIdLong : exceptIdLongArray) {
+ if (idsNotToGetStringBuilder.length() == 0) { // This is the first number, so only add the number.
+ idsNotToGetStringBuilder.append(databaseIdLong);
+ } else { // This is not the first number, so place a `,` before the new number.
+ idsNotToGetStringBuilder.append(",");
+ idsNotToGetStringBuilder.append(databaseIdLong);
+ }
+ }
+
+ // Prepare the SQL statement to select all items except those with the specified IDs.
+ String GET_ALL_BOOKMARKS_EXCEPT_SPECIFIED = "SELECT * FROM " + BOOKMARKS_TABLE +
+ " WHERE " + _ID + " NOT IN (" + idsNotToGetStringBuilder.toString() + ")";
+
+ // Return the results as a cursor. The cursor cannot be closed because it will be used in the parent activity.
+ return bookmarksDatabase.rawQuery(GET_ALL_BOOKMARKS_EXCEPT_SPECIFIED, null);
+ }
+
+ // Get a cursor for all bookmarks and folders by display order except for a specific of IDs.
+ public Cursor getAllBookmarksByDisplayOrderExcept(long[] exceptIdLongArray) {
+ // Get a readable database handle.
+ SQLiteDatabase bookmarksDatabase = this.getReadableDatabase();
+
+ // Prepare a string builder to contain the comma-separated list of IDs not to get.
+ StringBuilder idsNotToGetStringBuilder = new StringBuilder();
+
+ // Extract the array of IDs not to get to the string builder.
+ for (long databaseIdLong : exceptIdLongArray) {
+ if (idsNotToGetStringBuilder.length() == 0) { // This is the first number, so only add the number.
+ idsNotToGetStringBuilder.append(databaseIdLong);
+ } else { // This is not the first number, so place a `,` before the new number.
+ idsNotToGetStringBuilder.append(",");
+ idsNotToGetStringBuilder.append(databaseIdLong);
+ }
+ }
+
+ // Prepare the SQL statement to select all items except those with the specified IDs.
+ String GET_ALL_BOOKMARKS_EXCEPT_SPECIFIED = "SELECT * FROM " + BOOKMARKS_TABLE +
+ " WHERE " + _ID + " NOT IN (" + idsNotToGetStringBuilder.toString() +
+ ") ORDER BY " + DISPLAY_ORDER + " ASC";
+
+ // Return the results as a cursor. The cursor cannot be closed because it will be used in the parent activity.
+ return bookmarksDatabase.rawQuery(GET_ALL_BOOKMARKS_EXCEPT_SPECIFIED, null);
+ }
+
+ // Get a cursor for bookmarks and folders in the specified folder.
+ public Cursor getBookmarks(String folderName) {
+ // Get a readable database handle.
+ SQLiteDatabase bookmarksDatabase = this.getReadableDatabase();
+
+ // SQL escape the folder name.
+ folderName = DatabaseUtils.sqlEscapeString(folderName);
+
+ // Get everything in the bookmarks table with `folderName` as the `PARENT_FOLDER`.
+ String GET_BOOKMARKS = "SELECT * FROM " + BOOKMARKS_TABLE +
+ " WHERE " + PARENT_FOLDER + " = " + folderName;
+
+ // Return the result as a cursor. The cursor cannot be closed because it is used in the parent activity.
+ return bookmarksDatabase.rawQuery(GET_BOOKMARKS, null);
+ }
+
+ // Get a cursor for bookmarks and folders in the specified folder ordered by display order.
+ public Cursor getBookmarksByDisplayOrder(String folderName) {