}
// Get a `Cursor` for the bookmark with the specified database ID.
- public Cursor getBookmarkCursor(int databaseId) {
+ public Cursor getBookmark(int databaseId) {
// Get a readable database handle.
SQLiteDatabase bookmarksDatabase = this.getReadableDatabase();
return folderName;
}
- // The the database ID for the specified folder name.
+ // Get the database ID for the specified folder name.
public int getFolderDatabaseId (String folderName) {
// Get a readable database handle.
SQLiteDatabase bookmarksDatabase = this.getReadableDatabase();
return databaseId;
}
- // Get a `Cursor` for the specified folder name.
- public Cursor getFolderCursor(String folderName) {
+ // Get a cursor for the specified folder name.
+ public Cursor getFolder(String folderName) {
// Get a readable database handle.
SQLiteDatabase bookmarksDatabase = this.getReadableDatabase();
return bookmarksDatabase.rawQuery(GET_FOLDER, null);
}
- // Get a `Cursor` of all the folders except those specified.
- public Cursor getFoldersCursorExcept(String exceptFolders) {
+ // Get a cursor of all the folders except those specified.
+ public Cursor getFoldersExcept(String exceptFolders) {
// Get a readable database handle.
SQLiteDatabase bookmarksDatabase = this.getReadableDatabase();
return bookmarksDatabase.rawQuery(GET_FOLDERS_EXCEPT, null);
}
- // Get a `Cursor` with all the subfolders of the specified folder.
- public Cursor getSubfoldersCursor(String currentFolder) {
+ // Get a cursor with all the subfolders of the specified folder.
+ public Cursor getSubfolders(String currentFolder) {
// Get a readable database handle.
SQLiteDatabase bookmarksDatabase = this.getReadableDatabase();
return bookmarksDatabase.rawQuery(GET_SUBFOLDERS, null);
}
- // Get a `String` with the name of the parent folder.
- public String getParentFolder(String currentFolder) {
+ // Get the name of the parent folder.
+ public String getParentFolderName(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.
- String GET_PARENT_FOLDER = "SELECT * FROM " + BOOKMARKS_TABLE +
+ // Prepare the SQL statement to get the current folder.
+ String GET_CURRENT_FOLDER = "SELECT * FROM " + BOOKMARKS_TABLE +
" WHERE " + IS_FOLDER + " = " + 1 +
" AND " + BOOKMARK_NAME + " = " + currentFolder;
// Get the bookmark cursor and move to the first entry.
- Cursor bookmarkCursor = bookmarksDatabase.rawQuery(GET_PARENT_FOLDER, null);
+ Cursor bookmarkCursor = bookmarksDatabase.rawQuery(GET_CURRENT_FOLDER, null);
bookmarkCursor.moveToFirst();
// Store the name of the parent folder.
String parentFolder = bookmarkCursor.getString(bookmarkCursor.getColumnIndex(PARENT_FOLDER));
- // Close the `Cursor`.
+ // Close the cursor.
bookmarkCursor.close();
return parentFolder;
}
- // Get a `Cursor` of all the folders.
- public Cursor getAllFoldersCursor() {
+ // Get the name of the parent folder.
+ public String getParentFolderName(int databaseId) {
+ // Get a readable database handle.
+ SQLiteDatabase bookmarksDatabase = this.getReadableDatabase();
+
+ // Prepare the SQL statement to get the current bookmark.
+ String GET_BOOKMARK = "SELECT * FROM " + BOOKMARKS_TABLE +
+ " WHERE " + _ID + " = " + databaseId;
+
+ // Get the bookmark cursor and move to the first entry.
+ Cursor bookmarkCursor = bookmarksDatabase.rawQuery(GET_BOOKMARK, 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;
+ }
+
+ // Get a cursor of all the folders.
+ public Cursor getAllFolders() {
// Get a readable database handle.
SQLiteDatabase bookmarksDatabase = this.getReadableDatabase();
" WHERE " + IS_FOLDER + " = " + 1 +
" 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 the results as a cursor. The cursor cannot be closed because it is used in the parent activity.
return bookmarksDatabase.rawQuery(GET_ALL_FOLDERS, null);
}
// Get a cursor for all bookmarks and folders.
- public Cursor getAllBookmarksCursor() {
+ public Cursor getAllBookmarks() {
// Get a readable database handle.
SQLiteDatabase bookmarksDatabase = this.getReadableDatabase();
return bookmarksDatabase.rawQuery(GET_ALL_BOOKMARKS, null);
}
- // Get a `Cursor` for all bookmarks and folders in the specified folder.
- public Cursor getAllBookmarksCursor(String folderName) {
+ // 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();
folderName = DatabaseUtils.sqlEscapeString(folderName);
// Get everything in the bookmarks table with `folderName` as the `PARENT_FOLDER`.
- String GET_ALL_BOOKMARKS = "SELECT * FROM " + BOOKMARKS_TABLE +
+ 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_ALL_BOOKMARKS, null);
+ return bookmarksDatabase.rawQuery(GET_BOOKMARKS, null);
}
- // Get a cursor for all bookmarks and folders ordered by display order.
- public Cursor getAllBookmarksCursorByDisplayOrder() {
+ // Get a cursor for bookmarks and folders in the specified folder ordered by display order.
+ public Cursor getBookmarksByDisplayOrder(String folderName) {
// 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 +
+ // SQL escape `folderName`.
+ 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 +
" 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);
+ return bookmarksDatabase.rawQuery(GET_BOOKMARKS, null);
}
- // Get a cursor for all bookmarks and folders in the specified folder ordered by display order.
- public Cursor getAllBookmarksCursorByDisplayOrder(String folderName) {
+ // Get a cursor with just database ID of bookmarks and folders in the specified folder. This is useful for deleting folders with bookmarks that have favorite icons too large to fit in a cursor.
+ public Cursor getBookmarkIDs(String folderName) {
// Get a readable database handle.
SQLiteDatabase bookmarksDatabase = this.getReadableDatabase();
- // SQL escape `folderName`.
+ // SQL escape the folder name.
folderName = DatabaseUtils.sqlEscapeString(folderName);
// Get everything in the bookmarks table with `folderName` as the `PARENT_FOLDER`.
- String GET_ALL_BOOKMARKS = "SELECT * FROM " + BOOKMARKS_TABLE +
+ String GET_BOOKMARKS = "SELECT " + _ID + " 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 except for ta specific list of IDs.
+ public Cursor getBookmarksExcept(long[] exceptIdLongArray, String folderName) {
+ // 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);
+ }
+ }
+
+ // SQL escape the folder name.
+ folderName = DatabaseUtils.sqlEscapeString(folderName);
+
+ // Get everything in the bookmarks table with `folderName` as the `PARENT_FOLDER` except those with the specified IDs.
+ String GET_BOOKMARKS_EXCEPT_SPECIFIED = "SELECT * FROM " + BOOKMARKS_TABLE +
" WHERE " + PARENT_FOLDER + " = " + folderName +
- " ORDER BY " + DISPLAY_ORDER + " ASC";
+ " AND " + _ID + " NOT IN (" + idsNotToGetStringBuilder.toString() + ")";
// 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);
+ return bookmarksDatabase.rawQuery(GET_BOOKMARKS_EXCEPT_SPECIFIED, null);
}
- // Get a `Cursor` for all bookmarks and folders in the specified folder except for a specific list of IDs.
- public Cursor getBookmarksCursorExcept(long[] exceptIdLongArray, String folderName) {
+ // Get a cursor for bookmarks and folders in the specified folder by display order except for a specific list of IDs.
+ public Cursor getBookmarksByDisplayOrderExcept(long[] exceptIdLongArray, String folderName) {
// Get a readable database handle.
SQLiteDatabase bookmarksDatabase = this.getReadableDatabase();
- // Prepare a string builder that contains the comma-separated list of IDs not to get.
- StringBuilder doNotGetIdsStringBuilder = new StringBuilder();
+ // Prepare a string builder to contain the comma-separated list of IDs not to get.
+ StringBuilder idsNotToGetStringBuilder = new StringBuilder();
- // Extract the array to `doNotGetIdsString`.
+ // Extract the array of IDs not to get to the string builder.
for (long databaseIdLong : exceptIdLongArray) {
- // If this is the first number, only add the number.
- if (doNotGetIdsStringBuilder.toString().isEmpty()) {
- doNotGetIdsStringBuilder.append(databaseIdLong);
- } else { // If there already is a number in the string, place a `,` before the new number.
- doNotGetIdsStringBuilder.append(",");
- doNotGetIdsStringBuilder.append(databaseIdLong);
+ 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);
}
}
folderName = DatabaseUtils.sqlEscapeString(folderName);
// Prepare the SQL statement to select all items except those with the specified IDs.
- String GET_All_BOOKMARKS_EXCEPT_SPECIFIED = "SELECT * FROM " + BOOKMARKS_TABLE +
+ String GET_BOOKMARKS_EXCEPT_SPECIFIED = "SELECT * FROM " + BOOKMARKS_TABLE +
" WHERE " + PARENT_FOLDER + " = " + folderName +
- " AND " + _ID + " NOT IN (" + doNotGetIdsStringBuilder.toString() +
+ " AND " + _ID + " NOT IN (" + idsNotToGetStringBuilder.toString() +
") 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_EXCEPT_SPECIFIED, null);
+ // Return the results as a cursor. The cursor cannot be closed because it will be used in the parent activity.
+ return bookmarksDatabase.rawQuery(GET_BOOKMARKS_EXCEPT_SPECIFIED, null);
}
// Check if a database ID is a folder.
SQLiteDatabase bookmarksDatabase = this.getReadableDatabase();
// Prepare the SQL statement to determine if `databaseId` is a folder.
- String CHECK_IF_FOLDER = "SELECT * FROM " + BOOKMARKS_TABLE +
+ String CHECK_IF_FOLDER = "SELECT " + IS_FOLDER + " FROM " + BOOKMARKS_TABLE +
" WHERE " + _ID + " = " + databaseId;
- // Populate folderCursor. The second argument is `null` because there are no `selectionArgs`.
+ // Populate the folder cursor.
Cursor folderCursor = bookmarksDatabase.rawQuery(CHECK_IF_FOLDER, null);
// Ascertain if this database ID is a folder.
folderCursor.moveToFirst();
boolean isFolder = (folderCursor.getInt(folderCursor.getColumnIndex(IS_FOLDER)) == 1);
- // Close the `Cursor` and the database handle.
+ // Close the cursor and the database handle.
folderCursor.close();
bookmarksDatabase.close();
// Update the bookmark name and URL.
public void updateBookmark(int databaseId, String bookmarkName, String bookmarkUrl) {
- // Initialize a `ContentValues`.
+ // Initialize a ContentValues.
ContentValues bookmarkContentValues = new ContentValues();
// Store the updated values.